summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Maps.UWP
diff options
context:
space:
mode:
authorindydawgy <tophe112@yahoo.com>2017-03-07 10:40:47 (GMT)
committerRui Marinho <me@ruimarinho.net>2017-03-07 10:40:47 (GMT)
commit917d27e079a23c96ee3201cc7f35069cd837ed9a (patch)
tree7a655b95e4370614cbaac758271abbf534265a5d /Xamarin.Forms.Maps.UWP
parentf6633c462929fdf426492dd9f08e9862b523b420 (diff)
downloadxamarin-forms-917d27e079a23c96ee3201cc7f35069cd837ed9a.zip
xamarin-forms-917d27e079a23c96ee3201cc7f35069cd837ed9a.tar.gz
xamarin-forms-917d27e079a23c96ee3201cc7f35069cd837ed9a.tar.bz2
UWP MapRenderer fixes. (#724)
* Issues: 1. The MapRenderer calls TrySetViewBoundsAsync before the map is ready for it. This causes the map to hardly ever initialize to the correct position. 2. The visible region calculation gets the zoom wrong. 3. Map can cause a crash if you rotate/zoom a lot when setting the visible region. Fixes: 1. Call MoveToRegion using MapControl's RunIdleAsync to have it move after the map starts rendering 2. lat/long delta should be: var latitudeDelta = Math.Abs(nw.Position.Latitude - se.Position.Latitude); var longitudeDelta = Math.Abs(nw.Position.Longitude - se.Position.Longitude); rather than calculated from the center 3. Move the visible region set into the try/catch block. * Made spaces into tabs to conform to previous standard.
Diffstat (limited to 'Xamarin.Forms.Maps.UWP')
-rw-r--r--Xamarin.Forms.Maps.UWP/MapRenderer.cs40
1 files changed, 17 insertions, 23 deletions
diff --git a/Xamarin.Forms.Maps.UWP/MapRenderer.cs b/Xamarin.Forms.Maps.UWP/MapRenderer.cs
index 842864b..7b3bcd2 100644
--- a/Xamarin.Forms.Maps.UWP/MapRenderer.cs
+++ b/Xamarin.Forms.Maps.UWP/MapRenderer.cs
@@ -47,8 +47,8 @@ namespace Xamarin.Forms.Maps.WinRT
{
SetNativeControl(new MapControl());
Control.MapServiceToken = FormsMaps.AuthenticationToken;
- Control.ZoomLevelChanged += async (s, a) => await UpdateVisibleRegion();
- Control.CenterChanged += async (s, a) => await UpdateVisibleRegion();
+ Control.ZoomLevelChanged += (s, a) => UpdateVisibleRegion();
+ Control.CenterChanged += (s, a) => UpdateVisibleRegion();
}
MessagingCenter.Subscribe<Map, MapSpan>(this, "MapMoveToRegion", async (s, a) => await MoveToRegion(a), mapModel);
@@ -63,7 +63,8 @@ namespace Xamarin.Forms.Maps.WinRT
LoadPins();
await UpdateIsShowingUser();
- }
+ await Control.Dispatcher.RunIdleAsync(async (i) => await MoveToRegion(mapModel.LastMoveToRegion, MapAnimationKind.None));
+ }
}
protected override async void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
@@ -98,7 +99,6 @@ namespace Xamarin.Forms.Maps.WinRT
}
bool _disposed;
- bool _firstZoomLevelChangeFired;
Ellipse _userPositionCircle;
DispatcherTimer _timer;
@@ -207,36 +207,30 @@ namespace Xamarin.Forms.Maps.WinRT
await Control.TrySetViewBoundsAsync(boundingBox, null, animation);
}
- async Task UpdateVisibleRegion()
+ void UpdateVisibleRegion()
{
if (Control == null || Element == null)
return;
-
- if (!_firstZoomLevelChangeFired)
- {
- await MoveToRegion(Element.LastMoveToRegion, MapAnimationKind.None);
- _firstZoomLevelChangeFired = true;
- return;
- }
- Geopoint nw, se = null;
+
try
{
+ Geopoint nw, se = null;
Control.GetLocationFromOffset(new Windows.Foundation.Point(0, 0), out nw);
Control.GetLocationFromOffset(new Windows.Foundation.Point(Control.ActualWidth, Control.ActualHeight), out se);
- }
+
+ if (nw != null && se != null)
+ {
+ var boundingBox = new GeoboundingBox(nw.Position, se.Position);
+ var center = new Position(boundingBox.Center.Latitude, boundingBox.Center.Longitude);
+ var latitudeDelta = Math.Abs(nw.Position.Latitude - se.Position.Latitude);
+ var longitudeDelta = Math.Abs(nw.Position.Longitude - se.Position.Longitude);
+ Element.VisibleRegion = new MapSpan(center, latitudeDelta, longitudeDelta);
+ }
+ }
catch (Exception)
{
return;
}
-
- if (nw != null && se != null)
- {
- var boundingBox = new GeoboundingBox(nw.Position, se.Position);
- var center = new Position(boundingBox.Center.Latitude, boundingBox.Center.Longitude);
- var latitudeDelta = Math.Abs(center.Latitude - boundingBox.NorthwestCorner.Latitude);
- var longitudeDelta = Math.Abs(center.Longitude - boundingBox.NorthwestCorner.Longitude);
- Element.VisibleRegion = new MapSpan(center, latitudeDelta, longitudeDelta);
- }
}
void LoadUserPosition(Geocoordinate userCoordinate, bool center)