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

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

问题描述

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

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

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