Skip to content

Extract shared RoutePolylineReconciler for both map flavors (#1906)#1918

Merged
bmander merged 1 commit into
mainfrom
fix/1906-route-polyline-reconciler
Jul 16, 2026
Merged

Extract shared RoutePolylineReconciler for both map flavors (#1906)#1918
bmander merged 1 commit into
mainfrom
fix/1906-route-polyline-reconciler

Conversation

@bmander

@bmander bmander commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Fixes #1906.

Problem

The route-polyline reconcile/width algorithm (~60 lines) was duplicated verbatim across GoogleMapRenderer and MapLibreRenderer: the identity/equality early-exit, the reconcileEqualItems diff, per-index width comparison against the stored widths, the native width patch, the three-field state update, and the camera-settle width resync. As the issue notes, a single bug fix had recently had to be applied by hand to both copies — the maintenance hazard this refactor removes.

Change

Introduce RoutePolylineReconciler<NativeLine> in the existing map/render module. It owns all the flavor-neutral bookkeeping and is parameterized by the four genuinely platform-specific operations over the opaque native-line type:

  • widthOf(polyline, zoom) — resolve a line's pixel width (gms scales by density; maplibre doesn't)
  • createLine(polyline, width) — mint a native line
  • removeLines(lines) — batch removal (gms remove() per line; maplibre removeAnnotations)
  • setWidth(line, width) — patch a live line's width

Each renderer now holds a RoutePolylineReconciler<Polyline> supplying those, and renderRoutePolylines / onCameraSettled / dispose collapse to single delegations (reconcile / resyncWidths / clear). Three private state fields and the reconcileEqualItems import drop out of each renderer.

Behavior is unchanged — a pure extraction. The MapLibre dispose keeps its exact prior semantics (route lines cleared before the mass removeAnnotations()).

Tests

New RoutePolylineReconcilerTest (11 cases) drives the shared logic through a fake native line: retain-equal, remove-gone, create-new, patch-changed-width, patch-skipped-when-unchanged, the same-list O(1) no-op, resyncWidths, and clear.

Verification

  • Both flavors compile clean under -PwarningsAsErrors=true (the CI gate).
  • Render unit-test suite passes on obaGoogle and obaMaplibre.
  • Rebased onto latest main (Cleanup: small-exhaust sweep from the 2026-07-16 debt review #1915); main's concurrent renderer edits were comment/constant drift outside the reconcile path, so the merge was clean.

🤖 Generated with Claude Code

The route-polyline reconcile/width algorithm was duplicated verbatim across
GoogleMapRenderer and MapLibreRenderer: the identity/equality early-exit, the
reconcileEqualItems diff, per-index width comparison against the stored widths,
the native width patch, the three-field state update, and the camera-settle
width resync. A single bug fix had to be applied by hand to both copies.

Move that flavor-neutral bookkeeping into a new
RoutePolylineReconciler<NativeLine> in the render module, parameterized by the
four genuinely platform-specific operations over the opaque native line type:
width resolution, line creation, batch removal, and width patch. Each renderer
now supplies those and calls reconcile()/resyncWidths()/clear(), dropping ~60
lines of duplicated logic and its three private state fields.

Add RoutePolylineReconcilerTest covering retain-equal, remove-gone, create-new,
patch-changed-width, the same-list O(1) no-op, resync, and clear via a fake
native line. Behavior is unchanged on both flavors; both compile clean under
-PwarningsAsErrors and the render test suite passes on obaGoogle and obaMaplibre.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@bmander
bmander merged commit ac3e7c2 into main Jul 16, 2026
2 checks passed
@bmander
bmander deleted the fix/1906-route-polyline-reconciler branch July 16, 2026 23:02
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.

Map: route-polyline reconcile/width algorithm duplicated verbatim across Google and MapLibre renderers

1 participant