Update leaflet baselayer properties with GoogleMutant

522 Views Asked by At

I have a google layer (baselayer) GoogleMutant and want to update its options. I try to

map.remove(google.layer)
//update the POI visibility
google.layer.options.styles.forEach(i=>i.stylers[0].visibility = "off")
map.addLayer(google.layer)

this updates the layer options but the Points of interest are still on the map. Is there any way to update the options and apply them to the baselayer? Thanks

Here is an example with google mutant https://jsfiddle.net/benderlio/2m4c01w6/10/ There is a button "remove POI", and I want to remove all poi from current layer with leaflet API

1

There are 1 best solutions below

0
On BEST ANSWER

Leaflet doesn't work changing settings on the fly. You have to remove the whole object and create a substitute.

Like if you need to change a layer, you have to remove it like:

roadMutant.removeFrom(map); // or
map.removeLayer(roadMutant);

And then create and add the new one:

roadMutant.addTo(map);

I created a fiddle to help the change based on yours. It still have bugs and somewhere to grow, but it's a base...