summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRui Marinho <me@ruimarinho.net>2016-06-16 17:03:11 (GMT)
committerGitHub <noreply@github.com>2016-06-16 17:03:11 (GMT)
commit7ae79f49072d4543da80eaf443e214fdfa02ed9c (patch)
treed4332fa6a76b7f4ac27fad7a1c4d9f733b9f861c
parent122a1f2a4028d7359774f5f4987c51dc3573c5d6 (diff)
downloadxamarin-forms-7ae79f49072d4543da80eaf443e214fdfa02ed9c.zip
xamarin-forms-7ae79f49072d4543da80eaf443e214fdfa02ed9c.tar.gz
xamarin-forms-7ae79f49072d4543da80eaf443e214fdfa02ed9c.tar.bz2
[IOS] Update the current region of the MKMapView when visibility is changed (#172)
-rw-r--r--Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla38284.cs77
-rw-r--r--Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems1
-rw-r--r--Xamarin.Forms.Maps.iOS/MapRenderer.cs14
3 files changed, 92 insertions, 0 deletions
diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla38284.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla38284.cs
new file mode 100644
index 0000000..f476e56
--- /dev/null
+++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla38284.cs
@@ -0,0 +1,77 @@
+´╗┐using System;
+
+using Xamarin.Forms.CustomAttributes;
+using Xamarin.Forms.Internals;
+using Xamarin.Forms.Maps;
+
+
+namespace Xamarin.Forms.Controls
+{
+ [Preserve(AllMembers = true)]
+ [Issue(IssueTracker.Bugzilla, 38284, "when creating a map in iOS, if the map is not visible when the page is created the zoom level is offn")]
+ public class Bugzilla38284 : TestContentPage // or TestMasterDetailPage, etc ...
+ {
+ Map map1;
+ Map map2;
+ double Latitude = 28.032005;
+ double Longitude = -81.948931;
+ string LocationTitle = "Someplace Cool";
+ string StreetAddress = "";
+
+ protected override void Init()
+ {
+ var stack = new StackLayout();
+
+ map1 = new Maps.Map
+ {
+ IsShowingUser = false,
+ WidthRequest = 320,
+ HeightRequest = 200
+ };
+
+ map2 = new Maps.Map
+ {
+ IsShowingUser = false,
+ WidthRequest = 320,
+ HeightRequest = 200
+ };
+
+
+ var btn = new Button { Text = "Show" };
+ btn.Clicked += (sender, e) =>
+ {
+ map2.IsVisible = !map2.IsVisible;
+ };
+
+ stack.Children.Add(map1);
+ stack.Children.Add(map2);
+ stack.Children.Add(btn);
+ DisplayMaps();
+ Content = stack;
+ }
+
+ public void DisplayMaps()
+ {
+ map2.IsVisible = false;
+ var mapPinPosition = new Position(Latitude, Longitude);
+
+ var type = MapType.Satellite;
+ map1.MapType = type;
+ map2.MapType = type;
+ var pin = new Pin
+ {
+ Type = PinType.Place,
+ Position = mapPinPosition,
+ Label = LocationTitle,
+ Address = StreetAddress
+ };
+ map1.Pins.Add(pin);
+ map2.Pins.Add(pin);
+
+ // Move the map to center on the map location with the proper zoom level
+ var lldegrees = 360 / (Math.Pow(2, 16));
+ map1.MoveToRegion(new MapSpan(map1.Pins[0].Position, lldegrees, lldegrees));
+ map2.MoveToRegion(new MapSpan(map2.Pins[0].Position, lldegrees, lldegrees));
+ }
+ }
+}
diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems
index ed0d973..5c96324 100644
--- a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems
+++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems
@@ -406,6 +406,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla39987.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla40704.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla41038.cs" />
+ <Compile Include="$(MSBuildThisFileDirectory)Bugzilla38284.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Bugzilla22229.xaml">
diff --git a/Xamarin.Forms.Maps.iOS/MapRenderer.cs b/Xamarin.Forms.Maps.iOS/MapRenderer.cs
index 94d5eee..c556d14 100644
--- a/Xamarin.Forms.Maps.iOS/MapRenderer.cs
+++ b/Xamarin.Forms.Maps.iOS/MapRenderer.cs
@@ -134,6 +134,7 @@ namespace Xamarin.Forms.Maps.iOS
public class MapRenderer : ViewRenderer
{
CLLocationManager _locationManager;
+ bool _shouldUpdateRegion;
public override SizeRequest GetDesiredSize(double widthConstraint, double heightConstraint)
{
@@ -215,6 +216,19 @@ namespace Xamarin.Forms.Maps.iOS
UpdateHasScrollEnabled();
else if (e.PropertyName == Map.HasZoomEnabledProperty.PropertyName)
UpdateHasZoomEnabled();
+ else if (e.PropertyName == VisualElement.IsVisibleProperty.PropertyName && ((Map)Element).LastMoveToRegion != null)
+ _shouldUpdateRegion = true;
+ }
+
+ public override void LayoutSubviews()
+ {
+ base.LayoutSubviews();
+ if (_shouldUpdateRegion)
+ {
+ MoveToRegion(((Map)Element).LastMoveToRegion, false);
+ _shouldUpdateRegion = false;
+ }
+
}
void AddPins(IList pins)