2014-06-13 79 views
1

我想顯示每個地圖標記的工具提示onload,而不需要懸停或單擊以顯示它。這裏是我嘗試鏈接openPopup函數bindPopup:mapbox顯示多個工具提示onload

function onEachFeature(feature, layer) { 
     if (feature.properties && feature.properties.popupContent) { 
      popupContent = feature.properties.popupContent; 
     } 
     layer.bindPopup(popupContent).openPopup(); 
    } 

但是,工具提示不會出現,除非點擊。

fiddle

我看到文檔的this page提供了以下功能,但它只是一個單一的標記,而不是多重的。

marker.eachLayer(function(m) { 
    m.openPopup(); 
}); 

如何顯示所有標記onload?

回答

1

不幸的是,這是彈出窗口在傳單中的工作原理。

有一個在https://stackoverflow.com/a/16707921/128165

/*** little hack starts here ***/ 
L.Map = L.Map.extend({ 
    openPopup: function (popup) { 
     //  this.closePopup(); // just comment this 
     this._popup = popup; 

     return this.addLayer(popup).fire('popupopen', { 
      popup: this._popup 
     }); 
    } 
}); /*** end of hack ***/ 

提供一旦你添加到您的代碼,你可以使用

for (var o in overlays){ 
    overlays[o].eachLayer(function (m) { 
     m.eachLayer(function(l){l.openPopup();}); 
    }); 
} 

遍歷你的情況下,所有的標記,並呼籲他們openPopup方法的小黑客

Demo athttp://jsfiddle.net/46f2r/6/

+0

美麗,謝謝 – nathanbweb