admin管理员组

文章数量:1332345

I don't want to the show the layers control on the map, but I want to put some buttons somewhere else to change between layers. Is this possible to change the layer programmatically?

I don't want to the show the layers control on the map, but I want to put some buttons somewhere else to change between layers. Is this possible to change the layer programmatically?

Share edited Dec 7, 2013 at 1:47 nickponline asked Dec 7, 2013 at 1:30 nickponlinenickponline 25.9k34 gold badges106 silver badges178 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5

Suppose you have a map:

var map = L.map('worldmap-map').setView([37.8, -96], 4);

To remove a layer, layer1:

map.removeLayer(layer1)

To remove a control layer, ctrlLayer,

map.removeControl(ctrlLayer)

Or you want to add a layer1 to map:

layer1.addTo(map)

For an example, there is a Leaflet example : http://leafletjs./examples/choropleth-example.html

You could use firebug or chrome dev tools to see its source.

From https://stackoverflow./a/33762133/4355695 : Just myTileLayer.addTo(map) does the job of changing background layer (without adding on top), if it is already part of the base layers. And you don't need to explicitly remove the previously selected background layer.

本文标签: javascriptHow do I programatically change layers in LeafletStack Overflow