<div>Hi Scott,</div><div><br></div><div>function getJson(features)</div><div>{</div><div><br></div><div>var geojson_format = new OpenLayers.Format.GeoJSON(); // for json response</div><div> <span class="Apple-tab-span" style="white-space:pre">        </span>var vectorlayer=map.getLayersByName(layerName)[0]; // get the layer</div>
<div> <span class="Apple-tab-span" style="white-space:pre">        </span>vectorlayer.addFeatures(geojson_format.read(features));</div><div>}</div><div><br></div><div><br></div><div>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.</div>
<div><br></div><div>regards,</div><div>Imran</div><br><div class="gmail_quote">On Tue, Feb 28, 2012 at 8:36 AM, Scott Chapman <span dir="ltr"><<a href="mailto:scott@mischko.com">scott@mischko.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I've got a map and want to add a layer to it from a bunch of GeoJSON<br>
formatted features that I can fetch from the server at<br>
/kiosks_status_geoJSON/. The server will return JSON format output.<br>
<br>
Can someone point me to an example of how to do this or lay it out for me?<br>
<br>
Some of my points of confusion include:<br>
<br>
1) The docs (<a href="http://dev.openlayers.org/releases/OpenLayers-2.11/doc/apidocs/files/OpenLayers/Format/GeoJSON-js.html" target="_blank">http://dev.openlayers.org/releases/OpenLayers-2.11/doc/apidocs/files/OpenLayers/Format/GeoJSON-js.html</a>)<br>
say that a GeoJSON Format.read() will deserialize a GeoJSON string,<br>
but the example<br>
(<a href="http://dev.openlayers.org/releases/OpenLayers-2.11/examples/geojson.html" target="_blank">http://dev.openlayers.org/releases/OpenLayers-2.11/examples/geojson.html</a>)<br>
shows a GeoJSON.read() being passed an actual javascript object that's<br>
already been deserialized. Is it smart enough to deal with both<br>
cases?<br>
<br>
2) The overall flow of things. I think I should make a Request.GET<br>
to fetch the URL, an event handler to deal with the response having a<br>
Format.geoJSON.read() the result and vector_layer.addFeatures on that.<br>
I'd love to see an example of this setup.<br>
<br>
Thanks!<br>
Scott<br>
_______________________________________________<br>
Users mailing list<br>
<a href="mailto:Users@lists.osgeo.org">Users@lists.osgeo.org</a><br>
<a href="http://lists.osgeo.org/mailman/listinfo/openlayers-users" target="_blank">http://lists.osgeo.org/mailman/listinfo/openlayers-users</a><br>
</blockquote></div><br><br clear="all"><div><br></div>-- <br>I.R<br>