[mapserver-users] Setting up a JSONP service

Even Rouault even.rouault at spatialys.com
Mon Dec 29 16:36:18 PST 2014


Le mardi 30 décembre 2014 00:55:59, Jeff McKenna a écrit :
> On 2014-12-29 6:34 AM, Lars Fricke wrote:
> > Dear List,
> > 
> > I have a WFS service running under MapServer that I would like to
> > operate as JSONP service. I managed to set GEOJSON as output format but
> > I get "Cross-Origin-Request Blocked" if I try to call it with a
> > Javascript client (using Leaflet L.layerJSON.
> > The question is: Is it possible to set up a JSONP service from Mapserver
> > and if yes, how? My current mapfile looks like this (relevant parts):
> > 
> > "
> > # in WEB - METADATA
> > "wfs_getfeature_formatlist" "geojson,csv,ogrgml"
> > 
> > OUTPUTFORMAT
> > 
> >     NAME "geojson"
> >     DRIVER "OGR/GEOJSON"
> >     MIMETYPE "application/json; subtype=geojson; charset=utf-8"
> >     FORMATOPTION "STORAGE=stream"
> >     FORMATOPTION "FORM=SIMPLE"
> >     FORMATOPTION "LCO:COORDINATE_PRECISION=5"
> >    
> >    END
> > 
> > "
> > If this would already be a correct JSONP service, I have to look on the
> > Leaflet side for the error...
> > Thanks for your help.
> > 
> > Cheers
> > 
> > Lars
> 
> Since you're using the OGR driver, you might want to review the GDAL/OGR
> drive page thoroughly (http://www.gdal.org/drv_geojson.html), or ask
> about JSONP on the GDAL-dev mailing list (I see several discussions
> about JSONP, when I search the mailing list archives
> http://osgeo-org.1560.x6.nabble.com/GDAL-Dev-f3742093.html)

Lars,

AFAICS, this would needs a modest enhancement in the OGR GeoJSON driver to 
have for example a FORMAT=JSONP creation option, and probably another one like 
JSONP_CALLBACK=the_name_you_wish to define the name of the callback function.

Then you could define:

OUTPUTFORMAT
     NAME "jsonp"
     DRIVER "OGR/GEOJSON"
     MIMETYPE "text/javascript"
     FORMATOPTION "STORAGE=stream"
     FORMATOPTION "FORM=SIMPLE"
     FORMATOPTION "LCO:FORMAT=JSONP"
     FORMATOPTION "LCO:JSONP_CALLBACK=the_name_you_wish"
     FORMATOPTION "LCO:COORDINATE_PRECISION=5"
END

I see that GeoServer has a way to specify the callback name from a user-
specified "format_options=" vendor specific parameters. We could probably do 
something similar with substitution in output format formatoption like

OUTPUTFORMAT
     NAME "jsonp"
     DRIVER "OGR/GEOJSON"
     MIMETYPE "text/javascript"
     FORMATOPTION "STORAGE=stream"
     FORMATOPTION "FORM=SIMPLE"
     FORMATOPTION "LCO:FORMAT=JSONP"
     FORMATOPTION "LCO:JSONP_CALLBACK=%jsonp_callback%"
     FORMATOPTION "LCO:COORDINATE_PRECISION=5"
END

But AFAIK, this is only currently implemented for the FILENAME format option, 
so this would require a small enhancement in MapServer too.

Even

-- 
Spatialys - Geospatial professional services
http://www.spatialys.com



More information about the MapServer-users mailing list