summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjh5.cho <jh5.cho@samsung.com>2017-03-15 20:42:39 +0900
committerKangho Hur <kangho.hur@samsung.com>2017-04-24 13:36:55 +0900
commit7eddd987a359af43fb147d5da1897db7e84f3f69 (patch)
tree7261a31dcfb4451a1462aa9942417a8c9d001ea0
parent5ed0ce74aea15d4f4ddb0f2caec65bd616821015 (diff)
downloadxamarin-forms-7eddd987a359af43fb147d5da1897db7e84f3f69.tar.gz
xamarin-forms-7eddd987a359af43fb147d5da1897db7e84f3f69.tar.bz2
xamarin-forms-7eddd987a359af43fb147d5da1897db7e84f3f69.zip
Add Implementation of VisibleRegion
- Implementation of 'VisibleRegion' property - update 'MoveToRegion()' to support Latitude/Longitude Degree(VisibleRegion) Change-Id: Ia88657d9ddba25a1c766a16905dab8d1fca68100
-rwxr-xr-xXamarin.Forms.Maps.Tizen/MapRenderer.cs53
1 files changed, 51 insertions, 2 deletions
diff --git a/Xamarin.Forms.Maps.Tizen/MapRenderer.cs b/Xamarin.Forms.Maps.Tizen/MapRenderer.cs
index cf7ddf7f..752b021f 100755
--- a/Xamarin.Forms.Maps.Tizen/MapRenderer.cs
+++ b/Xamarin.Forms.Maps.Tizen/MapRenderer.cs
@@ -14,6 +14,7 @@ namespace Xamarin.Forms.Maps.Tizen
public class MapRenderer : ViewRenderer<Map, MapView>
{
const string MoveMessageName = "MapMoveToRegion";
+ const int BaseZoomLevel = 2;
bool _disposed;
Marker _marker;
@@ -40,6 +41,9 @@ namespace Xamarin.Forms.Maps.Tizen
if (Control == null)
{
var mapControl = new MapView(Platform.Tizen.Forms.Context.MainWindow, FormsMaps.MapService);
+
+ mapControl.RenderPost += OnVisibleRegionChanged;
+
SetNativeControl(mapControl);
}
@@ -63,6 +67,7 @@ namespace Xamarin.Forms.Maps.Tizen
UpdateHasScrollEnabled();
UpdateHasZoomEnabled();
UpdateIsShowingUser();
+ UpdateVisibleRegion();
}
base.OnElementChanged(e);
}
@@ -83,6 +88,7 @@ namespace Xamarin.Forms.Maps.Tizen
{
((ObservableCollection<Pin>)Element.Pins).CollectionChanged -= OnCollectionChanged;
}
+ Control.RenderPost -= OnVisibleRegionChanged;
Control.Unrealize();
}
base.Dispose(disposing);
@@ -104,8 +110,51 @@ namespace Xamarin.Forms.Maps.Tizen
void OnMoveToRegion(Map map, MapSpan span)
{
- var newCenter = new Geocoordinates(span.Center.Latitude, span.Center.Longitude);
- Control.Center = newCenter;
+ UpdateVisibleRegion();
+
+ int latitudeZoomFactor = GetZoomFactor(span.LatitudeDegrees, 90.0);
+ int longitudeZoomFactor = GetZoomFactor(span.LongitudeDegrees, 180.0);
+
+ Control.Center = new Geocoordinates(span.Center.Latitude, span.Center.Longitude); ;
+ Control.ZoomLevel = BaseZoomLevel + Math.Min(latitudeZoomFactor, longitudeZoomFactor);
+ UpdateVisibleRegion();
+ }
+
+ int GetZoomFactor(double degree, double targetDegree)
+ {
+ int factor = 0;
+ double tempDegree = degree;
+ while (true)
+ {
+ tempDegree = tempDegree * 2;
+ if (tempDegree > targetDegree)
+ break;
+ factor++;
+ }
+ return factor;
+ }
+
+ void OnVisibleRegionChanged(object sender, EventArgs e)
+ {
+ UpdateVisibleRegion();
+ }
+
+ void UpdateVisibleRegion()
+ {
+ int width = Control.Geometry.Width;
+ int height = Control.Geometry.Height;
+ int x = Control.Geometry.X;
+ int y = Control.Geometry.Y;
+
+ Geocoordinates ul = Control.ScreenToGeolocation(new ElmSharp.Point { X = x, Y = y});
+ Geocoordinates ur = Control.ScreenToGeolocation(new ElmSharp.Point { X = x + width, Y = y});
+ Geocoordinates ll = Control.ScreenToGeolocation(new ElmSharp.Point { X = x, Y = y + height });
+ Geocoordinates lr = Control.ScreenToGeolocation(new ElmSharp.Point { X = x + width, Y = y + height });
+
+ double dlat = Math.Max(Math.Abs(ul.Latitude - lr.Latitude), Math.Abs(ur.Latitude - ll.Latitude));
+ double dlong = Math.Max(Math.Abs(ul.Longitude - lr.Longitude), Math.Abs(ur.Longitude - ll.Longitude));
+
+ Element.VisibleRegion = new MapSpan(new Position(Control.Center.Latitude, Control.Center.Longitude), dlat, dlong);
}