lundi 3 juin 2019

How to toggle on/off a geojson layer on a google maps html page

I'm confused about show and hide some geojson layer on a google map API V3 I want to set layer status by checkbox, i'dont know how to do this,

Now i'm able to set on more than 1 layer by the code below:

var geojesonlayer1 = new google.maps.Data();
var geojesonlayer2 = new google.maps.Data();
geojesonlayer1.loadGeoJson('mygeojson path');
geojesonlayer2.loadGeoJson('mygeojson path');
//layer style
geojesonlayer1.setStyle({
  strokeColor: 'yellow',
  strokeWeight: 5
});
geojesonlayer2.setStyle({
  strokeColor: 'blue',
  strokeWeight: 1
 });
//add layer to map
geojesonlayer1.setMap(map);
geojesonlayer2.setMap(map);
//remove layer from map
geojesonlayer1.setMap(null);
geojesonlayer2.setMap(null);




Aucun commentaire:

Enregistrer un commentaire