[mapserver-users] Setting up a JSONP service

Eichner, Andreas - SID Andreas.Eichner at sid.sachsen.de
Thu Jan 15 03:26:09 PST 2015


Hey Lars,

that's great news ;) I did some minor modifications (full patch attached). Now if output format has the format option "JSONP" then default substitutions are applied to it and the "Content-Disposition" header is omitted (causes browsers to display the "Save as" dialog).

The map file should contain

OUTPUTFORMAT
      NAME 'jsonp'
      DRIVER 'OGR/GEOJSON'
      MIMETYPE 'text/javascript; charset=utf-8'
      FORMATOPTION 'LCO:COORDINATE_PRECISION=5'
      FORMATOPTION 'STORAGE=stream'
      FORMATOPTION 'FORM=simple'
      FORMATOPTION 'JSONP=%callback%'
END

WEB
      METADATA
              wfs_getfeature_formatlist "jsonp"
      END
	VALIDATION
              callback '.*'
              default_callback 'my_callback'
      END
END

A WFS GetFeature request should then set the query string to contain OUTPUTFORMAT=jsonp and CALLBACK=callme. The default value might be useful if you want to run some javascript directly:

  default_callback '(function(j){alert(JSON.stringify(j));})'

creates an immediately called anonymous function that displays the JSON. Of course, the real validation pattern should be something more sophisticated.

Just to summarize for all those who didn't follow the thread: The same result could be achieved using the template engine as Steve mentioned and all this is a workaround for a missing datasource creation option in OGR's JSON driver. This patch might provide more performance and might save memory on large result sets.

Kind regards!


> -----Ursprüngliche Nachricht-----
> Von: mapserver-users-bounces at lists.osgeo.org [mailto:mapserver-users-
> bounces at lists.osgeo.org] Im Auftrag von Lars Fricke
> Gesendet: Mittwoch, 14. Januar 2015 17:17
> An: mapserver-users at lists.osgeo.org
> Betreff: Re: [mapserver-users] Setting up a JSONP service
> 
> Hello Andreas,
> 
> I confirm your solution is working perfectly well. I succeeded to
> integrate the JSONP output into my web application with no conflicts.
> Funny this depended so much on the version of code I happened to grab
> wrong. Sorry for producing extra work by that.
> 
> I'd love to see this go to the repositories, it's really helpful until
> someone will extend OGR.
> 
> So thanks again from Mecklenburg to Saxony :-)
> 
> Best
> 
> Lars
> 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: jsonp.diff
Type: application/octet-stream
Size: 1566 bytes
Desc: jsonp.diff
URL: <http://lists.osgeo.org/pipermail/mapserver-users/attachments/20150115/d7889b51/attachment.obj>


More information about the mapserver-users mailing list