2014-12-28 94 views
0

Leaflet支持的插件Leaflet.GroupedLayerControl現在支持專用分組圖層(通過與基本圖層功能類似的單選按鈕)。Collapse Leaflet帶獨有圖層的GroupedLayerControl

但是,由於獨佔分組層的實現,在調用專用層組時,isCollapsed呼叫不再像預期的那樣執行。如果未調用,基礎層和分組層仍會按預期執行,但只要將專用分組層添加到代碼中就會出現問題。

代碼詢問用於分組層控制塌陷如果窗口< = 767px否則如果窗口較大,以顯示其全部的分組層的控制:基於我最初的試驗和

 if (document.body.clientWidth <= 767) { 
      var isCollapsed = true; 
     } else { 
      var isCollapsed = false; 
     } 


     var layerControl = L.control.groupedLayers(baseLayers, groupedOverlays, options, { 
      collapsed: isCollapsed 
     }).addTo(map); 

出現錯誤,無法修改現有更改以使分組圖層控件在超過767px寬度的窗口中打開,並且Leaflet.GroupedLayerControl中唯一的代碼更改包括基本獨佔組代碼。我猜測需要額外的代碼來確保分組圖層控件中包含專用圖層。

有關疑難解答,請看:working JS fiddle WITHOUT exclusive layersnon-working JS fiddle WITH exclusive layers

回答

0

嘗試移動collapsed: isCollapsed的選項對象,像這樣:

var options = {exclusiveGroups: ["Landmarks"], collapsed: isCollapsed};

相關問題