如何停止层单击事件的事件传播。
mapBox.on('click', layerId, function (e) {
console.log(e);
//e.stopPropagation(); which is not working
//e.originalEvent.stopPropagation(); which is not working
var popupHtml = getPopupHtmlWrapper(e.features[0]);
new mapboxgl.Popup({closeButton:false})
.setLngLat(e.lngLat)
.setHTML(popupHtml)
.addTo(mapBox);
});
Run Code Online (Sandbox Code Playgroud) 我有一个组件,有时被用作父组件的子组件,有时它没有任何父组件。
该组件发出一个特定的事件,该事件要么被父级捕获(如果订阅),要么我想由该组件本身处理它。
那么在运行时,我如何以编程方式检查
if (someone is listening to the event){
let them catch and handle it
}else {
let's handle it by our own
}
Run Code Online (Sandbox Code Playgroud)