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

Imran Rajjad rajjad at gmail.com
Mon Feb 27 23:30:37 EST 2012


Hi Scott,

function getJson(features)
{

var geojson_format = new OpenLayers.Format.GeoJSON(); // for json response
   var vectorlayer=map.getLayersByName(layerName)[0]; // get the layer
          vectorlayer.addFeatures(geojson_format.read(features));
}


this is how I do it, you did not mention the source of your JSON response.
Is it coming from some Gis server or a custom service, because you need to
embed the response as a script in the browser and it should be calling a
callback function.

regards,
Imran

On Tue, Feb 28, 2012 at 8:36 AM, Scott Chapman <scott at mischko.com> wrote:

> 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
> _______________________________________________
> Users mailing list
> Users at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/openlayers-users
>



-- 
I.R
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20120228/e94975e8/attachment.html


More information about the Users mailing list