I have a site that uses google api v3 for showing polygons from json files.
the site has multiple json polygons, I need to style each polygon with a different color and create a handle to the shape.
The only examples that I can find refer to pure polygons and not json files, there is one example that changes the json file (i cant do this as the json files are static.
sample code:
var map;
function initMap() {
map = new google.maps.Map(document.getElementById('map'), {
zoom: 4,
center: { lat: 45, lng: -90 }
});
//1st Json file
map.data.loadGeoJson(
'https://storage.googleapis.com/mapsdevsite/json/google.json');
//2nd json file (same as #1 for illustration purpose)
map.data.loadGeoJson(
'https://storage.googleapis.com/mapsdevsite/json/google.json');
// I want to style each Json file independently
map.data.setStyle({
fillColor: 'green',
strokeWeight: 1
});
// map1.setMap(map);
}
I managed to get the layer added to the map using,
data_layer.loadGeoJson('https://storage.googleapis.com/mapsdevsite/json/google.json');
// Construct the polygon.
var nLayer = new google.maps.JSON({
paths: data_layer,
strokeColor: 'green',
strokeOpacity: 0.5,
strokeWeight: 1,
fillColor: 'green',
fillOpacity: 0.8
});
nLayer.setMap(map);
I cannot get the style to apply to the map. any ideas ?