Skip to content

Fix overlay insertion index and batch annotation updates - #16

Merged
esenmx merged 2 commits into
masterfrom
perf/batch-annotations-and-overlay-index-fix
Aug 12, 2026
Merged

Fix overlay insertion index and batch annotation updates#16
esenmx merged 2 commits into
masterfrom
perf/batch-annotations-and-overlay-index-fix

Conversation

@esenmx

@esenmx esenmx commented Aug 12, 2026

Copy link
Copy Markdown
Owner

Summary

Fixes a z-ordering bug in MKMapView.addFlutterOverlay where a co-located FlutterTileOverlay skewed the insertion index for vector overlays, and batches annotation adds/removals through addAnnotations/removeAnnotations instead of per-item calls.

Changes

  • FlutterOverlay.swiftaddFlutterOverlay previously counted only FlutterOverlay peers to compute an insertion index, then indexed into the level's full overlay array (which also includes non-FlutterOverlay peers like FlutterTileOverlay, which defaults to .aboveRoads alongside vector overlays). That mismatch corrupted zIndex ordering whenever a tile overlay shared a level with vector overlays. Now uses firstIndex(where:) over the full peer array to find the first Flutter peer with strictly greater zIndex, inserting before it (or appending when none is found); equal zIndex still preserves insertion order, and non-Flutter peers never shift the position.
  • AnnotationController.swiftannotationsToAdd and annotationsToRemove now call mapView.addAnnotations(_:) / mapView.removeAnnotations(_:) once per batch instead of looping with single-item addAnnotation/removeAnnotation, mirroring the batched overlay removal from ⚡ Optimize overlay updates with batched removal #15. Bookkeeping (annotationsById) and stale-id dedup on re-add are unchanged; annotationsToChange still updates in place.

Test plan

  • CI: Example iOS build + tests

Notes

Local simulator build currently fails on master under a stricter local Xcode toolchain flagging UIScreen.main isolation in PlatformAliases.swift. Pre-existing and unrelated to this change, so it's not addressed here; CI remains the verification path for this branch.

🤖 Generated with Claude Code

esenmx and others added 2 commits August 12, 2026 11:18
addFlutterOverlay counted only FlutterOverlay peers for the insertion
index but applied it against the level's full overlay array, which
can also hold tile overlays (FlutterTileOverlay doesn't conform to
FlutterOverlay and shares the .aboveRoads default level). A tile
overlay in that array skewed every subsequent vector-overlay insert,
breaking zIndex order and letting vectors land below the tile.

Now the position is found with firstIndex over the full array: insert
directly before the first Flutter peer with a strictly greater
zIndex, append when there is none. Non-Flutter peers can no longer
shift the index.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
annotationsToAdd and annotationsToRemove called
mapView.addAnnotation/removeAnnotation once per item, each an O(N)
pass in MapKit. They now collect items and issue single
addAnnotations/removeAnnotations calls, mirroring the batched overlay
removal merged in PR #15.

Dictionary bookkeeping and the replace-existing-id dedup behavior are
unchanged; annotationsToChange keeps its in-place update path.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@esenmx
esenmx merged commit 85d73af into master Aug 12, 2026
7 checks passed
@esenmx
esenmx deleted the perf/batch-annotations-and-overlay-index-fix branch August 12, 2026 08:22
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.

1 participant