我試圖在使用L.GeoJSON(data).addTo(map)
的傳單地圖上繪製國家/地區形狀。然後我要綁定一個彈出該國形狀的單擊事件...在圖層組上打開傳單
new L.GeoJSON(data, {
onEachFeature: function(feature, layer) {
layer['on']('click', popupFunction);
}
}).addTo(this.map);
popupFunction = function(event) {
var layer = event.target;
// Open the 'add' popup and get our content node
var bound = layer.bindPopup(
"<div>Hello World!</div>"
).openPopup();
// Ugly hack to get the HTML content node for the popup
// because I need to do things with it
var contentNode = $(bound['_popup']['_contentNode']);
}
現在,當該數據是一個多邊形這工作得很好,因爲那時layer
屬性傳遞給onEachFeature功能就是這樣: 一層。
但是,如果data
是一個多面(即美國),這將停止,因爲「layer
」的工作現在是一個圖層組(它有一個_layers
)屬性,因此沒有_popup
屬性,所以我不能讓_contentNode
爲彈出。
看來這應該是一個相當普遍的事情,希望在layerGroup上彈出。爲什麼它沒有_popup
屬性?
如果這解決了您的問題,請將其設置爲正確答案 – 2016-12-21 11:43:01