Skip to content

feat: add EditLine#unstable_insertVertex - #1757

Merged
mscno merged 4 commits into
v3from
feat/insert-vertex
Nov 26, 2026
Merged

mscno merged 4 commits into
v3from
feat/insert-vertex

Conversation

@mscno

@mscno mscno commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Adds EditLine#unstable_insertVertex(indexPath, latlng) (hook 1) for Pro's add-vertex-on-click. It is for @geoman-io packages and has no semver guarantee. EditPolygon inherits it; EditRectangle does too, but Pro doesn't call it there.

  • indexPath is the path the new vertex will have: [0, 3] inserts before ring 0's vertex 3, [2] on a line before vertex 2, and the ring's length appends.
  • It splices a copy of the latlng into the coordinates and rebuilds the vertex and middle markers with _initMarkers() (and snapping when snappable). So it needs no middle marker and works with hideMiddleMarkers, where the fork's fallback of firing a middle marker's event failed.
  • It fires what a middle-marker insert (_addMarker) fires, in the same order: pm:edit, then pm:change, then pm:vertexadded with the new indexPath, marker and latlng. It also sets _layerEdited, so pm:update follows on disable.
    • Decided by the landing owner: this differs from the fork's _insertVertex, which fires only pm:vertexadded. The Pro port lists it as a user-visible difference.
  • No validator action and no addVertexValidation, as in the fork.
  • It returns the new vertex marker, or undefined when edit is off or rotate mode is on (the rotate helper's editor has no vertex markers). A path that is no vertex position throws a RangeError: a wrong ring, an index out of range, a non-integer, or a ring path on a polygon. On a polygon, a vertex that would close the ring also throws a RangeError, because Leaflet drops a closing duplicate. That is a vertex at the ring's end equal to its first vertex, or at index 0 equal to its last. The JSDoc says to call it outside a vertex drag.
  • Nothing in Free calls it, so behaviour is unchanged. The CHANGELOG gets one unstable-hook line.

Tests: new cypress/e2e/insertVertex.cy.ts, 3 tests:

  • a polygon insert: coordinates, a copied LatLng, 5 markers and 5 middle markers, the returned marker, event order and payload, the new vertex dragging like any other, and one pm:update on disable;
  • hideMiddleMarkers and a line;
  • invalid paths and ring-closing vertices throwing with nothing changed, a no-op when edit is off or on the rotate helper, and appending at the ring's end.

Mutants: firing only pm:vertexadded (the fork's events) fails 1 test, skipping the marker rebuild fails 2, and dropping the ring-closing throw or the rotate check each fails 1. test/types/unstable.mts calls it on an EditLine from ./unstable.

Checks: build, typecheck, lint, unit 103/103. Full e2e (Electron): base 480/480 (807c4f6), PR 483/483 (+3) at 1fe3d48; 2c13f0c only fixes JSDoc wording.

Independent review (Opus 5.5): three findings at fc8019f (the ring-closing duplicate, rotate mode, and the drag note), all fixed and confirmed at 1fe3d48.

… drags

Leaflet drops a polygon ring's closing duplicate, so inserting a copy of the
neighbouring vertex across the ring's start lost a vertex (or the new one)
while still firing the events. Throw a RangeError instead. The rotate
helper's editor has no vertex markers, so return undefined there.

Amp-Thread-ID: https://ampcode.com/threads/T-4f0176da-b9a1-4ad0-aeca-c1780876e0eb
…ction

EditRectangle inherits the hook, but a Rectangle keeps its 4 corner markers,
so an insert left a 5-vertex ring and returned a corner marker. Return
undefined there and change nothing.

Amp-Thread-ID: https://ampcode.com/threads/T-4f0176da-b9a1-4ad0-aeca-c1780876e0eb
@mscno
mscno merged commit 0a3186c into v3 Nov 26, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants