[OpenLayers-Users] Make vector layer from JSON
Robert Sanson
SansonR at asurequality.com
Wed Mar 10 19:14:46 EST 2010
Thanks Atle - this is what is working for me from the returned JSON:
var myObject = JSON.parse(response.responseText); //JSON.parse is a parser based on json2.js
var x_nztm = (+myObject.results[0].attributes.x_nztm);
var y_nztm = (+myObject.results[0].attributes.y_nztm);
var mggeom = new OpenLayers.Geometry.Point(x_nztm,y_nztm);
var mgfeat = new OpenLayers.Feature.Vector(mggeom);
mgfeat.attributes.farm_id = myObject.results[0].attributes.farm_id;
mgfeat.attributes.rapid_no = myObject.results[0].attributes.rapid_no;
mgfeat.attributes.road_name = myObject.results[0].attributes.road_name;
mgfeat.attributes.locality = myObject.results[0].attributes.locality;
var maingatewfs = new OpenLayers.Layer.Vector("Main Gate 2",
{isBaseLayer: false,
styleMap: style_gate,
extractAttributes: true });
maingatewfs.addFeatures(mgfeat);
map.addLayer(maingatewfs);
Robert Sanson
>>> "Sveen Atle Frenvik (Geomatikk IKT)" <Atle.Frenvik.Sveen at geomatikk.no> 9/03/2010 1:32 a.m. >>>
As long as you are able to parse the data, putting them on the map is a
no-brainer, pseudo-code something like:
for each feature
- fetch x and y
- create an OpenLayers Geometry
- create a OpenLayers Vector feature
- add attributes to feature if required
then add features to a layer
-atle
------------------------------------------------------------------
The contents of this email are confidential to AsureQuality. If you have received this communication in error please notify the sender immediately and delete the message and any attachments. The opinions expressed in this email are not necessarily those of AsureQuality. This message has been scanned for known viruses before delivery. AsureQuality supports the Unsolicited Electronic Messages Act 2007. If you do not wish to receive similar communications in future, please notify the sender of this message.
------------------------------------------------------------------
This message has been scanned for malware by SurfControl plc. www.surfcontrol.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20100311/e65bc382/attachment.html
More information about the Users
mailing list