Setting up your map server for JSON-P¶
Issues¶
To display a WFS stream in a web map library, it is necessary to retrieve the data and then visualize it. However, the request is usually blocked by the Cross Domain principle, which aims to prevent two servers with different domains from exchanging data.
JSONP gets around this problem, by encapsulating the result in a <script>
tag (see the article dedicated to JSONP on Journal du Net). To avoid Javascript errors, the result is contained in a function, so you need to know the name of this function to be able to use the response.
Not all popular map servers can generate JSONP via the OUTPUTFORMAT=
parameter. Here we present the solution with GeoServer (a free, open-source map server), Esri having implemented its own versions of the standards (see Esri Feature/service d'entités correspondant au WFS).
GeoServer¶
GeoServer can return JSONP if this feature has been enabled (it is disabled by default). To enable this parameter, create an environment variable dependent on the user running the GeoServer service, named ENABLE_JSONP
, with the value true
, then restart the GeoServer service.
To do this, we recommend using the SETX command:
SETX /u myuser [/p [<Password>]] ENABLE_JSONP true
Once you've done this, when you make a GetCapabilities
request to one of your WFS services from GeoServer, the JSONP format is present.