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 badges2 Answers
Reset to default 5Suppose 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
版权声明:本文标题:javascript - How do I programatically change layers in Leaflet? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742262760a2442823.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论