問題描述
有沒有一種簡單的方法來制作 傳單層控件(L.control.layers
) 使用復選框而不是單選按鈕?
Is there an easy way to make a leaflet layers control (L.control.layers
) use checkboxes rather than radio buttons?
我有多個 WMS 切片圖層,我希望能夠在地圖上同時擁有多個圖層.就上下文而言,WMS 切片圖層包括水深測量和等高線(地形線),因此將兩者同時可視化會提供更多信息,而不是僅僅讓一些線漂浮在海洋中.
I have multiple WMS tile layers, and I'd like to be able to have more than one on the map at the same time. For context, the WMS tile layers include bathymetry and contours (topo lines), so it'd be more informative to visualize both at the same time, rather than just having some lines floating in the ocean.
在 傳單示例中,它說圖層控件足夠聰明"可以知道分配單選按鈕和復選框,但最好有更多自定義控件.
In the leaflet example it says the layers control is "smart enough" to know which to assign radio buttons and which checkboxes, but it'd be nice to have more customized control.
相關代碼:
L.control.layers(WMS, null, {collapsed: false}).addTo(map);
其中 WMS
是多個 L.tileLayer.wms
層.
推薦答案
將您的 WMS
作為第二個參數(即作為疊加層)而不是 L.control 的第一個(底圖)傳遞.layers
.
Pass your WMS
as the 2nd argument (i.e. as overlays) instead of the 1st (basemaps) of L.control.layers
.
疊加使用復選框,而底圖使用單選按鈕.
Overlays use check boxes, whereas basemaps use radio buttons.
這篇關于使用復選框而不是單選按鈕來控制傳單層?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!