openlayers Note 1: Load the vector map data, methods and solutions to address the problem of cross-domain

Both methods load vector map data

Use OpenLayers vector map data may be loaded in two ways. First, load the file directly to local geojson format; the second is to publish GIS vector map data to the server, and then use OpenLayers WFS service request retrieval of vector map data. (Hereinafter to GeoServer for example)
Both of these methods may appear cross-domain problems (Console to Access to the beginning of the XMLHttpRequest error) when used.

Load cross-domain issue local geojson file format problems and solutions.

Load cross-domain issue local geojson format file that appears is because the local HTML page opened directly with the back-end are separated, you can not get to data or geojson json format.
The solution is simple to deploy html pages to a web server, http service access request page on the line.
geojson file formats have to add the corresponding message type in the content server. IIS is the mime type, add the application / geojson. Add node.js server code directly in the creation of this type of mapping.
This method is useful not only for OpenLayers various other items or data to be loaded json geojson data are applicable, such as using D3.js geojson retrieved data.

Geoserver cross-domain request to issue WFS service problems and solutions.

OpenLayers WFS service request cross-domain problem occurs because of your GIS and web server is not a domain.
There are many solutions, specific reference Openlayers WFS cross-domain request .
I think one of the most convenient is to use jsonp. Need GeoServer \ webapps \ geoserver \ WEB- INF \ web.xml in the comment portion jsonp removed, restart GeoServer, and may be combined or other ajax sends a corresponding request to the GIS server, the returned results could be loaded.

Published an original article · won praise 5 · views 34

Guess you like

Origin blog.csdn.net/nolesstime/article/details/105235905