我正在使用 Leaflet sidebar V2 插件,我想知道是否可以将传单图层控制菜单放入侧边栏中?任何帮助是极大的赞赏!谢谢!
I'm using the Leaflet sidebar V2 plugin and am wondering if it is possible to put a leaflet layer control menu into the sidebar? Any help is greatly appreciated! Thanks!
只需使用 this 提示.它从地图容器中删除 L.control 元素并将其添加到新的父级.您可以直接对侧边栏执行此操作.
Just use this hint. It removes the L.control element from the map container and adds it to a new parent. You can do this for the sidebar straight forward.
HTML:
<div id="sidebar" class="sidebar collapsed">
<div class="sidebar-tabs">
<ul role="tablist">
<li>....</li>
<li>....</li>
</ul>
</div>
<div class="sidebar-content">
<div class="sidebar-pane" id="">
<h1 class="sidebar-header">...</h1>
<div id="example"> <!--Here the layer control menu will be added--></div>
</div>
</div>
JS:
var layer = L.control.layers(baseMaps, overlayMaps).addTo(map);
var htmlObject = layer.getContainer();
var a = document.getElementById('example')
function setParent(el, newParent){
newParent.appendChild(el);
}
setParent(htmlObject, a);
对我来说,这个解决方案效果很好.
For me, this solution worked well.
这篇关于将 Leaflet 图层控件添加到侧边栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
检查一个多边形点是否在传单中的另一个内部Check if a polygon point is inside another in leaflet(检查一个多边形点是否在传单中的另一个内部)
更改传单标记群集图标颜色,继承其余默认 CSSChanging leaflet markercluster icon color, inheriting the rest of the default CSS properties(更改传单标记群集图标颜色,继承其余默认
触发点击传单标记Trigger click on leaflet marker(触发点击传单标记)
如何更改 LeafletJS 中的默认加载磁贴颜色?How can I change the default loading tile color in LeafletJS?(如何更改 LeafletJS 中的默认加载磁贴颜色?)
将外部geojson添加到传单层Add external geojson to leaflet layer(将外部geojson添加到传单层)
Leaflet - 在弹出窗口中获取标记的纬度和经度Leaflet - get latitude and longitude of a marker inside a pop-up(Leaflet - 在弹出窗口中获取标记的纬度和经度)