Fix overlay insertion index and batch annotation updates - #16
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes a z-ordering bug in
MKMapView.addFlutterOverlaywhere a co-locatedFlutterTileOverlayskewed the insertion index for vector overlays, and batches annotation adds/removals throughaddAnnotations/removeAnnotationsinstead of per-item calls.Changes
FlutterOverlay.swift—addFlutterOverlaypreviously counted onlyFlutterOverlaypeers to compute an insertion index, then indexed into the level's full overlay array (which also includes non-FlutterOverlaypeers likeFlutterTileOverlay, which defaults to.aboveRoadsalongside vector overlays). That mismatch corruptedzIndexordering whenever a tile overlay shared a level with vector overlays. Now usesfirstIndex(where:)over the full peer array to find the first Flutter peer with strictly greaterzIndex, inserting before it (or appending when none is found); equalzIndexstill preserves insertion order, and non-Flutter peers never shift the position.AnnotationController.swift—annotationsToAddandannotationsToRemovenow callmapView.addAnnotations(_:)/mapView.removeAnnotations(_:)once per batch instead of looping with single-itemaddAnnotation/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;annotationsToChangestill updates in place.Test plan
Notes
Local simulator build currently fails on
masterunder a stricter local Xcode toolchain flaggingUIScreen.mainisolation inPlatformAliases.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