I am new to JavaScript and facing some difficulties in converting GeoJSON to a JavaScript Object Array.
Using JSON.parse, I successfully parse the JSON generated on the server into a JSON Object.
The addGeoJson method from Google returns [object (Array)], displaying the shape on the map immediately. However, I require it later for different granularities when zooming in or out.
How can I generate an [object (Array)] from an [object]? Specifically, how do I do this with "generatedGeoJsonPlz2"?
This is my current progress:
var generatedGeoJsonPlz1 = JSON.parse(geoJsonString);
var generatedGeoJsonPlz2 = JSON.parse(geoJsonString2);
var plz1area = plz.data.addGeoJson(generatedGeoJsonPlz1); // returns [object (Array)]
plz.addListener('zoom_changed', function() {
var zoom = plz.getZoom();
if (zoom == 8) {
for (var i = 0; i < plz1area.length; i++) {
plz.data.remove(plz1area[i]);
}
plz.data.addGeoJson(generatedGeoJsonPlz2);
}
else if (zoom == 5) {
var plz2area = generatedGeoJsonPlz2;
for (var i = 0; i < plz2area.length; i++) {
plz.data.remove(plz2area[i]);
}
plz.data.addGeoJson(generatedGeoJsonPlz1);
}
}
Thank you! Christian