【发布时间】:2017-01-26 18:55:08
【问题描述】:
我正在使用 Openlayers 3 开发网络地图应用程序,我在地图上显示要素(点),当我单击它们时,我会显示一个弹出窗口,其中我添加了一个按钮。这是弹出窗口和按钮代码:
map.on('singleclick', function(evt) {
popup.hide();
popup.setOffset([0, 0]);
// Attempt to find a feature in one of the visible vector layers
var feature = map.forEachFeatureAtPixel(evt.pixel, function(feature, layer) {
return feature;
});
if (feature) {
var coord = feature.getGeometry().getCoordinates();
var props = feature.getProperties();
var info = "<input type='button' id='popupButton' value='Get here ?' />" ;
// Offset the popup so it points at the middle of the marker not the tip
popup.setOffset([0, -22]);
popup.show(coord, info);
}
});
之后我在stackoverflow中看到了一些类似的问题,我尝试使用这段代码在事件触发时启动一个函数:
$(document).on("click", "#popupButton", function(){
alert(nearest_feature(my_position));
});
问题是事件没有被触发,我尝试用“#map”(这是显示地图的 div)替换文档,但仍然没有。
如何在弹出窗口中触发该按钮的事件?
【问题讨论】:
标签: javascript jquery html openlayers-3