[OpenLayers-Users] Example of GeoJson fetch via HTTP?

Scott Chapman scott at mischko.com
Mon Feb 27 22:36:51 EST 2012


I've got a map and want to add a layer to it from a bunch of GeoJSON
formatted features that I can fetch from the server at
/kiosks_status_geoJSON/.  The server will return JSON format output.

Can someone point me to an example of how to do this or lay it out for me?

Some of my points of confusion include:

1) The docs (http://dev.openlayers.org/releases/OpenLayers-2.11/doc/apidocs/files/OpenLayers/Format/GeoJSON-js.html)
say that a GeoJSON Format.read() will deserialize a GeoJSON string,
but the example
(http://dev.openlayers.org/releases/OpenLayers-2.11/examples/geojson.html)
shows a GeoJSON.read() being passed an actual javascript object that's
already been deserialized.  Is it smart enough to deal with both
cases?

2) The overall flow of things.   I think I should make a Request.GET
to fetch the URL, an event handler to deal with the response having a
Format.geoJSON.read() the result and vector_layer.addFeatures on that.
 I'd love to see an example of this setup.

Thanks!
Scott


More information about the Users mailing list