单击标记会单击其下方的图层 (Mapbox-gl)
Clicking on a marker clicks the layer below it (Mapbox-gl)
当我点击地图上的标记时,该点击也会被标记下方路径 运行 的 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
}
});
尝试捕获事件并停止其传播:
el.addEventListener('click', e => {
e.stopPropagation();
//functions
}, true);
当我点击地图上的标记时,该点击也会被标记下方路径 运行 的 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
}
});
尝试捕获事件并停止其传播:
el.addEventListener('click', e => {
e.stopPropagation();
//functions
}, true);