From 703836e3d99d9545b0f148894410dae0d1ddb889 Mon Sep 17 00:00:00 2001 From: Tuyen Vu Date: Thu, 4 Jul 2024 07:45:32 +0700 Subject: [PATCH 1/5] - add GestureSettings --- nuget.config | 2 +- src/libs/Mapbox.Maui/IMapboxView.cs | 1 + src/libs/Mapbox.Maui/Mapbox.Maui.csproj | 4 +- src/libs/Mapbox.Maui/MapboxView.cs | 11 +++ src/libs/Mapbox.Maui/MapboxViewHandler.cs | 1 + .../Mapbox.Maui/Models/GestureSettings.cs | 99 +++++++++++++++++++ .../Platforms/Android/AdditionalExtensions.cs | 10 ++ .../Platforms/Android/MapboxViewHandler.cs | 30 +++++- .../Platforms/iOS/AdditionalExtensions.cs | 30 ++++-- .../Platforms/iOS/GeometryExtensions.cs | 8 -- .../iOS/MapboxViewHandler.Controller.cs | 2 +- .../Platforms/iOS/MapboxViewHandler.cs | 26 +++++ src/qs/MapboxMauiQs/MapboxMauiQs.csproj | 4 +- 13 files changed, 206 insertions(+), 22 deletions(-) create mode 100644 src/libs/Mapbox.Maui/Models/GestureSettings.cs diff --git a/nuget.config b/nuget.config index ba7edaf..ad9100d 100644 --- a/nuget.config +++ b/nuget.config @@ -1,6 +1,6 @@  - + \ No newline at end of file diff --git a/src/libs/Mapbox.Maui/IMapboxView.cs b/src/libs/Mapbox.Maui/IMapboxView.cs index 3cf595d..c4ec801 100644 --- a/src/libs/Mapbox.Maui/IMapboxView.cs +++ b/src/libs/Mapbox.Maui/IMapboxView.cs @@ -8,6 +8,7 @@ public partial interface IMapboxView : IView { CameraOptions CameraOptions { get; set; } + GestureSettings GestureSettings { get; set; } MapboxStyle MapboxStyle { get; set; } IPosition MapCenter { get; set; } float? MapZoom { get; set; } diff --git a/src/libs/Mapbox.Maui/Mapbox.Maui.csproj b/src/libs/Mapbox.Maui/Mapbox.Maui.csproj index 11bf076..e1451d9 100644 --- a/src/libs/Mapbox.Maui/Mapbox.Maui.csproj +++ b/src/libs/Mapbox.Maui/Mapbox.Maui.csproj @@ -80,8 +80,8 @@ - - + + diff --git a/src/libs/Mapbox.Maui/MapboxView.cs b/src/libs/Mapbox.Maui/MapboxView.cs index 1b3901b..07bf827 100644 --- a/src/libs/Mapbox.Maui/MapboxView.cs +++ b/src/libs/Mapbox.Maui/MapboxView.cs @@ -5,6 +5,17 @@ public partial class MapboxView : View, IMapboxView { + public static readonly BindableProperty GestureSettingsProperty = BindableProperty.Create( + nameof(GestureSettings), + typeof(GestureSettings), + typeof(MapboxView) + ); + public GestureSettings GestureSettings + { + get => (GestureSettings)GetValue(ViewAnnotationsProperty); + set => SetValue(ViewAnnotationsProperty, value); + } + public static readonly BindableProperty ViewAnnotationsProperty = BindableProperty.Create( nameof(ViewAnnotations), typeof(IEnumerable), diff --git a/src/libs/Mapbox.Maui/MapboxViewHandler.cs b/src/libs/Mapbox.Maui/MapboxViewHandler.cs index 141b3fe..4b954d1 100644 --- a/src/libs/Mapbox.Maui/MapboxViewHandler.cs +++ b/src/libs/Mapbox.Maui/MapboxViewHandler.cs @@ -18,6 +18,7 @@ public static IPropertyMapper PropertyMapper = new PropertyMapper(ViewHandler.ViewMapper) { [nameof(MapboxView.CameraOptions)] = HandleCameraOptionsChanged, + [nameof(MapboxView.GestureSettings)] = HandleGestureSettingsChanged, [nameof(MapboxView.MapboxStyle)] = HandleMapboxStyleChanged, [nameof(MapboxView.ScaleBarVisibility)] = HandleScaleBarVisibilityChanged, [nameof(MapboxView.DebugOptions)] = HandleDebugOptionsChanged, diff --git a/src/libs/Mapbox.Maui/Models/GestureSettings.cs b/src/libs/Mapbox.Maui/Models/GestureSettings.cs new file mode 100644 index 0000000..4973ffa --- /dev/null +++ b/src/libs/Mapbox.Maui/Models/GestureSettings.cs @@ -0,0 +1,99 @@ +namespace MapboxMaui; + +public record struct GestureSettings +{ + public GestureSettings() + { + } + + /// + /// Whether the rotate gesture is enabled. + /// + public bool RotateEnabled { get; set; } = true; + /// + /// Whether the pinch to zoom gesture is enabled. + /// + /// iOS: PinchZoomEnabled + /// + public bool PinchToZoomEnabled { get; set; } = true; + /// + /// Whether the single-touch scroll gesture is enabled. + /// + public bool ScrollEnabled { get; set; } = true; + /// + /// Whether rotation is enabled for the pinch to zoom gesture. + /// + /// iOS: SimultaneousRotateAndPinchZoomEnabled + /// + public bool SimultaneousRotateAndPinchToZoomEnabled { get; set; } = true; + /// + /// Whether the pitch gesture is enabled. + /// + public bool PitchEnabled { get; set; } = true; + /// + /// Configures the directions in which the map is allowed to move during a scroll gesture. + /// + /// iOS: PanMode + /// + public PanMode ScrollMode { get; set; } = PanMode.Both; + /// + /// Whether double tapping the map with one touch results in a zoom-in animation. + /// + public bool DoubleTapToZoomInEnabled { get; set; } = true; + /// + /// Whether single tapping the map with two touches results in a zoom-out animation. + /// + public bool DoubleTouchToZoomOutEnabled { get; set; } = true; + /// + /// Whether the quick zoom gesture is enabled. + /// + public bool QuickZoomEnabled { get; set; } = true; + /// + /// By default, gestures rotate and zoom around the center of the gesture. Set this property to + /// rotate and zoom around a fixed point instead. + /// + public ScreenPosition? FocalPoint { get; set; } + /// + /// Android only. + /// Whether a deceleration animation following a pinch-to-zoom gesture is enabled. True by default. + /// + public bool PinchToZoomDecelerationEnabled { get; set; } = true; + /// + /// Android only. + /// Whether a deceleration animation following a rotate gesture is enabled. True by default. + /// + public bool RotateDecelerationEnabled { get; set; } = true; + /// + /// Android only. + /// Whether a deceleration animation following a scroll gesture is enabled. True by default. + /// + public bool ScrollDecelerationEnabled { get; set; } = true; + /// + /// Android only. + /// + /// Whether rotate threshold increases when pinching to zoom. true by default. + /// + public bool IncreaseRotateThresholdWhenPinchingToZoom { get; set; } = true; + /// + /// Android only. + /// Whether pinch to zoom threshold increases when rotating. true by default. + /// + public bool IncreasePinchToZoomThresholdWhenRotating { get; set; } = true; + /// + /// The amount by which the zoom level increases or decreases during a double-tap-to-zoom-in or + /// double-touch-to-zoom-out gesture. 1.0 by default. Must be positive. + /// + public float ZoomAnimationAmount { get; set; } = 1.0f; + /// + /// Whether pan is enabled for the pinch gesture. + /// + /// iOS: PanEnabled + /// + public bool PinchScrollEnabled { get; set; } = true; +} +public enum PanMode +{ + Horizontal = 0x0001, + Vertical = 0x0010, + Both = 0x0011, +} \ No newline at end of file diff --git a/src/libs/Mapbox.Maui/Platforms/Android/AdditionalExtensions.cs b/src/libs/Mapbox.Maui/Platforms/Android/AdditionalExtensions.cs index b711623..c456614 100644 --- a/src/libs/Mapbox.Maui/Platforms/Android/AdditionalExtensions.cs +++ b/src/libs/Mapbox.Maui/Platforms/Android/AdditionalExtensions.cs @@ -15,10 +15,20 @@ using AndroidX.Fragment.App; using Com.Mapbox.Maps.Plugins.Animation; using Com.Mapbox.Functions; +using Com.Mapbox.Maps.Plugins; static class AdditionalExtensions { internal static DisplayMetrics Metrics; + + public static ScrollMode ToNative(this PanMode scrollDirection) + { + return scrollDirection switch { + PanMode.Horizontal => ScrollMode.Horizontal, + PanMode.Vertical => ScrollMode.Vertical, + _ => ScrollMode.HorizontalAndVertical, + }; + } public static MapAnimationOptions ToNative(this AnimationOptions animationOptions) { diff --git a/src/libs/Mapbox.Maui/Platforms/Android/MapboxViewHandler.cs b/src/libs/Mapbox.Maui/Platforms/Android/MapboxViewHandler.cs index 048b8bc..13450db 100644 --- a/src/libs/Mapbox.Maui/Platforms/Android/MapboxViewHandler.cs +++ b/src/libs/Mapbox.Maui/Platforms/Android/MapboxViewHandler.cs @@ -7,12 +7,40 @@ using Android.Content; using Android.Graphics; using GeoJSON.Text; - +using Com.Mapbox.Maps.Plugins.Gestures; +using Com.Mapbox.Maps.Plugins.Gestures.Generated; + namespace MapboxMaui; public partial class MapboxViewHandler { MapboxFragment mapboxFragment; + private static void HandleGestureSettingsChanged(MapboxViewHandler handler, IMapboxView view) + { + var mapView = handler.GetMapView(); + if (mapView == null) return; + + var gestures = mapView.GetGestures(); + + gestures.DoubleTapToZoomInEnabled = view.GestureSettings.DoubleTapToZoomInEnabled; + gestures.DoubleTouchToZoomOutEnabled = view.GestureSettings.DoubleTouchToZoomOutEnabled; + gestures.FocalPoint = view.GestureSettings.FocalPoint?.ToScreenCoordinate(); + gestures.IncreasePinchToZoomThresholdWhenRotating = view.GestureSettings.IncreasePinchToZoomThresholdWhenRotating; + gestures.IncreaseRotateThresholdWhenPinchingToZoom = view.GestureSettings.IncreaseRotateThresholdWhenPinchingToZoom; + gestures.PinchScrollEnabled = view.GestureSettings.PinchScrollEnabled; + gestures.PinchToZoomDecelerationEnabled = view.GestureSettings.PinchToZoomDecelerationEnabled; + gestures.PinchToZoomEnabled = view.GestureSettings.PinchToZoomEnabled; + gestures.PitchEnabled = view.GestureSettings.PitchEnabled; + gestures.QuickZoomEnabled = view.GestureSettings.QuickZoomEnabled; + gestures.RotateDecelerationEnabled = view.GestureSettings.RotateDecelerationEnabled; + gestures.RotateEnabled = view.GestureSettings.RotateEnabled; + gestures.ScrollDecelerationEnabled = view.GestureSettings.ScrollDecelerationEnabled; + gestures.ScrollEnabled = view.GestureSettings.ScrollEnabled; + gestures.ScrollMode = view.GestureSettings.ScrollMode.ToNative(); + gestures.SimultaneousRotateAndPinchToZoomEnabled = view.GestureSettings.SimultaneousRotateAndPinchToZoomEnabled; + gestures.ZoomAnimationAmount = view.GestureSettings.ZoomAnimationAmount; + } + private static void HandleLightChanged(MapboxViewHandler handler, IMapboxView view) { var mapView = handler.GetMapView(); diff --git a/src/libs/Mapbox.Maui/Platforms/iOS/AdditionalExtensions.cs b/src/libs/Mapbox.Maui/Platforms/iOS/AdditionalExtensions.cs index 28ca899..020fe9c 100644 --- a/src/libs/Mapbox.Maui/Platforms/iOS/AdditionalExtensions.cs +++ b/src/libs/Mapbox.Maui/Platforms/iOS/AdditionalExtensions.cs @@ -11,10 +11,20 @@ namespace MapboxMaui; using MapboxMapsObjC; using Microsoft.Maui.Controls.Compatibility.Platform.iOS; using Microsoft.Maui.Platform; -using System.Runtime.InteropServices; +using CoreGraphics; public static partial class AdditionalExtensions { + internal static TMBPanMode ToNative(this PanMode panMode) + { + return panMode switch + { + PanMode.Horizontal => TMBPanMode.Horizontal, + PanMode.Vertical => TMBPanMode.Vertical, + _ => TMBPanMode.HorizontalAndVertical, + }; + } + internal static NSDictionary ToNative(this IDictionary dictionary) { var list = new NSMutableDictionary(); @@ -278,12 +288,8 @@ public static TMBCameraOptions ToNative(this CameraOptions cameraOptions) (float)cameraOptions.Padding.Value.Bottom, (float)cameraOptions.Padding.Value.Right) : UIKit.UIEdgeInsets.Zero; - var anchor = cameraOptions.Anchor is not null - ? new CoreGraphics.CGPoint( - cameraOptions.Anchor.Value.X, - cameraOptions.Anchor.Value.Y - ) - : CoreGraphics.CGPoint.Empty; + var anchor = cameraOptions.Anchor?.ToNative() + ?? CGPoint.Empty; var zoom = cameraOptions.Zoom.HasValue ? cameraOptions.Zoom.Value : 14f; @@ -303,5 +309,15 @@ public static TMBCameraOptions ToNative(this CameraOptions cameraOptions) pitch ); } + + internal static CGPoint ToNative(this ScreenPosition screenPosition) + { + return new CGPoint(screenPosition.X, screenPosition.Y); + } + + internal static NSValue ToNSValue(this ScreenPosition screenPosition) + { + return NSValue.FromCGPoint(screenPosition.ToNative()); + } } diff --git a/src/libs/Mapbox.Maui/Platforms/iOS/GeometryExtensions.cs b/src/libs/Mapbox.Maui/Platforms/iOS/GeometryExtensions.cs index 7d64a4a..69be0c8 100644 --- a/src/libs/Mapbox.Maui/Platforms/iOS/GeometryExtensions.cs +++ b/src/libs/Mapbox.Maui/Platforms/iOS/GeometryExtensions.cs @@ -93,14 +93,6 @@ internal static CGPoint ToCGPoint(this IPosition xobj) ); } - internal static CGPoint ToCGPoint(this ScreenPosition xobj) - { - return new CGPoint( - xobj.X, - xobj.Y - ); - } - public static IPosition ToMapPosition(this CLLocationCoordinate2D point) { return new MapPosition( diff --git a/src/libs/Mapbox.Maui/Platforms/iOS/MapboxViewHandler.Controller.cs b/src/libs/Mapbox.Maui/Platforms/iOS/MapboxViewHandler.Controller.cs index 1a73146..872c247 100644 --- a/src/libs/Mapbox.Maui/Platforms/iOS/MapboxViewHandler.Controller.cs +++ b/src/libs/Mapbox.Maui/Platforms/iOS/MapboxViewHandler.Controller.cs @@ -26,7 +26,7 @@ public IPosition GetMapPosition(ScreenPosition position) if (mapView == null) return null; var coords = mapView.MapboxMap().CoordinateFor( - position.ToCGPoint() + position.ToNative() ); return coords.ToMapPosition(); diff --git a/src/libs/Mapbox.Maui/Platforms/iOS/MapboxViewHandler.cs b/src/libs/Mapbox.Maui/Platforms/iOS/MapboxViewHandler.cs index a6a039b..a693522 100644 --- a/src/libs/Mapbox.Maui/Platforms/iOS/MapboxViewHandler.cs +++ b/src/libs/Mapbox.Maui/Platforms/iOS/MapboxViewHandler.cs @@ -14,6 +14,32 @@ public partial class MapboxViewHandler UITapGestureRecognizer mapTapGestureRecognizer; UILongPressGestureRecognizer mapLongPressGestureRecognizer; + private static void HandleGestureSettingsChanged(MapboxViewHandler handler, IMapboxView view) + { + var mapView = handler.PlatformView.MapView; + if (mapView == null) return; + + var gestures = mapView.Gestures().GestureOptions(); + + gestures.DoubleTapToZoomInEnabled = view.GestureSettings.DoubleTapToZoomInEnabled; + gestures.DoubleTouchToZoomOutEnabled = view.GestureSettings.DoubleTouchToZoomOutEnabled; + gestures.FocalPoint = view.GestureSettings.FocalPoint?.ToNSValue(); + //gestures.IncreasePinchToZoomThresholdWhenRotating = view.GestureSettings.IncreasePinchToZoomThresholdWhenRotating; + //gestures.IncreaseRotateThresholdWhenPinchingToZoom = view.GestureSettings.IncreaseRotateThresholdWhenPinchingToZoom; + gestures.PanEnabled = view.GestureSettings.PinchToZoomEnabled; + //gestures.PinchToZoomDecelerationEnabled = view.GestureSettings.PinchToZoomDecelerationEnabled; + gestures.PinchZoomEnabled = view.GestureSettings.PinchToZoomEnabled; + gestures.PitchEnabled = view.GestureSettings.PitchEnabled; + gestures.QuickZoomEnabled = view.GestureSettings.QuickZoomEnabled; + //gestures.RotateDecelerationEnabled = view.GestureSettings.RotateDecelerationEnabled; + gestures.RotateEnabled = view.GestureSettings.RotateEnabled; + //gestures.ScrollDecelerationEnabled = view.GestureSettings.ScrollDecelerationEnabled; + //gestures.ScrollEnabled = view.GestureSettings.ScrollEnabled; + gestures.PanMode = view.GestureSettings.ScrollMode.ToNative(); + gestures.SimultaneousRotateAndPinchZoomEnabled = view.GestureSettings.SimultaneousRotateAndPinchToZoomEnabled; + gestures.PanDecelerationFactor = view.GestureSettings.ZoomAnimationAmount; + } + private static void HandleLightChanged(MapboxViewHandler handler, IMapboxView view) { var mapView = handler.PlatformView.MapView; diff --git a/src/qs/MapboxMauiQs/MapboxMauiQs.csproj b/src/qs/MapboxMauiQs/MapboxMauiQs.csproj index fdbb110..b8f40ac 100644 --- a/src/qs/MapboxMauiQs/MapboxMauiQs.csproj +++ b/src/qs/MapboxMauiQs/MapboxMauiQs.csproj @@ -105,8 +105,8 @@ - - + + Platforms\iOS\Shared\%(RecursiveDir)%(Filename)%(Extension) From f54b9396a70b81e67b3727363c728ef0419ae26d Mon Sep 17 00:00:00 2001 From: Tuyen Vu Date: Thu, 4 Jul 2024 07:47:47 +0700 Subject: [PATCH 2/5] - revert nuget.config --- nuget.config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nuget.config b/nuget.config index ad9100d..ba7edaf 100644 --- a/nuget.config +++ b/nuget.config @@ -1,6 +1,6 @@  - + \ No newline at end of file From 7c41f4ef2fb6a56b888ba77c0d35cb0526c40786 Mon Sep 17 00:00:00 2001 From: Tuyen Vu Date: Thu, 4 Jul 2024 07:51:52 +0700 Subject: [PATCH 3/5] - empty example for gesture settings --- .../GestureSettingsExample.cs | 41 +++++++++++++++++++ .../GestureSettingsExampleInfo.cs | 11 +++++ 2 files changed, 52 insertions(+) create mode 100644 src/qs/MapboxMauiQs/Examples/Lab/66.GestureSettings/GestureSettingsExample.cs create mode 100644 src/qs/MapboxMauiQs/Examples/Lab/66.GestureSettings/GestureSettingsExampleInfo.cs diff --git a/src/qs/MapboxMauiQs/Examples/Lab/66.GestureSettings/GestureSettingsExample.cs b/src/qs/MapboxMauiQs/Examples/Lab/66.GestureSettings/GestureSettingsExample.cs new file mode 100644 index 0000000..d70ee4b --- /dev/null +++ b/src/qs/MapboxMauiQs/Examples/Lab/66.GestureSettings/GestureSettingsExample.cs @@ -0,0 +1,41 @@ +namespace MapboxMauiQs; + +public class GestureSettingsExample : ContentPage, IExamplePage, IQueryAttributable +{ + MapboxView map; + IExampleInfo info; + + public GestureSettingsExample() + { + iOSPage.SetUseSafeArea(this, false); + Content = map = new MapboxView(); + + map.MapReady += Map_MapReady; + map.MapLoaded += Map_MapLoaded; + } + + public void ApplyQueryAttributes(IDictionary query) + { + info = query["example"] as IExampleInfo; + + Title = info?.Title; + } + + private void Map_MapReady(object sender, EventArgs e) + { + var centerLocation = new MapPosition(21.0278, 105.8342); + var cameraOptions = new CameraOptions + { + Center = centerLocation, + Zoom = 14, + }; + + map.CameraOptions = cameraOptions; + map.MapboxStyle = MapboxStyle.MAPBOX_STREETS; + } + + private void Map_MapLoaded(object sender, EventArgs e) + { + // Setup Styles, Annotations, etc here + } +} \ No newline at end of file diff --git a/src/qs/MapboxMauiQs/Examples/Lab/66.GestureSettings/GestureSettingsExampleInfo.cs b/src/qs/MapboxMauiQs/Examples/Lab/66.GestureSettings/GestureSettingsExampleInfo.cs new file mode 100644 index 0000000..432aba7 --- /dev/null +++ b/src/qs/MapboxMauiQs/Examples/Lab/66.GestureSettings/GestureSettingsExampleInfo.cs @@ -0,0 +1,11 @@ +namespace MapboxMauiQs; + +class GestureSettingsExampleInfo : IExampleInfo +{ + public string Group => "Lab"; + public string Title => "Gesture Settings"; + public string Subtitle => "Enable and disable default gestures."; + public string PageRoute => typeof(GestureSettingsExample).FullName; + public int GroupIndex => 0; + public int Index => 66; +} \ No newline at end of file From 9a044b5e11265d9d45813d3b5647029621719f40 Mon Sep 17 00:00:00 2001 From: Tuyen Vu Date: Fri, 5 Jul 2024 06:46:51 +0700 Subject: [PATCH 4/5] - WIP --- src/libs/Mapbox.Maui/MapboxView.cs | 4 +- .../Mapbox.Maui/Models/GestureSettings.cs | 7 + .../Platforms/Android/MapboxViewHandler.cs | 2 +- .../Platforms/iOS/MapboxViewHandler.cs | 2 +- src/qs/MapboxMauiQs/AppShell.xaml.cs | 2 + .../GestureSettingsExample.cs | 454 +++++++++++++++++- 6 files changed, 460 insertions(+), 11 deletions(-) diff --git a/src/libs/Mapbox.Maui/MapboxView.cs b/src/libs/Mapbox.Maui/MapboxView.cs index 07bf827..d9fe7ca 100644 --- a/src/libs/Mapbox.Maui/MapboxView.cs +++ b/src/libs/Mapbox.Maui/MapboxView.cs @@ -12,8 +12,8 @@ public partial class MapboxView : View, IMapboxView ); public GestureSettings GestureSettings { - get => (GestureSettings)GetValue(ViewAnnotationsProperty); - set => SetValue(ViewAnnotationsProperty, value); + get => (GestureSettings)GetValue(GestureSettingsProperty); + set => SetValue(GestureSettingsProperty, value); } public static readonly BindableProperty ViewAnnotationsProperty = BindableProperty.Create( diff --git a/src/libs/Mapbox.Maui/Models/GestureSettings.cs b/src/libs/Mapbox.Maui/Models/GestureSettings.cs index 4973ffa..c847975 100644 --- a/src/libs/Mapbox.Maui/Models/GestureSettings.cs +++ b/src/libs/Mapbox.Maui/Models/GestureSettings.cs @@ -80,11 +80,18 @@ public GestureSettings() /// public bool IncreasePinchToZoomThresholdWhenRotating { get; set; } = true; /// + /// Android only. /// The amount by which the zoom level increases or decreases during a double-tap-to-zoom-in or /// double-touch-to-zoom-out gesture. 1.0 by default. Must be positive. /// public float ZoomAnimationAmount { get; set; } = 1.0f; /// + /// iOS only. + /// A constant factor that determines how quickly pan deceleration animations happen. + /// Multiplied with the velocity vector once per millisecond during deceleration animations. + /// + public float PanDecelerationFactor { get; set; } = 1.0f; + /// /// Whether pan is enabled for the pinch gesture. /// /// iOS: PanEnabled diff --git a/src/libs/Mapbox.Maui/Platforms/Android/MapboxViewHandler.cs b/src/libs/Mapbox.Maui/Platforms/Android/MapboxViewHandler.cs index 13450db..e98fc0e 100644 --- a/src/libs/Mapbox.Maui/Platforms/Android/MapboxViewHandler.cs +++ b/src/libs/Mapbox.Maui/Platforms/Android/MapboxViewHandler.cs @@ -225,7 +225,7 @@ private static void HandleMapboxStyleChanged(MapboxViewHandler handler, IMapboxV styleUri = MapboxMapsStyle.MapboxStreets; } - handler.GetMapView()?.MapboxMap.LoadStyleUri(styleUri); + handler.GetMapView()?.MapboxMap.LoadStyle(styleUri); } protected override PlatformView CreatePlatformView() diff --git a/src/libs/Mapbox.Maui/Platforms/iOS/MapboxViewHandler.cs b/src/libs/Mapbox.Maui/Platforms/iOS/MapboxViewHandler.cs index a693522..643d18e 100644 --- a/src/libs/Mapbox.Maui/Platforms/iOS/MapboxViewHandler.cs +++ b/src/libs/Mapbox.Maui/Platforms/iOS/MapboxViewHandler.cs @@ -37,7 +37,7 @@ private static void HandleGestureSettingsChanged(MapboxViewHandler handler, IMap //gestures.ScrollEnabled = view.GestureSettings.ScrollEnabled; gestures.PanMode = view.GestureSettings.ScrollMode.ToNative(); gestures.SimultaneousRotateAndPinchZoomEnabled = view.GestureSettings.SimultaneousRotateAndPinchToZoomEnabled; - gestures.PanDecelerationFactor = view.GestureSettings.ZoomAnimationAmount; + gestures.PanDecelerationFactor = view.GestureSettings.PanDecelerationFactor; } private static void HandleLightChanged(MapboxViewHandler handler, IMapboxView view) diff --git a/src/qs/MapboxMauiQs/AppShell.xaml.cs b/src/qs/MapboxMauiQs/AppShell.xaml.cs index ec63949..c76c482 100644 --- a/src/qs/MapboxMauiQs/AppShell.xaml.cs +++ b/src/qs/MapboxMauiQs/AppShell.xaml.cs @@ -5,6 +5,8 @@ public partial class AppShell : Shell public AppShell() { InitializeComponent(); + + Routing.RegisterRoute(nameof(GestureSettingsExample.GestureSettingsExampleSettingsPage), typeof(GestureSettingsExample.GestureSettingsExampleSettingsPage)); } } diff --git a/src/qs/MapboxMauiQs/Examples/Lab/66.GestureSettings/GestureSettingsExample.cs b/src/qs/MapboxMauiQs/Examples/Lab/66.GestureSettings/GestureSettingsExample.cs index d70ee4b..5d75ee6 100644 --- a/src/qs/MapboxMauiQs/Examples/Lab/66.GestureSettings/GestureSettingsExample.cs +++ b/src/qs/MapboxMauiQs/Examples/Lab/66.GestureSettings/GestureSettingsExample.cs @@ -6,24 +6,46 @@ public class GestureSettingsExample : ContentPage, IExamplePage, IQueryAttributa IExampleInfo info; public GestureSettingsExample() - { + { iOSPage.SetUseSafeArea(this, false); - Content = map = new MapboxView(); + Content = map = new MapboxView(); + + var toolbarItem = new ToolbarItem() + { + Text = "Config", + Command = new Command(ShowPopup) + }; + ToolbarItems.Add(toolbarItem); map.MapReady += Map_MapReady; map.MapLoaded += Map_MapLoaded; - } + } + + private async void ShowPopup() + { + await Shell.Current.GoToAsync(nameof(GestureSettingsExampleSettingsPage), true, new Dictionary() + { + { "data", map.GestureSettings } + }); + } public void ApplyQueryAttributes(IDictionary query) { - info = query["example"] as IExampleInfo; + if (query.TryGetValue("example", out var example) && example is IExampleInfo exampleInfo) + { + info = exampleInfo; + Title = info?.Title; + } - Title = info?.Title; + if (query.TryGetValue("data", out var data) && data is GestureSettings gestureSettings) + { + map.GestureSettings = gestureSettings; + } } private void Map_MapReady(object sender, EventArgs e) { - var centerLocation = new MapPosition(21.0278, 105.8342); + var centerLocation = new MapPosition(21.028511, 105.804817); var cameraOptions = new CameraOptions { Center = centerLocation, @@ -31,11 +53,429 @@ private void Map_MapReady(object sender, EventArgs e) }; map.CameraOptions = cameraOptions; - map.MapboxStyle = MapboxStyle.MAPBOX_STREETS; } private void Map_MapLoaded(object sender, EventArgs e) { // Setup Styles, Annotations, etc here } + + public class GestureSettingsExampleSettingsPage : ContentPage, IQueryAttributable + { + private GestureSettings gestureSettings; + private StackLayout mainContent; + + public GestureSettingsExampleSettingsPage() + { + Shell.SetPresentationMode(this, PresentationMode.ModalAnimated); + + Padding = new Thickness(0, 64, 0, 0); + + mainContent = new StackLayout + { + Spacing = 0, + }; + Content = new StackLayout + { + Spacing = 0, + Children = { + new Grid + { + Children = + { + new Label + { + Text = "Gesture Configs", + FontSize = 26, + Margin = 16, + HorizontalTextAlignment = TextAlignment.Center, + }, + new Label + { + Text = "Apply", + Margin = 16, + VerticalOptions = LayoutOptions.Center, + HorizontalOptions = LayoutOptions.End, + GestureRecognizers = + { + new TapGestureRecognizer + { + Command = new Command(Apply), + }, + } + } + } + }, + new BoxView + { + Margin = 16, + }, + new ScrollView + { + HorizontalScrollBarVisibility = ScrollBarVisibility.Never, + Content = new Grid + { + Children = + { + mainContent, + }, + }, + } + }, + }; + } + + private View CreateSwitchRow(string title, bool defaultValue) + { + var @switch = new Switch + { + IsToggled = defaultValue, + VerticalOptions = LayoutOptions.Center, + HorizontalOptions = LayoutOptions.End, + }; + + @switch.Toggled += (s, e) => + { + ToggleEnabled((s as Switch).Parent, e); + }; + return new Grid + { + Padding = new Thickness(16, 8), + Children = { + new Label + { + Text = title, + FontSize = 16, + VerticalOptions = LayoutOptions.Center, + }, + @switch, + } + }; + } + + private void ToggleEnabled(object sender, ToggledEventArgs e) + { + var grid = (Grid)sender; + var label = (Label)grid.Children[0]; + + switch (label.Text) { + case nameof(DoubleTapToZoomInEnabled): + DoubleTapToZoomInEnabled = e.Value; + break; + case nameof(DoubleTouchToZoomOutEnabled): + DoubleTouchToZoomOutEnabled = e.Value; + break; + case nameof(PinchScrollEnabled): + PinchScrollEnabled = e.Value; + break; + case nameof(PinchToZoomDecelerationEnabled): + PinchToZoomDecelerationEnabled = e.Value; + break; + case nameof(PinchToZoomEnabled): + PinchToZoomEnabled = e.Value; + break; + case nameof(PitchEnabled): + PitchEnabled = e.Value; + break; + case nameof(QuickZoomEnabled): + QuickZoomEnabled = e.Value; + break; + case nameof(RotateDecelerationEnabled): + RotateDecelerationEnabled = e.Value; + break; + case nameof(RotateEnabled): + RotateEnabled = e.Value; + break; + case nameof(ScrollDecelerationEnabled): + ScrollDecelerationEnabled = e.Value; + break; + case nameof(ScrollEnabled): + ScrollEnabled = e.Value; + break; + case nameof(SimultaneousRotateAndPinchToZoomEnabled): + SimultaneousRotateAndPinchToZoomEnabled = e.Value; + break; + } + } + + private async void Apply() + { + await Shell.Current.GoToAsync("..", new Dictionary() + { + { "data", gestureSettings }, + }); + } + + public void ApplyQueryAttributes(IDictionary query) + { + gestureSettings = (GestureSettings)query["data"]; + + mainContent.Children.Add(CreateSwitchRow(nameof(DoubleTapToZoomInEnabled), DoubleTapToZoomInEnabled)); + mainContent.Children.Add(CreateSwitchRow(nameof(DoubleTouchToZoomOutEnabled), DoubleTouchToZoomOutEnabled)); + mainContent.Children.Add(CreateSwitchRow(nameof(IncreasePinchToZoomThresholdWhenRotating), IncreasePinchToZoomThresholdWhenRotating)); + mainContent.Children.Add(CreateSwitchRow(nameof(IncreaseRotateThresholdWhenPinchingToZoom), IncreaseRotateThresholdWhenPinchingToZoom)); + mainContent.Children.Add(CreateSwitchRow(nameof(PinchScrollEnabled), PinchScrollEnabled)); + mainContent.Children.Add(CreateSwitchRow(nameof(PinchToZoomDecelerationEnabled), PinchToZoomDecelerationEnabled)); + mainContent.Children.Add(CreateSwitchRow(nameof(PinchToZoomEnabled), PinchToZoomEnabled)); + mainContent.Children.Add(CreateSwitchRow(nameof(PitchEnabled), PitchEnabled)); + mainContent.Children.Add(CreateSwitchRow(nameof(QuickZoomEnabled), QuickZoomEnabled)); + mainContent.Children.Add(CreateSwitchRow(nameof(RotateDecelerationEnabled), RotateDecelerationEnabled)); + mainContent.Children.Add(CreateSwitchRow(nameof(RotateEnabled), RotateEnabled)); + mainContent.Children.Add(CreateSwitchRow(nameof(ScrollDecelerationEnabled), ScrollDecelerationEnabled)); + mainContent.Children.Add(CreateSwitchRow(nameof(ScrollEnabled), ScrollEnabled)); + mainContent.Children.Add(CreateSwitchRow(nameof(SimultaneousRotateAndPinchToZoomEnabled), SimultaneousRotateAndPinchToZoomEnabled)); + + mainContent.Children.Add(CreateFocalPointView()); + } + + private IView CreateFocalPointView() + { + var row = new StackLayout + { + + }; + row.Add(new Label + { + Text = "FocalPoint", + }); + row.Add(new StackLayout + { + Orientation = StackOrientation.Horizontal, + Children = + { + new Label + { + Text = "X=" + }, + new Slider + { + Minimum = 0, + Maximum = DeviceDisplay.Current.MainDisplayInfo.Width, + }, + } + }); + row.Add(new StackLayout + { + Orientation = StackOrientation.Horizontal, + Children = + { + new Label + { + Text = "Y=" + }, + new Slider + { + Minimum = 0, + Maximum = DeviceDisplay.Current.MainDisplayInfo.Height, + }, + } + }); + + return row; + } + + /// + /// Whether the rotate gesture is enabled. + /// + public bool RotateEnabled + { + get => gestureSettings.RotateEnabled; + set => gestureSettings = gestureSettings with + { + RotateEnabled = value, + }; + } + /// + /// Whether the pinch to zoom gesture is enabled. + /// + /// iOS: PinchZoomEnabled + /// + public bool PinchToZoomEnabled + { + get => gestureSettings.PinchToZoomEnabled; + set => gestureSettings = gestureSettings with + { + PinchToZoomEnabled = value, + }; + } + /// + /// Whether the single-touch scroll gesture is enabled. + /// + public bool ScrollEnabled + { + get => gestureSettings.ScrollEnabled; + set => gestureSettings = gestureSettings with + { + ScrollEnabled = value, + }; + } + /// + /// Whether rotation is enabled for the pinch to zoom gesture. + /// + /// iOS: SimultaneousRotateAndPinchZoomEnabled + /// + public bool SimultaneousRotateAndPinchToZoomEnabled + { + get => gestureSettings.SimultaneousRotateAndPinchToZoomEnabled; + set => gestureSettings = gestureSettings with + { + SimultaneousRotateAndPinchToZoomEnabled = value, + }; + } + /// + /// Whether the pitch gesture is enabled. + /// + public bool PitchEnabled + { + get => gestureSettings.PitchEnabled; + set => gestureSettings = gestureSettings with + { + PitchEnabled = value, + }; + } + /// + /// Configures the directions in which the map is allowed to move during a scroll gesture. + /// + /// iOS: PanMode + /// + public PanMode ScrollMode + { + get => gestureSettings.ScrollMode; + set => gestureSettings = gestureSettings with + { + ScrollMode = value, + }; + } + /// + /// Whether double tapping the map with one touch results in a zoom-in animation. + /// + public bool DoubleTapToZoomInEnabled + { + get => gestureSettings.DoubleTapToZoomInEnabled; + set => gestureSettings = gestureSettings with + { + DoubleTapToZoomInEnabled = value, + }; + } + /// + /// Whether single tapping the map with two touches results in a zoom-out animation. + /// + public bool DoubleTouchToZoomOutEnabled + { + get => gestureSettings.DoubleTouchToZoomOutEnabled; + set => gestureSettings = gestureSettings with + { + DoubleTouchToZoomOutEnabled = value, + }; + } + /// + /// Whether the quick zoom gesture is enabled. + /// + public bool QuickZoomEnabled + { + get => gestureSettings.QuickZoomEnabled; + set => gestureSettings = gestureSettings with + { + QuickZoomEnabled = value, + }; + } + /// + /// By default, gestures rotate and zoom around the center of the gesture. Set this property to + /// rotate and zoom around a fixed point instead. + /// + public ScreenPosition? FocalPoint + { + get => gestureSettings.FocalPoint; + set => gestureSettings = gestureSettings with + { + FocalPoint = value, + }; + } + /// + /// Android only. + /// Whether a deceleration animation following a pinch-to-zoom gesture is enabled. True by default. + /// + public bool PinchToZoomDecelerationEnabled + { + get => gestureSettings.PinchToZoomDecelerationEnabled; + set => gestureSettings = gestureSettings with + { + PinchToZoomDecelerationEnabled = value, + }; + } + /// + /// Android only. + /// Whether a deceleration animation following a rotate gesture is enabled. True by default. + /// + public bool RotateDecelerationEnabled + { + get => gestureSettings.RotateDecelerationEnabled; + set => gestureSettings = gestureSettings with + { + RotateDecelerationEnabled = value, + }; + } + /// + /// Android only. + /// Whether a deceleration animation following a scroll gesture is enabled. True by default. + /// + public bool ScrollDecelerationEnabled + { + get => gestureSettings.ScrollDecelerationEnabled; + set => gestureSettings = gestureSettings with + { + ScrollDecelerationEnabled = value, + }; + } + /// + /// Android only. + /// + /// Whether rotate threshold increases when pinching to zoom. true by default. + /// + public bool IncreaseRotateThresholdWhenPinchingToZoom + { + get => gestureSettings.IncreaseRotateThresholdWhenPinchingToZoom; + set => gestureSettings = gestureSettings with + { + IncreaseRotateThresholdWhenPinchingToZoom = value, + }; + } + /// + /// Android only. + /// Whether pinch to zoom threshold increases when rotating. true by default. + /// + public bool IncreasePinchToZoomThresholdWhenRotating + { + get => gestureSettings.IncreasePinchToZoomThresholdWhenRotating; + set => gestureSettings = gestureSettings with + { + IncreasePinchToZoomThresholdWhenRotating = value, + }; + } + /// + /// The amount by which the zoom level increases or decreases during a double-tap-to-zoom-in or + /// double-touch-to-zoom-out gesture. 1.0 by default. Must be positive. + /// + public float ZoomAnimationAmount + { + get => gestureSettings.ZoomAnimationAmount; + set => gestureSettings = gestureSettings with + { + ZoomAnimationAmount = value, + }; + } + /// + /// Whether pan is enabled for the pinch gesture. + /// + /// iOS: PanEnabled + /// + public bool PinchScrollEnabled + { + get => gestureSettings.PinchScrollEnabled; + set => gestureSettings = gestureSettings with + { + PinchScrollEnabled = value, + }; + } + } } \ No newline at end of file From d03cc52390a77f776d50d367293afae4e4d2f5e1 Mon Sep 17 00:00:00 2001 From: Tuyen Vu Date: Wed, 10 Jul 2024 06:11:17 +0700 Subject: [PATCH 5/5] - 11.4.0-alpha02 --- src/libs/Mapbox.Maui/Mapbox.Maui.csproj | 4 +-- .../Platforms/iOS/MapboxViewHandler.cs | 35 +++++++++---------- src/qs/MapboxMauiQs/MapboxMauiQs.csproj | 2 +- 3 files changed, 19 insertions(+), 22 deletions(-) diff --git a/src/libs/Mapbox.Maui/Mapbox.Maui.csproj b/src/libs/Mapbox.Maui/Mapbox.Maui.csproj index e1451d9..907eee3 100644 --- a/src/libs/Mapbox.Maui/Mapbox.Maui.csproj +++ b/src/libs/Mapbox.Maui/Mapbox.Maui.csproj @@ -53,7 +53,7 @@ https://github.com/tuyen-vuduc/mapbox-maui https://mapbox.tuyen-vuduc.tech false - 11.4.0-alpha01 + 11.4.0-alpha02 README.md LICENSE tv-mapbox.png @@ -80,7 +80,7 @@ - + diff --git a/src/libs/Mapbox.Maui/Platforms/iOS/MapboxViewHandler.cs b/src/libs/Mapbox.Maui/Platforms/iOS/MapboxViewHandler.cs index 643d18e..751c9b1 100644 --- a/src/libs/Mapbox.Maui/Platforms/iOS/MapboxViewHandler.cs +++ b/src/libs/Mapbox.Maui/Platforms/iOS/MapboxViewHandler.cs @@ -19,25 +19,22 @@ private static void HandleGestureSettingsChanged(MapboxViewHandler handler, IMap var mapView = handler.PlatformView.MapView; if (mapView == null) return; - var gestures = mapView.Gestures().GestureOptions(); - - gestures.DoubleTapToZoomInEnabled = view.GestureSettings.DoubleTapToZoomInEnabled; - gestures.DoubleTouchToZoomOutEnabled = view.GestureSettings.DoubleTouchToZoomOutEnabled; - gestures.FocalPoint = view.GestureSettings.FocalPoint?.ToNSValue(); - //gestures.IncreasePinchToZoomThresholdWhenRotating = view.GestureSettings.IncreasePinchToZoomThresholdWhenRotating; - //gestures.IncreaseRotateThresholdWhenPinchingToZoom = view.GestureSettings.IncreaseRotateThresholdWhenPinchingToZoom; - gestures.PanEnabled = view.GestureSettings.PinchToZoomEnabled; - //gestures.PinchToZoomDecelerationEnabled = view.GestureSettings.PinchToZoomDecelerationEnabled; - gestures.PinchZoomEnabled = view.GestureSettings.PinchToZoomEnabled; - gestures.PitchEnabled = view.GestureSettings.PitchEnabled; - gestures.QuickZoomEnabled = view.GestureSettings.QuickZoomEnabled; - //gestures.RotateDecelerationEnabled = view.GestureSettings.RotateDecelerationEnabled; - gestures.RotateEnabled = view.GestureSettings.RotateEnabled; - //gestures.ScrollDecelerationEnabled = view.GestureSettings.ScrollDecelerationEnabled; - //gestures.ScrollEnabled = view.GestureSettings.ScrollEnabled; - gestures.PanMode = view.GestureSettings.ScrollMode.ToNative(); - gestures.SimultaneousRotateAndPinchZoomEnabled = view.GestureSettings.SimultaneousRotateAndPinchToZoomEnabled; - gestures.PanDecelerationFactor = view.GestureSettings.PanDecelerationFactor; + var gestureOptions = new TMBGestureOptions( + panEnabled: view.GestureSettings.PinchScrollEnabled, + pinchEnabled: false, + rotateEnabled: view.GestureSettings.RotateEnabled, + simultaneousRotateAndPinchZoomEnabled: view.GestureSettings.SimultaneousRotateAndPinchToZoomEnabled, + pinchZoomEnabled: view.GestureSettings.PinchToZoomEnabled, + pinchPanEnabled: false, + pitchEnabled: view.GestureSettings.PitchEnabled, + doubleTapToZoomInEnabled: view.GestureSettings.DoubleTapToZoomInEnabled, + doubleTouchToZoomOutEnabled: view.GestureSettings.DoubleTouchToZoomOutEnabled, + quickZoomEnabled: view.GestureSettings.QuickZoomEnabled, + panDecelerationFactor: UIScrollView.DecelerationRateNormal, + panMode: view.GestureSettings.ScrollMode.ToNative(), + focalPoint: view.GestureSettings.FocalPoint?.ToNSValue() + ); + mapView.Gestures().GestureOptions = gestureOptions; } private static void HandleLightChanged(MapboxViewHandler handler, IMapboxView view) diff --git a/src/qs/MapboxMauiQs/MapboxMauiQs.csproj b/src/qs/MapboxMauiQs/MapboxMauiQs.csproj index b8f40ac..4692bf6 100644 --- a/src/qs/MapboxMauiQs/MapboxMauiQs.csproj +++ b/src/qs/MapboxMauiQs/MapboxMauiQs.csproj @@ -105,7 +105,7 @@ - +