Skip to content

Commit

Permalink
Add support for Geodesic polylines option
Browse files Browse the repository at this point in the history
Android & iOS only, not supported by UWP
  • Loading branch information
SebastienForay committed Jun 7, 2021
1 parent 1b54a84 commit 39ec94d
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ protected override NativePolyline CreateNativeItem(Polyline outerItem)
foreach (var p in outerItem.Positions)
opts.Add(new LatLng(p.Latitude, p.Longitude));

opts.Geodesic(outerItem.IsGeodesic);
opts.InvokeWidth(outerItem.StrokeWidth * this.ScaledDensity); // TODO: convert from px to pt. Is this collect? (looks like same iOS Maps)
opts.InvokeColor(outerItem.StrokeColor.ToAndroid());
opts.Clickable(outerItem.IsClickable);
Expand Down Expand Up @@ -105,6 +106,11 @@ internal override void OnUpdateZIndex(Polyline outerItem, NativePolyline nativeI
{
nativeItem.ZIndex = outerItem.ZIndex;
}

internal override void OnUpdateIsGeodesic(Polyline outerItem, NativePolyline nativeItem)
{
nativeItem.Geodesic = outerItem.IsGeodesic;
}
}
}

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
Expand Down Expand Up @@ -109,5 +109,9 @@ internal override void OnUpdateZIndex(Polyline outerItem, MapPolyline nativeItem
{
nativeItem.ZIndex = outerItem.ZIndex;
}

internal override void OnUpdateIsGeodesic(Polyline outerItem, MapPolyline nativeItem)
{
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
Expand Down Expand Up @@ -90,6 +90,11 @@ internal override void OnUpdateZIndex(Polyline outerItem, NativePolyline nativeI
{
nativeItem.ZIndex = outerItem.ZIndex;
}

internal override void OnUpdateIsGeodesic(Polyline outerItem, NativePolyline nativeItem)
{
nativeItem.Geodesic = outerItem.IsGeodesic;
}
}
}

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.ComponentModel;

Expand All @@ -21,11 +21,13 @@ protected override void OnItemPropertyChanged(object sender, PropertyChangedEven
else if (e.PropertyName == Polyline.StrokeColorProperty.PropertyName) OnUpdateStrokeColor(outerItem, nativeItem);
else if (e.PropertyName == Polyline.StrokeWidthProperty.PropertyName) OnUpdateStrokeWidth(outerItem, nativeItem);
else if (e.PropertyName == Polyline.ZIndexProperty.PropertyName) OnUpdateZIndex(outerItem, nativeItem);
else if (e.PropertyName == Polyline.IsGeodesicProperty.PropertyName) OnUpdateIsGeodesic(outerItem, nativeItem);
}

internal abstract void OnUpdateIsClickable(Polyline outerItem, TNative nativeItem);
internal abstract void OnUpdateStrokeColor(Polyline outerItem, TNative nativeItem);
internal abstract void OnUpdateStrokeWidth(Polyline outerItem, TNative nativeItem);
internal abstract void OnUpdateZIndex(Polyline outerItem, TNative nativeItem);
internal abstract void OnUpdateIsGeodesic(Polyline outerItem, TNative nativeItem);
}
}
7 changes: 7 additions & 0 deletions Xamarin.Forms.GoogleMaps/Xamarin.Forms.GoogleMaps/Polyline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ void HandleAction(GoogleMaps.Polygon arg1, NotifyCollectionChangedEventArgs arg2
public static readonly BindableProperty StrokeColorProperty = BindableProperty.Create(nameof(StrokeColor), typeof(Color), typeof(Polyline), Color.Blue);
public static readonly BindableProperty IsClickableProperty = BindableProperty.Create(nameof(IsClickable), typeof(bool), typeof(Polyline), false);
public static readonly BindableProperty ZIndexProperty = BindableProperty.Create(nameof(ZIndex), typeof(int), typeof(Polyline), 0);
public static readonly BindableProperty IsGeodesicProperty = BindableProperty.Create(nameof(ZIndex), typeof(bool), typeof(Polyline), false);

private readonly ObservableCollection<Position> _positions = new ObservableCollection<Position>();

Expand Down Expand Up @@ -45,6 +46,12 @@ public int ZIndex
set { SetValue(ZIndexProperty, value); }
}

public bool IsGeodesic
{
get { return (bool)GetValue(IsGeodesicProperty); }
set { SetValue(IsGeodesicProperty, value); }
}

public IList<Position> Positions
{
get { return _positions; }
Expand Down

0 comments on commit 39ec94d

Please sign in to comment.