我正在使用这个用于地图框的角度库来渲染地图ngx-mapbox-gl https://github.com/Wykks/ngx-mapbox-gl我在 mouseenter 事件上显示一个弹出窗口。
mapInstance.on("mouseenter", "scoots_layers", function (e) {
var _lat = e.lngLat.lat;
var _lng = e.lngLat.lng;
var coordinates = [_lng, _lat];
this.popup = new Popup({
closeButton: true,
closeOnClick: true,
});
this.popup.setLngLat(coordinates)
.setHTML('<button (click)="goToPage()">Hello </button>')
.addTo(mapInstance);
});
弹出窗口工作正常。但按钮的点击事件没有被触发。
也许如果你这样做它会起作用
this.popup.setLngLat(coordinates)
.setHTML('<button id="myBtn">Hello </button>')
.addTo(mapInstance);
});
并在你的 ts 文件中
document.getElementById("myBtn").addEventListener("click", function(){
alert('say something...');
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)