Skip to content

feat: add EditLine.unstable_addMarkerFilter - #1758

Merged
mscno merged 3 commits into
v3from
feat/marker-filters
Nov 26, 2026
Merged

mscno merged 3 commits into
v3from
feat/marker-filters

Conversation

@mscno

@mscno mscno commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Adds EditLine.unstable_addMarkerFilter(filter) and the type UnstableMarkerFilter from ./unstable (hook 2). Pro uses them to narrow the markers an editor shows, such as markers limited to the viewport. They are for @geoman-io packages and have no semver guarantee.

  • A filter is (pm, markers, latlng) => markers. It runs inside applyLimitFilters, after Free's closest-count pass (limitMarkersToCount), and gets that pass's markers. Several filters chain in the order they were added. latlng is the call's latlng: a pointer move's, or the caller's. It is undefined when the editor rebuilt its markers (on enable, after a reset or an insert), so a filter can tell a rebuild from a real point at 0, 0.
  • The markers include middle markers as well as vertex markers, because markerCache holds both. The JSDoc says so.
  • Filters apply when edit mode turns on: _initMarkers → filterMarkerGroup → applyLimitFilters({}). They also apply on every pass Free already runs: the throttled pointermove when limitMarkersToCount > -1, and the rebuild on pm:vertexremoved.
  • Free binds no new triggers. As agreed, Pro binds its own click and moveend handlers and calls pm.applyLimitFilters({ latlng }). That works with limitMarkersToCount -1, where Free binds no pointermove: filterMarkerGroup still builds markerCache and runs the first pass, and the test calls it directly in that mode.
  • applyLimitFilters now returns early when the editor has no marker cache: a Rectangle, which keeps its four corners, the rotate helper, or an editor that was never enabled. Before, only Free called it, through filterMarkerGroup, so that case was unreachable. A caller looping over edited layers would have thrown "markerCache is not iterable" at the first rectangle.
  • Filters are global (static on EditLine, a module-level list), like the toolbar's unstable_add* hooks. There is no remove; Pro adds its filter once.
  • With no filter added, behaviour is unchanged. The pass runs one null check and one loop over an empty list.

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

  • with limitMarkersToCount -1: the filter applies on enable with no latlng, a pointer move changes nothing because Free binds nothing, and a direct applyLimitFilters({ latlng }) re-applies it with that latlng. On a Rectangle the call doesn't throw, doesn't call the filter, and keeps 4 corners;
  • with limitMarkersToCount: 5: the filter gets the 5 closest markers and the pointer latlng in the throttled pointermove pass, and what it drops is hidden;
  • a control with no filter: the 5 closest markers show.

Mutants: not calling the filters fails 2 tests. Passing all of markerCache instead of the closest-count result fails 2. Dropping the no-cache return fails 1, and passing (0, 0) on rebuilds fails 1. test/types/unstable.mts adds an UnstableMarkerFilter through EditLine.unstable_addMarkerFilter.

Timings, with nothing registered: a 2000-vertex polygon, enable time, then 300 direct applyLimitFilters calls at moving latlngs. Electron/Chromium headless, base 0a3186c against head d7c0ccb. Each page records which build it loaded (head has unstable_addMarkerFilter). 12 alternating rounds per batch; paired is the median of head/base − 1 per round.

case base enable head enable base 300 passes head 300 passes paired enable paired passes
limitMarkersToCount: 20, batch 1 36.6 ms 49.2 ms 1740 ms 1772 ms +11.4% (head faster 3/12) +1.2% (4/12)
limitMarkersToCount: 20, batch 2 35.8 ms 34.7 ms 1736 ms 1728 ms +1.3% (5/12) −0.2% (7/12)
limitMarkersToCount: -1 185.5 ms 199.6 ms 245 ms 240 ms +3.0% (6/12) −1.9% (7/12)

That is noise. Batch 1's enable median comes from slow outlier runs: its 12 head enables span 35–92 ms and base's 33–126 ms, and batch 2 shows no difference. One enable is a single cold measurement. A pass costs about 6 ms with a limit, almost all of it Free's distance sort of 4000 markers, and 0.8 ms at -1; the change adds one check and one empty loop. Earlier batches on the pre-rebase head against 807c4f6 gave +2.3% and +0.7% for passes.

Checks: build, typecheck, lint, unit 103/103. Full e2e (Electron): base 483/483 (0a3186c), PR 486/486 (+3).

Independent review (Opus 5.5) at 02a0940: one Medium (the throw on editors without a cache) and one Low (the made-up (0, 0) on rebuilds). Both are fixed in d7c0ccb, which is rebased onto 0a3186c (#1757).

…ebuilds

A Rectangle, the rotate helper and a never-enabled editor have no marker
cache, so a caller's applyLimitFilters threw. On a rebuild the filters got a
made-up (0, 0) pointer; they now get undefined.

Amp-Thread-ID: https://ampcode.com/threads/T-4f0176da-b9a1-4ad0-aeca-c1780876e0eb
@mscno
mscno force-pushed the feat/marker-filters branch from 02a0940 to d7c0ccb Compare November 26, 2026 09:05
@mscno
mscno merged commit afefa35 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