Friday, 19 April 2019

Adding multiple OpenLayers Vector Layer markers with data parsed from JSON file?


I would like to parse a local JSON file and add markers to a map based on the latitude and longitude parsed from the JSON file.


Here is a sample from the local JSON file:


"LOCATION_A": {
"latitude": 10.2070,
"longitude": 25.3215,

"altitude": 1.2,
"status": "CLOSED",
"serverAddress": "192.168.0.1"
}

I am unsure how to proceed beyond the following block of code:


var markers = new OpenLayers.Layer.Vector("Sites", {
projection: map.displayProjection,
strategies: [new OpenLayers.Strategy.Fixed()],
protocol: new OpenLayers.Protocol.HTTP({

url: "filename.json",
format: new OpenLayers.Format.JSON()
}),
});

I am unsure how to use the parser to do this. I would like to use jQuery for this exercise now.



Answer



var json_array = ;

for (var item in json_array) {

for(var value in item) {
var feature = new Openlayers.Feature.Vector(
new Openlayers.Geometry.Point(value.longitude, value.latitude),
value
);
markers.addFeatures[feature]);
}
}

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...