当我单击地图上的标记时,单击也将由标记下方运行的路径的onclick侦听器记录。我该如何阻止这种情况的发生?我希望点击仅由标记的onclick侦听器注册。
标记的代码:
var el = document.createElement('div');
el.className = 'marker';
el.addEventListener('click', () => {
//functions
})
const marker = new mapboxgl.Marker(el)
.setLngLat([location.longitude, location.latitude])
.addTo(this.map);
该层的代码:
map.addLayer({
"id": "route",
"type": "line",
"source": {
"type": "geojson",
"data": path
},
"layout": {
"line-join": "round",
"line-cap": "round"
},
"paint": {
"line-color": "#888",
"line-width": 8
}
});
答案 0 :(得分:1)
尝试捕获事件并停止传播:
el.addEventListener('click', e => {
e.stopPropagation();
//functions
}, true);