本文介紹了將 Leaflet 圖層控件添加到側邊欄的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我正在使用 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模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!