Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement .NET MAUI Maps #7886

Merged
merged 154 commits into from
Aug 26, 2022
Merged

Implement .NET MAUI Maps #7886

merged 154 commits into from
Aug 26, 2022

Conversation

rmarinho
Copy link
Member

@rmarinho rmarinho commented Jun 9, 2022

Description of Change

Adding handlers for maps

Removed API:

  • Position - Replaced by Microsoft.Maui.Devices.Sensors.Location
  • Geocoder - Replaced by Microsoft.Maui.Devices.Sensors.Geocoding
  • GeographyUtils
  • Remove MoveToLastRegionOnLayoutChange on `Map
  • On Map remove EditorBrowsable APIs
[EditorBrowsable(EditorBrowsableState.Never)]
public MapSpan LastMoveToRegion { get; private set; }

[EditorBrowsable(EditorBrowsableState.Never)]
public void SetVisibleRegion(MapSpan value) 

[EditorBrowsable(EditorBrowsableState.Never)]
public void SendMapClicked(Position position) 

Changed API:

  • Change Microsoft.Maui.Controls.Maps.Position on Pin to Microsoft.Maui.Devices.Sensors.Location
  • Change Microsoft.Maui.Controls.Maps.Position on MapClickedEventArgs to Microsoft.Maui.Devices.Sensors.Location
  • Change Microsoft.Maui.Controls.Maps.Position Center on MapSpan to Microsoft.Maui.Devices.Sensors.Location
  • Change Microsoft.Maui.Controls.Maps.Position Geopath on Polyline to Microsoft.Maui.Devices.Sensors.Location
  • Change Microsoft.Maui.Controls.Maps.Position Geopath on Polygon to Microsoft.Maui.Devices.Sensors.Location
  • Change Map property TrafficEnabled to HasTrafficEnabled
  • Change Pin property Position to Location

New API:

  • Interfaces
public interface IMap : IView
{
	MapSpan? VisibleRegion { get; set;  }
	MapType MapType { get; }
	bool IsShowingUser { get; }
	bool HasScrollEnabled { get; }
	bool HasZoomEnabled { get; }
	bool HasTrafficEnabled { get; }
	IList<IMapPin> Pins { get; }
	IList<IMapElement> Elements { get; }	
	void Clicked(Location position);
	void MoveToRegion(MapSpan region);
	bool MoveToLastRegionOnLayoutChange { get; }
}

public interface IMapPin : IElement
{
	string Address { get; }
	string Label { get; }
	Location Position { get; }
	object? MarkerId { get; set; }
	bool SendMarkerClick();
	bool SendInfoWindowClick();
}

public interface IMapElement : IElement, IStroke
{
	object? MapElementId { get; set; }
}

public interface IGeoPathMapElement : IMapElement
{
	IList<Location> Geopath { get; }
}

public interface IFilledMapElement : IMapElement
{
	Paint? Fill { get; }
}

public interface ICircleMapElement : IMapElement, IFilledMapElement
{
	Location Center { get; }
	Distance Radius { get; }
}

public interface IMapHandler : IViewHandler
{
	new IMap VirtualView { get; }
	new PlatformView PlatformView { get; }
#if MONOANDROID
	GoogleMap? Map { get; set; }
#endif

	void UpdateMapElement(IMapElement element);
}

public interface IMapElementHandler : IElementHandler
{
	new IMapElement VirtualView { get; }
	new PlatformView PlatformView { get; }
}

public interface IMapPinHandler : IElementHandler
{
	new IMapPin VirtualView { get; }
	new PlatformView PlatformView { get; }
}

  • Handlers
public partial class MapHandler : IMapHandler
{
	public static IPropertyMapper<IMap, IMapHandler> Mapper = new PropertyMapper<IMap, IMapHandler>(ViewHandler.ViewMapper)
	{
		[nameof(IMap.MapType)] = MapMapType,
		[nameof(IMap.IsShowingUser)] = MapIsShowingUser,
		[nameof(IMap.HasScrollEnabled)] = MapHasScrollEnabled,
		[nameof(IMap.HasTrafficEnabled)] = MapHasTrafficEnabled,
		[nameof(IMap.HasZoomEnabled)] = MapHasZoomEnabled,
		[nameof(IMap.Pins)] = MapPins,
		[nameof(IMap.Elements)] = MapElements,
	};

	public static CommandMapper<IMap, IMapHandler> CommandMapper = new(ViewCommandMapper)
	{
		[nameof(IMap.MoveToRegion)] = MapMoveToRegion,
	};

	IMap IMapHandler.VirtualView => VirtualView;
	PlatformView IMapHandler.PlatformView => PlatformView;
}

public partial class MapHandler : ViewHandler<IMap, MKMapView>

public partial class MapHandler : ViewHandler<IMap, MapView>

public partial class MapElementHandler : IMapElementHandler
{
	public static IPropertyMapper<IMapElement, IMapElementHandler> Mapper = new PropertyMapper<IMapElement, IMapElementHandler>(ElementMapper)
	{
		[nameof(IMapElement.Stroke)] = MapStroke,
		[nameof(IMapElement.StrokeThickness)] = MapStrokeThickness,
		[nameof(IFilledMapElement.Fill)] = MapFill,
#if MONOANDROID
		[nameof(IGeoPathMapElement.Geopath)] = MapGeopath,
		[nameof(ICircleMapElement.Radius)] = MapRadius,
		[nameof(ICircleMapElement.Center)] = MapCenter,
#endif
	};

	IMapElement IMapElementHandler.VirtualView => VirtualView;
	PlatformView IMapElementHandler.PlatformView => PlatformView;
}

public partial class MapElementHandler : ElementHandler<IMapElement, MKOverlayRenderer>

public partial class MapElementHandler : ElementHandler<IMapElement, Java.Lang.Object>

public partial class MapPinHandler : IMapPinHandler
{
	public static IPropertyMapper<IMapPin, IMapPinHandler> Mapper = new PropertyMapper<IMapPin, IMapPinHandler>(ElementMapper)
	{
		[nameof(IMapPin.Position)] = MapPosition,
		[nameof(IMapPin.Label)] = MapLabel,
		[nameof(IMapPin.Address)] = MapAddress,
	};

	IMapPin IMapPinHandler.VirtualView => VirtualView;

	PlatformView IMapPinHandler.PlatformView => PlatformView;
}

public partial class MapPinHandler : ElementHandler<IMapPin, MarkerOptions>

public partial class MapPinHandler : ElementHandler<IMapPin, IMKAnnotation>

Issues Fixed

Fixes #3933

@rmarinho rmarinho added this to the .NET 7 milestone Jun 9, 2022
@Eilon Eilon added area-controls-map Map / Maps legacy-area-controls Label, Button, CheckBox, Slider, Stepper, Switch, Picker, Entry, Editor labels Jun 9, 2022
@davidbuckleyni
Copy link

Is this for the new apple maps just announced or just the old maps

@jfversluis
Copy link
Member

Is this for the new apple maps just announced or just the old maps

This is porting over Xamarin.Forms Maps to .NET MAUI. Nothing new needs to be done for the new Apple Maps stuff.

@jfversluis jfversluis changed the title Maps Implement .NET MAUI Maps Jun 14, 2022
# Conflicts:
#	src/Core/src/Handlers/ScrollView/ScrollViewHandler.iOS.cs
#	src/Core/src/Layouts/GridLayoutManager.cs
#	src/Core/src/Platform/iOS/SearchBarExtensions.cs
#	src/Templates/src/templates/maui-blazor/MauiApp.1.csproj
@jsuarezruiz jsuarezruiz self-requested a review August 25, 2022 08:18
@jsuarezruiz
Copy link
Contributor

jsuarezruiz commented Aug 25, 2022

I have updated the gallery with multiple examples to test with ItemsSource, polygons, etc.

Test results.

✔️ - Works!
🕐 - Not yet verified.
❌ - Not working.

Maps Android iOS Catalyst Windows
HasScrollEnabled ✔️ ✔️ ✔️ 🕐
HasZoomEnabled ✔️ ✔️ ✔️ 🕐
IsShowingUser ✔️ ✔️ 🕐
ItemsSource ✔️ ✔️ ✔️ 🕐
ItemTemplate ✔️ ✔️ ✔️ 🕐
MapType ✔️ ✔️ ✔️ 🕐
TrafficEnabled ✔️ ✔️ ✔️ 🕐
MapElements (Polygon) ✔️ ✔️ 🕐
MapElements (Circle) ✔️ ✔️ 🕐
MapElements (Polyline) ✔️ ✔️ 🕐
VisibleRegion ✔️ ✔️ ✔️ 🕐
MoveToRegion ✔️ ✔️ 🕐

Feedback.

Android
Can use the polygon gallery to verify that they are not being rendered, nor is the MoveToRegion method working as expected.
image

iOS
All the properties are working as expe
ios-maps
cted.

src/Compatibility/Maps/src/iOS/FormsMaps.cs Outdated Show resolved Hide resolved
@@ -212,16 +214,16 @@ protected override void OnLayout(bool changed, int l, int t, int r, int b)
{
if (NativeMap != null)
{
MoveToRegion(Element.LastMoveToRegion, false);
// MoveToRegion(Element.LastMoveToRegion, false);
Copy link
Contributor

Choose a reason for hiding this comment

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

LastMoveToRegion have been removed?

if (googleMap == null)
return;

googleMap.MapType = map.MapType switch
Copy link
Contributor

Choose a reason for hiding this comment

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

It's not essential, but could we move this to extension methods like in other Handlers? This way, someone extending the Handler could easily access this logic.

src/Core/maps/src/Handlers/Map/MapHandler.Android.cs Outdated Show resolved Hide resolved
src/Core/maps/src/Handlers/MapPin/MapPinHandler.Android.cs Outdated Show resolved Hide resolved
@rmarinho rmarinho merged commit 4f3075b into main Aug 26, 2022
@rmarinho rmarinho deleted the maps branch August 26, 2022 11:18
Copy link

@Jun1119jun Jun1119jun left a comment

Choose a reason for hiding this comment

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

@sky41906

@github-actions github-actions bot locked and limited conversation to collaborators Dec 20, 2023
@Eilon Eilon removed the legacy-area-controls Label, Button, CheckBox, Slider, Stepper, Switch, Picker, Entry, Editor label May 10, 2024
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.

Move Maps to handler architecture
10 participants