mapbox / mapbox/mapbox-gl-draw

Disable other events with other layers on map while drawing new polygon

Open
#1,166 2 comments 0 reactions 0 assignees View on GitHub
auto-triaged feature
Dominant language
JavaScript
Stars
1.1k
Forks
612
Avg merge
8d 9h
Merged PRs (30d)
5

Description

Hello,

I'm using mapbox-gl-draw with maplibre.
I use the following code:
```
maplibre = new maplibregl.Map({
container: carte.value,
style: etalab,
center: [-1.5558731878137084, 47.218394135080096], // Nantes
zoom: 14,
});
var draw = new MapboxDraw({
displayControlsDefault: false,
// Select which mapbox-gl-draw control buttons to add to the map.
controls: {
polygon: true,
trash: true
}
});
maplibre.addControl(draw);
maplibre.on('draw.create', (e) => {
if (shapelibre?.id) draw.delete(shapelibre.id)
const data = draw.getAll();
if (data.features.length > 0) {
shapelibre = data.features[0]
maj(shapelibre);
}
});
maplibre.on('draw.delete', (e) => {
maj();
});
```

Later on, I add some geojson shapes (layers) on the map and have some events (hover, click) when the user interacts with them:
```
maplibre.addSource('mylayer', {
'type': 'geojson',
'data': mydata,
'promoteId': "id"
});

maplibre.addLayer({
'id': 'mylayer-fill',
'type': 'fill',
'source': 'mylayer',
...
})
maplibre.on('mousemove', 'parcellesnew-fill', (e) => {
maplibre.getCanvas().style.cursor = 'pointer';
if (e.features.length === 0) return;
...
});
```
When I draw a polygon with mapbox-draw-gl, all events with those geojson shapes get fired and interfere with the polygon drawing.

How can I avoid that?

Thanks a lot
Samuel

Contributor guide

Open the contributing guide

Research direction

Start with the maplibre.addControl(draw) setup and the draw.create/draw.delete handlers, then reproduce the issue while the mylayer-fill mousemove handler is active. Trace how drawing mode and the GeoJSON-layer events interact; done means drawing a polygon no longer triggers or interferes with the shown layer hover and click behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.