使用复选框(而不是单选按钮)控制传单层吗? [英] Make leaflet layers control with checkboxes, not radio buttons?

查看:86
本文介绍了使用复选框(而不是单选按钮)控制传单层吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种简单的方法来制作传单层控件 (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层.

L.control.layers(WMS, null, {collapsed: false}).addTo(map);
where WMS is multiple L.tileLayer.wms layers.

推荐答案

将您的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.

这篇关于使用复选框(而不是单选按钮)控制传单层吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆