[mapserver-users] Setting up a JSONP service
Lime, Steve D (MNIT)
Steve.Lime at state.mn.us
Tue Dec 30 07:24:21 PST 2014
You can also use MapServer templates to accomplish this. It's a little more work since you have to write the template but it's quite flexible then. Usually I write the template to produce JSON and then use a simple wrapper template to produce JSONP. For example, jsonp.js looks like (callback is passed in):
// MapServer Template
[callback](
[include src="templates/json.js"]
)
Output formats look like:
OUTPUTFORMAT
NAME 'JSON'
DRIVER 'TEMPLATE'
MIMETYPE 'application/json;'
FORMATOPTION 'FILE=templates/json.js'
FORMATOPTION 'ATTACHMENT=service.json'
END
OUTPUTFORMAT
NAME 'JSONP'
DRIVER 'TEMPLATE'
MIMETYPE 'application/json;'
FORMATOPTION 'FILE=templates/jsonp.js'
FORMATOPTION 'ATTACHMENT=service.json'
END
Steve
-----Original Message-----
From: mapserver-users-bounces at lists.osgeo.org [mailto:mapserver-users-bounces at lists.osgeo.org] On Behalf Of Lars Fricke
Sent: Monday, December 29, 2014 5:34 AM
To: mapserver-users at lists.osgeo.org
Subject: [mapserver-users] Setting up a JSONP service
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
_______________________________________________
mapserver-users mailing list
mapserver-users at lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/mapserver-users
More information about the MapServer-users
mailing list