[mapserver-users] Setting up a JSONP service

Lime, Steve D (MNIT) Steve.Lime at state.mn.us
Thu Jan 15 06:28:23 PST 2015


Andreas: Do you want to try creating a pull request so we can consider merging your patch?

Steve

________________________________________
From: mapserver-users-bounces at lists.osgeo.org [mapserver-users-bounces at lists.osgeo.org] on behalf of Eichner, Andreas - SID [Andreas.Eichner at sid.sachsen.de]
Sent: Thursday, January 15, 2015 5:26 AM
To: 'lars.fricke at skendata.de'; mapserver-users at lists.osgeo.org
Subject: Re: [mapserver-users] Setting up a JSONP service

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
>


More information about the mapserver-users mailing list