Skip to content

Conversation

@tomcurran
Copy link

@tomcurran tomcurran commented Oct 7, 2025

Clears all the annotations prior to adding new ones. We found it was needed as of .NET 9. Related code. Mirrors the behaviour in MauiMKMapView.

Summary by CodeRabbit

  • Bug Fixes
    • On iOS, the map now clears existing annotations before rendering updates, preventing duplicate or outdated pins after data refreshes. This improves visual consistency and reliability of map markers during navigation, filtering, or live updates. No changes to public APIs or user interactions; pin updates are simply more accurate and consistent.

@coderabbitai
Copy link

coderabbitai bot commented Oct 7, 2025

Walkthrough

Adds a pre-condition in AddPins to clear existing annotations on iOS by calling RemoveAnnotations(PlatformView.Annotations) before iterating and adding new pins.

Changes

Cohort / File(s) Summary
iOS Map Pin Refresh Logic
MauiMaps/Platforms/iOS/CustomMapHandler.cs
Inserted an early branch in AddPins to remove existing annotations via RemoveAnnotations(PlatformView.Annotations) before processing mapPins; no public API changes.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Caller
  participant CustomMapHandler
  participant PlatformView as MKMapView (iOS)

  Caller->>CustomMapHandler: AddPins(mapPins)
  alt Existing annotations present
    CustomMapHandler->>PlatformView: RemoveAnnotations(PlatformView.Annotations)
    note right of PlatformView: Clears current markers
  end
  loop For each pin in mapPins
    CustomMapHandler->>PlatformView: AddAnnotation(pin)
  end
  CustomMapHandler-->>Caller: Return
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

I sweep the map, a tidy bun,
Old pins hop off—now zero, none.
Fresh carrots—erm, markers—line in rows,
A clean slate gleams where river flows.
With tidy paws and careful cheer,
Tap-tap, new pins—the path is clear! 🥕🗺️

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title Check ✅ Passed The title clearly describes the primary change by indicating that it fixes the issue of pins remaining on the map when navigating between multiple pages, which aligns directly with the pull request’s objective of clearing annotations before adding new ones.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing touches
  • 🔄 Docstrings generation in progress.
🧪 Generate unit tests (beta)

✅ Copyable Unit Test edits generated.

  • Create PR with unit tests
  • Commit unit tests in branch feature/map-pins
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 519f54e and 66a2630.

📒 Files selected for processing (1)
  • MauiMaps/Platforms/iOS/CustomMapHandler.cs (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Codacy Static Code Analysis

Comment on lines +131 to +134
if (PlatformView.Annotations.Length > 0)
{
PlatformView.RemoveAnnotations(PlatformView.Annotations);
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Filter annotation removal to preserve system annotations.

Removing all annotations indiscriminately may unintentionally clear system-managed annotations such as the user location marker. Additionally, the async image loading for CustomPin (lines 144-157) can introduce a race condition: if AddPins is called again before image callbacks complete, those pending annotations might be added after the new clear operation, leaving stale pins on the map.

Consider filtering the removal to only target annotations added by this handler:

-if (PlatformView.Annotations.Length > 0)
-{
-    PlatformView.RemoveAnnotations(PlatformView.Annotations);
-}
+var annotationsToRemove = PlatformView.Annotations
+    .Where(a => a is CustomAnnotation || a is MKPointAnnotation)
+    .ToArray();
+if (annotationsToRemove.Length > 0)
+{
+    PlatformView.RemoveAnnotations(annotationsToRemove);
+}

This preserves system annotations while still addressing the .NET 9 issue where pins persist across page navigations.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (PlatformView.Annotations.Length > 0)
{
PlatformView.RemoveAnnotations(PlatformView.Annotations);
}
var annotationsToRemove = PlatformView.Annotations
.Where(a => a is CustomAnnotation || a is MKPointAnnotation)
.ToArray();
if (annotationsToRemove.Length > 0)
{
PlatformView.RemoveAnnotations(annotationsToRemove);
}

return;
}

if (PlatformView.Annotations.Length > 0)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tomcurran could you please explain why we need to clear all annotations? I see we removed annotations on line 116.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found this to be needed to get the correct behaviour. See the description for information.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please provide example to reproduce the issue?

@coderabbitai
Copy link

coderabbitai bot commented Oct 13, 2025

Note

Docstrings generation - SUCCESS
Generated docstrings for this pull request at #451

coderabbitai bot added a commit that referenced this pull request Oct 13, 2025
Docstrings generation was requested by @VladislavAntonyuk.

* #450 (comment)

The following files were modified:

* `MauiMaps/Platforms/iOS/CustomMapHandler.cs`
@coderabbitai
Copy link

coderabbitai bot commented Oct 13, 2025

Note

Unit test generation is an Early Access feature. Expect some limitations and changes as we gather feedback and continue to improve it.


Generating unit tests... This may take up to 20 minutes.

1 similar comment
@coderabbitai
Copy link

coderabbitai bot commented Oct 13, 2025

Note

Unit test generation is an Early Access feature. Expect some limitations and changes as we gather feedback and continue to improve it.


Generating unit tests... This may take up to 20 minutes.

@coderabbitai
Copy link

coderabbitai bot commented Oct 13, 2025

Caution

The CodeRabbit agent failed during execution: Clone operation failed

1 similar comment
@coderabbitai
Copy link

coderabbitai bot commented Oct 13, 2025

Caution

The CodeRabbit agent failed during execution: Clone operation failed

@coderabbitai
Copy link

coderabbitai bot commented Oct 13, 2025

Note

Unit test generation is an Early Access feature. Expect some limitations and changes as we gather feedback and continue to improve it.


Generating unit tests... This may take up to 20 minutes.

@coderabbitai
Copy link

coderabbitai bot commented Oct 13, 2025

Caution

The CodeRabbit agent failed during execution: Clone operation failed

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