mapbox / mapbox/mapbox-gl-draw

Polygon with 2 vertices disappears on click

Open
#1,446 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

auto-triaged bug
Dominant language
JavaScript
Stars
1.1k
Forks
612
Avg merge
8d 9h
Merged PRs (30d)
5

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] });
}
}
};

```

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the draw_polygon mode and reproduce the issue by creating a polygon with two vertices, then clicking either vertex. Check the vertex-click behavior and verify that two-vertex polygons remain visible and the map does not enter simple_select mode, while polygons with more than two vertices retain their expected 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
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.