我试图在使用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