Add MapStyle property for custom JSON map styling (Android)#33991
Add MapStyle property for custom JSON map styling (Android)#33991jfversluis merged 5 commits intonet11.0from
Conversation
There was a problem hiding this comment.
Pull request overview
Adds an Android-only MapStyle API to the MAUI Maps control surface so developers can apply Google Maps JSON styling, wiring it through the handler/property mapper, updating PublicAPI files, and providing basic unit coverage + a sample gallery page.
Changes:
- Introduces
IMap.MapStyleandMap.MapStyle(BindableProperty) and maps it throughMapHandler. - Android implementation applies the JSON string using
GoogleMap.SetMapStyle(new MapStyleOptions(json)); other platforms add stubs/no-ops. - Updates PublicAPI.Unshipped files, adds unit tests, and adds a sample “Map Style” gallery page.
Reviewed changes
Copilot reviewed 27 out of 27 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Core/maps/src/PublicAPI/netstandard/PublicAPI.Unshipped.txt | Declares new IMap.MapStyle and handler mapper API for netstandard. |
| src/Core/maps/src/PublicAPI/net/PublicAPI.Unshipped.txt | Declares new IMap.MapStyle and handler mapper API for net. |
| src/Core/maps/src/PublicAPI/net-windows/PublicAPI.Unshipped.txt | Declares new IMap.MapStyle and handler mapper API for Windows TFM. |
| src/Core/maps/src/PublicAPI/net-tizen/PublicAPI.Unshipped.txt | Declares new IMap.MapStyle and handler mapper API for Tizen TFM. |
| src/Core/maps/src/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt | Declares new IMap.MapStyle and handler mapper API for MacCatalyst TFM. |
| src/Core/maps/src/PublicAPI/net-ios/PublicAPI.Unshipped.txt | Declares new IMap.MapStyle and handler mapper API for iOS TFM. |
| src/Core/maps/src/PublicAPI/net-android/PublicAPI.Unshipped.txt | Declares new IMap.MapStyle, handler mapper API, and Android UpdateMapStyle extension API. |
| src/Core/maps/src/Platform/Android/MapExtensions.cs | Adds UpdateMapStyle extension to apply/clear Google Maps JSON styling. |
| src/Core/maps/src/Handlers/Map/MapHandler.iOS.cs | Adds a no-op MapMapStyle mapping method for iOS/MacCatalyst. |
| src/Core/maps/src/Handlers/Map/MapHandler.cs | Adds MapStyle entry to the handler property mapper. |
| src/Core/maps/src/Handlers/Map/MapHandler.Windows.cs | Adds MapMapStyle stub for Windows handler. |
| src/Core/maps/src/Handlers/Map/MapHandler.Tizen.cs | Adds MapMapStyle stub for Tizen handler. |
| src/Core/maps/src/Handlers/Map/MapHandler.Standard.cs | Adds MapMapStyle stub for standard/netstandard handler. |
| src/Core/maps/src/Handlers/Map/MapHandler.Android.cs | Wires MapMapStyle and applies initial style in OnMapReady. |
| src/Core/maps/src/Core/IMap.cs | Adds MapStyle to the core map interface with platform annotations. |
| src/Controls/tests/Core.UnitTests/MapTests.cs | Adds unit tests for default/set/clear behavior of Map.MapStyle. |
| src/Controls/samples/Controls.Sample/Pages/Controls/MapsGalleries/MapsGallery.cs | Adds navigation entry to the new Map Style sample page. |
| src/Controls/samples/Controls.Sample/Pages/Controls/MapsGalleries/MapStyleGallery.xaml.cs | Adds code-behind to switch between default/dark/retro/night JSON styles. |
| src/Controls/samples/Controls.Sample/Pages/Controls/MapsGalleries/MapStyleGallery.xaml | Adds UI for the Map Style sample page. |
| src/Controls/Maps/src/PublicAPI/netstandard/PublicAPI.Unshipped.txt | Declares new Map.MapStyle APIs for netstandard. |
| src/Controls/Maps/src/PublicAPI/net/PublicAPI.Unshipped.txt | Declares new Map.MapStyle APIs for net. |
| src/Controls/Maps/src/PublicAPI/net-windows/PublicAPI.Unshipped.txt | Declares new Map.MapStyle APIs for Windows TFM. |
| src/Controls/Maps/src/PublicAPI/net-tizen/PublicAPI.Unshipped.txt | Declares new Map.MapStyle APIs for Tizen TFM. |
| src/Controls/Maps/src/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt | Declares new Map.MapStyle APIs for MacCatalyst TFM. |
| src/Controls/Maps/src/PublicAPI/net-ios/PublicAPI.Unshipped.txt | Declares new Map.MapStyle APIs for iOS TFM. |
| src/Controls/Maps/src/PublicAPI/net-android/PublicAPI.Unshipped.txt | Declares new Map.MapStyle APIs for Android TFM. |
| src/Controls/Maps/src/Map.cs | Adds MapStyleProperty and the MapStyle bindable property with platform annotations. |
d47b6aa to
46e92ec
Compare
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
Independent Code ReviewSummary: Adds a ✅ What Looks Good
🔴 Issues1. Error handling uses if (!result)
{
System.Diagnostics.Debug.WriteLine("Failed to apply map style...");
}
2. using var styleOptions = new MapStyleOptions(map.MapStyle);3. Non-Android platform handlers throw 🟡 Suggestions
|
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 33991Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 33991" |
Review ResponseThanks for the thorough review @kubaflo! All three red issues have been addressed in the latest commit: Issues - All Fixed1. Debug.WriteLine to ILogger Fixed. 2. MapStyleOptions disposal Fixed. 3. NotImplementedException to no-op Fixed. Suggestions - Responses
All changes verified: Build passes, 35 map tests pass. |
🔍 Round 2 Review — PR #33991 (MapStyle)Updated with author response analysis ✅ Fixed Since Round 1
|
|
/azp run maui-pr |
|
Azure Pipelines successfully started running 1 pipeline(s). |
📋 Round 3 — PR #33991 (MapStyle) — Final RecommendationNo outstanding issues. This was the most polished PR throughout the review process. Recommendation: Merge when CI passes. This is the simplest and cleanest of the 8 PRs — good candidate to merge first (least conflict risk). 🗺️ Suggested Merge Order for All 8 PRsTo minimize rebase conflicts (all 8 PRs modify
|
07aa9d0 to
28fe50e
Compare
|
🚨 API change(s) detected @davidortinau FYI |
- Add MapStyle string property to IMap interface and Map control - Android: Full Google Maps JSON styling via MapStyleOptions - iOS/MacCatalyst/Windows: No-op with [UnsupportedOSPlatform] attributes (MapKit and other native map controls don't support custom JSON styling) - Developers get compile-time CA1416 warning when using on unsupported platforms - Add MapStyleGallery sample page with Dark, Retro, Night presets - Add 3 unit tests for MapStyle property - Update all PublicAPI.Unshipped.txt files Closes #10706
- Guard UnsupportedOSPlatform attributes with #if !NETSTANDARD for netstandard TFMs - Check SetMapStyle return value and log warning on failure
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot CLI would wrongfully come up with old pipeline names (e.g., MAUI-UITests-public) found in historical PR comments. This documents the current correct names so agents use them: - maui-pr (overall CI) - maui-pr-devicetests (device tests) - maui-pr-uitests (UI tests) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
28fe50e to
17c39b2
Compare
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
Adds a
MapStyleproperty to theMapcontrol that accepts a Google Maps JSON style string for customizing the visual appearance of the map on Android.Fixes #10706
What this does
IMap.MapStyle(string?) property to the core map interfaceMap.MapStylePropertyBindableProperty on the Controls layerGoogleMap.SetMapStyle(new MapStyleOptions(json))[UnsupportedOSPlatform]— Apple MapKit does not support custom JSON map styling (only dark/light mode), so this property is Android-onlyWhy Android-only?
Apple MapKit has no equivalent to Google Maps'
SetMapStyle(JSON)API. Rather than providing a misleading partial implementation (e.g., only toggling dark/light mode based on JSON analysis), the property is marked with[UnsupportedOSPlatform("ios")],[UnsupportedOSPlatform("maccatalyst")], and[UnsupportedOSPlatform("windows")]. This gives developers a compile-time CA1416 warning when targeting unsupported platforms.Changes
IMap.cs— AddedMapStyleproperty with[UnsupportedOSPlatform]attributesMap.cs— AddedMapStylePropertyBindableProperty with[UnsupportedOSPlatform]attributesMapHandler.cs— Added PropertyMapper entryMapHandler.Android.cs— CallsUpdateMapStyleon the nativeGoogleMapMapHandler.iOS.cs— No-op handler with commentMapExtensions.cs(Android) —UpdateMapStyle()extension methodMapStyleGallerysample page with Dark, Retro, and Night presetsVerified
Part of the Maps Improvements Epic: #33787