How can I stop event propagation on layer click events?
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);
});
Click the Type option, and then choose the Symbol layer option so you can create a layer with markers.
Mapbox Studio is supported in browsers that support WebGL, a method of generating dynamic 3D graphics using JavaScript, accelerated through hardware. Mapbox Studio is compatible with all modern browsers, specifically: Safari 9 and above. Chrome latest.
Per the suggestion by @Stophface, I used
e => {
const features = map.queryRenderedFeatures(e.point)
if (features[0].layer.id === myLayerName ) {
doMyClickAction(e)
}
}
so as to only do something with the event when the layer I care about in this instance is the first one that is clicked.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With