admin管理员组文章数量:1024581
I'm trying to bine 2 or more overlays into one overlay checkbox. I'm using leaflet layers control with mapbox.js 1.6 to toggle my overlays. It doesn't matter to me if I bine them on mapbox into one data layer, or if I bine separate data layers in my JS code into one overlay checkbox, but I can't seem to do either. I'm exporting MBTiles from Tilemill to my Mapbox account.
Note that it's not an option to:
- bine them in Tilemill (the single zoom level and square bounding box won't work for me across all layers)
- add the various data layers to a single map project on Mapbox (I'd like it to be toggleabe by the user)
I'm trying to bine 2 or more overlays into one overlay checkbox. I'm using leaflet layers control with mapbox.js 1.6 to toggle my overlays. It doesn't matter to me if I bine them on mapbox. into one data layer, or if I bine separate data layers in my JS code into one overlay checkbox, but I can't seem to do either. I'm exporting MBTiles from Tilemill to my Mapbox account.
Note that it's not an option to:
- bine them in Tilemill (the single zoom level and square bounding box won't work for me across all layers)
- add the various data layers to a single map project on Mapbox. (I'd like it to be toggleabe by the user)
2 Answers
Reset to default 4You can use L.layerGroup to bine layers
var group = L.LayerGroup([layer1, layer2];
// add default layers to map
map.addLayer(layer1);
// switcher
var baseLayers = {
"My Group": group,
// more layers
};
// add layer groups to layer switcher control
var controlLayers = L.control.layers(baseLayers).addTo(map);
You may be interested in this thread Leaflet layer control for basemap group layers
You can use the L.control.layers with the L.layerGroup. Here is the JSFiddle I wrote for this. You can add as many base or overlay layers you want.
Once you create the L.layerGroups, define the base and the overlay layers and add them to the control like this:
var controlLayers = L.control.layers(baseLayers, overlayMaps).addTo(map);
I'm trying to bine 2 or more overlays into one overlay checkbox. I'm using leaflet layers control with mapbox.js 1.6 to toggle my overlays. It doesn't matter to me if I bine them on mapbox into one data layer, or if I bine separate data layers in my JS code into one overlay checkbox, but I can't seem to do either. I'm exporting MBTiles from Tilemill to my Mapbox account.
Note that it's not an option to:
- bine them in Tilemill (the single zoom level and square bounding box won't work for me across all layers)
- add the various data layers to a single map project on Mapbox (I'd like it to be toggleabe by the user)
I'm trying to bine 2 or more overlays into one overlay checkbox. I'm using leaflet layers control with mapbox.js 1.6 to toggle my overlays. It doesn't matter to me if I bine them on mapbox. into one data layer, or if I bine separate data layers in my JS code into one overlay checkbox, but I can't seem to do either. I'm exporting MBTiles from Tilemill to my Mapbox account.
Note that it's not an option to:
- bine them in Tilemill (the single zoom level and square bounding box won't work for me across all layers)
- add the various data layers to a single map project on Mapbox. (I'd like it to be toggleabe by the user)
2 Answers
Reset to default 4You can use L.layerGroup to bine layers
var group = L.LayerGroup([layer1, layer2];
// add default layers to map
map.addLayer(layer1);
// switcher
var baseLayers = {
"My Group": group,
// more layers
};
// add layer groups to layer switcher control
var controlLayers = L.control.layers(baseLayers).addTo(map);
You may be interested in this thread Leaflet layer control for basemap group layers
You can use the L.control.layers with the L.layerGroup. Here is the JSFiddle I wrote for this. You can add as many base or overlay layers you want.
Once you create the L.layerGroups, define the base and the overlay layers and add them to the control like this:
var controlLayers = L.control.layers(baseLayers, overlayMaps).addTo(map);
本文标签: javascriptcombining overlays in mapboxleaflet layers controlStack Overflow
版权声明:本文标题:javascript - combining overlays in mapboxleaflet layers control - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745608420a2158862.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论