javascript 如何更新传单中 WMS 图层的不透明度?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15917031/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to update opacity of WMS layer in leaflet?
提问by Setsuna
How do I adjust opacity in leaflet without calling "removeLayer"? I have already used "map.addLayer(myLayer)" to my map. I see that there is a setParams() method, but it appears to have no effect when I call "myLayer.setParams({opacity:0.1})" and there is no refresh button for the WMS. Is this even possible in Leaflet? If so, how? Is there even someway to call something along the lines of "map.getLayers()" or something to be able to retrieve already added layers to the map?
如何在不调用“removeLayer”的情况下调整传单中的不透明度?我已经在我的地图上使用了“map.addLayer(myLayer)”。我看到有一个 setParams() 方法,但是当我调用“myLayer.setParams({opacity:0.1})”并且WMS没有刷新按钮时它似乎没有效果。这在传单中甚至可能吗?如果是这样,如何?甚至有什么方法可以调用“map.getLayers()”之类的东西,或者可以检索已添加到地图的图层?
采纳答案by snkashis
Use setOpacity
like layer.setOpacity(0.5)
使用setOpacity
喜欢layer.setOpacity(0.5)
API Docs - http://leafletjs.com/reference.html#tilelayer-opacity(scroll down a bit)
API 文档 - http://leafletjs.com/reference.html#tilelayer-opacity(向下滚动一点)