[英]Add option for Blank TileLayer in Leaflet LayerGroup
I have a collection of BaseMaps I want users to be able to select: 我有一个BaseMaps集合,我希望用户能够选择:
var BaseMaps = {
// TODO blank tileLayer
"Default": L.tileLayer('https://{s}.tiles.mapbox.com/v3/{id}/{z}/{x}/{y}.png', {
id: 'examples.map-20v6611k',
noWrap: true
}),
"ESRI Roads": L.tileLayer('http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer/tile/{z}/{y}/{x}', {
noWrap: true
})
};
These layers are added to the LayerGroup control of my map with L.control.layers(BaseMaps).addTo(map)
and work as expected 使用L.control.layers(BaseMaps).addTo(map)
将这些图层添加到我的地图的LayerGroup控件中并按预期工作
The problem is I want the ability for the user to select a blank tile layer from the same control, effectively turning off the base map, but a null or blank tileLayer via L.tileLayer()
does not work as this breaks Leaflet functionality 问题是我希望用户能够从同一控件中选择空白图块层,有效地关闭基本地图,但是通过L.tileLayer()
的null或空白tileLayer不起作用,因为这会打破Leaflet功能
Is there a clean way to add a blank tileLayer option to this control? 是否有一种干净的方法可以为此控件添加空白的tileLayer选项? Digging through the API and various github/forum questions has not surfaced anything. 挖掘API和各种github /论坛问题并没有浮出水面。
Thanks in advance! 提前致谢!
Giving an empty string as url parameter works for me and doesn't throw any errors: 给出一个空字符串作为url参数对我有用,并且不会抛出任何错误:
var base = {
'Empty': L.tileLayer(''),
'OpenStreetMap': L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
'attribution': 'Map data © OpenStreetMap contributors'
})
};
Working example on Plunker: http://plnkr.co/edit/v7sICO?p=preview 关于Plunker的工作示例: http ://plnkr.co/edit/v7sICO?p = preview
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.