-
Notifications
You must be signed in to change notification settings - Fork 605
Open
Description
How to reproduce?
- set draw polygon mode
- tap two vertices on the map
- click on each on the two vertices
Expected result
- nothing happens
Actual result
- the polygon disappears and the map enters in simple_select mode
possible correction
import { MapboxDrawCustomMode } from '@mapbox/mapbox-gl-draw';
import MapboxDraw from '@mapbox/mapbox-gl-draw';
const DrawModes = {
SIMPLE_SELECT: 'simple_select',
DIRECT_SELECT: 'direct_select'
};
// Start with a copy of the original draw_polygon mode
const DrawPolygonMode = MapboxDraw.modes.draw_polygon;
// Override or extend the mode with custom functionality
export const DrawPolygonModeUndo: MapboxDrawCustomMode = {
...DrawPolygonMode, // Copy all existing methods
clickOnVertex(state) {
// If there are more than 2 vertices, finish the polygon on vertex click
// This corrects a bug, where if there are only two vertices and a vertex is clicked,
// the polygon is closed and disappears.
// Check if state has property 'polygon'
if (!('polygon' in state)) {
return;
}
if (state.currentVertexPosition > 2) {
// Only close the polygon if there are more than 2 vertices
return this.changeMode(DrawModes.SIMPLE_SELECT, { featureIds: [state.polygon.id] });
}
}
};
Metadata
Metadata
Assignees
Labels
No labels