Skip to content

Add Circle, Polygon, and Polyline click events for Map control#29101

Merged
jfversluis merged 2 commits intodotnet:net11.0from
kubaflo:polygon-and-circle-clicked-event
Feb 26, 2026
Merged

Add Circle, Polygon, and Polyline click events for Map control#29101
jfversluis merged 2 commits intodotnet:net11.0from
kubaflo:polygon-and-circle-clicked-event

Conversation

@kubaflo
Copy link
Copy Markdown
Contributor

@kubaflo kubaflo commented Apr 21, 2025

Note

Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!

Description of Change

This PR adds support for detecting click interactions on Circle, Polygon, and Polyline elements within the .NET MAUI Map control.

Enhancements over original proposal:

  • Added PolylineClicked event (in addition to Circle and Polygon)
  • Rebased onto net11.0 branch
  • Added proper PublicAPI.Unshipped.txt entries
  • Added sample gallery page (MapElementClickGallery)
  • Added unit tests for click events

Platforms Affected

  • Android: Uses IOnCircleClickListener, IOnPolygonClickListener, IOnPolylineClickListener
  • iOS/MacCatalyst: Uses hit testing in tap gesture recognizer

Public API Changes

// Circle
circle.CircleClicked += (s, e) =>
{
    DisplayAlert("Circle Clicked", "You clicked the circle!", "OK");
};

// Polygon
polygon.PolygonClicked += (s, e) =>
{
    DisplayAlert("Polygon Clicked", "You clicked the polygon!", "OK");
};

// Polyline (NEW)
polyline.PolylineClicked += (s, e) =>
{
    DisplayAlert("Polyline Clicked", "You clicked the polyline!", "OK");
};

Issues Fixed

Fixes #28825


Original Proposal

This PR proposes support for detecting click interactions on Polygon, and Circle elements within the .NET MAUI Map control.

Demo

Android iOS
Screen.Recording.2025-04-21.at.14.52.42.mov
Screen.Recording.2025-04-21.at.14.51.33.mov

Co-authored-by: Jakub Florkowski kubaflo123@gmail.com

@kubaflo kubaflo self-assigned this Apr 21, 2025
@dotnet-policy-service dotnet-policy-service bot added the community ✨ Community Contribution label Apr 21, 2025
@dotnet-policy-service
Copy link
Copy Markdown
Contributor

Hey there @@kubaflo! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

@jfversluis jfversluis added this to the .NET 11 Planning milestone Oct 21, 2025
@jfversluis jfversluis changed the base branch from main to net11.0 January 30, 2026 12:31
@jfversluis jfversluis force-pushed the polygon-and-circle-clicked-event branch from 17f6f65 to b9ce465 Compare January 30, 2026 12:32
@jfversluis jfversluis changed the title [.Net10][Proposal] Circle & Polygon clicked event Add Circle, Polygon, and Polyline click events for Map control Jan 30, 2026
@jfversluis jfversluis marked this pull request as ready for review January 30, 2026 12:35
Copilot AI review requested due to automatic review settings January 30, 2026 12:35
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds click/tap event support for Circle, Polygon, and Polyline map elements in the .NET MAUI Map control, addressing issue #28825. The implementation is cross-platform (Android, iOS/MacCatalyst) with proper unit tests and a sample gallery page demonstrating the functionality.

Changes:

  • Added IMapElement.Clicked() interface method to enable click event handling across all map elements
  • Implemented platform-specific click detection using native listeners on Android and hit testing on iOS/MacCatalyst
  • Added three new public events: CircleClicked, PolygonClicked, and PolylineClicked with corresponding EventHandler signatures

Reviewed changes

Copilot reviewed 25 out of 25 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/Core/maps/src/Core/IMapElement.cs Added Clicked() method to interface for click event propagation
src/Core/maps/src/Handlers/Map/MapHandler.Android.cs Implemented Android click listeners and registered them with GoogleMap
src/Core/maps/src/Platform/iOS/MauiMKMapView.cs Added iOS/MacCatalyst hit testing logic for circles, polygons, and polylines
src/Controls/Maps/src/Circle.cs Added CircleClicked event and implementation of IMapElement.Clicked()
src/Controls/Maps/src/Polygon.cs Added PolygonClicked event and implementation of IMapElement.Clicked()
src/Controls/Maps/src/Polyline.cs Added PolylineClicked event and implementation of IMapElement.Clicked()
src/Controls/Maps/src/HandlerImpl/MapElement.Impl.cs Added stub implementation throwing NotImplementedException
src/Controls/tests/Core.UnitTests/MapTests.cs Added 6 unit tests verifying click events fire correctly and sender is correct
src/Controls/samples/Controls.Sample/Pages/Controls/MapsGalleries/MapElementClickGallery.xaml Added sample page XAML with map and status label
src/Controls/samples/Controls.Sample/Pages/Controls/MapsGalleries/MapElementClickGallery.xaml.cs Added sample page implementation demonstrating all three click events
src/Controls/samples/Controls.Sample/Pages/Controls/MapsGalleries/MapsGallery.cs Added navigation button to new gallery page
PublicAPI.Unshipped.txt files (multiple) Added API entries for IMapElement.Clicked() and event properties

@rmarinho
Copy link
Copy Markdown
Member

/rebase

- Add CircleClicked, PolygonClicked, PolylineClicked events
- Implement IMapElement.Clicked() for all map elements
- Add Android click listeners (IOnCircleClickListener, IOnPolygonClickListener, IOnPolylineClickListener)
- Add iOS hit testing for circle, polygon, and polyline clicks
- Add MapElementClickGallery sample page
- Add unit tests for click events
- Update PublicAPI.Unshipped.txt files

Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com>
@jfversluis jfversluis force-pushed the polygon-and-circle-clicked-event branch from 66f7eb3 to 7e2dbaf Compare February 25, 2026 13:22
jfversluis
jfversluis previously approved these changes Feb 25, 2026
…y priority

- Use Math.Max(renderer.LineWidth, 44) for polyline hit testing instead of
  conditioning on StrokeColor. This ensures a minimum 44pt tap target while
  respecting larger line widths.
- Document the overlay hit-test priority order (Circle > Polygon > Polyline)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@jfversluis jfversluis force-pushed the polygon-and-circle-clicked-event branch from 7e2dbaf to 7e3e0fd Compare February 25, 2026 14:12
@jfversluis jfversluis merged commit dcd44b3 into dotnet:net11.0 Feb 26, 2026
21 of 27 checks passed
PureWeen added a commit that referenced this pull request Feb 27, 2026
…4260)

This PR merges commits from `net11.0` into `release/11.0.1xx-preview2`.

Commits include:
- Add Circle, Polygon, and Polyline click events for Map control
(#29101)
- [automated] Merge branch 'main' => 'net11.0' (#34203)
- Fix empty string binding to nullable value types (#33536)
- Add MapElement.IsVisible and MapElement.ZIndex properties (#33993)
- Add MauiXamlHotReload property for IDE communication (#34028)

## Instructions for merging

Complete this PR by creating a **merge commit**, *not* a squash or
rebase commit.
@github-actions github-actions bot locked and limited conversation to collaborators Mar 28, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MAP-Control Polyline,Polygon,Circle OnClicked Event

5 participants