summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKangho Hur <kangho.hur@samsung.com>2017-03-17 08:39:36 (GMT)
committerGerrit Code Review <gerrit@review.vlan103.tizen.org>2017-03-17 08:39:36 (GMT)
commitd4682208ed8deb8d97181f0ae13da90b90d5b205 (patch)
tree23a1c2647ac740a22024c3a16cb498408c7e6d85
parent441b3623df26aecd2e283cfa40c8c7a338ce0a7e (diff)
parente9f30fc1f8f43ddbd025807e398eb741596322bf (diff)
downloadxamarin-forms-d4682208ed8deb8d97181f0ae13da90b90d5b205.zip
xamarin-forms-d4682208ed8deb8d97181f0ae13da90b90d5b205.tar.gz
xamarin-forms-d4682208ed8deb8d97181f0ae13da90b90d5b205.tar.bz2
Merge "Add Implementation of VisibleRegion" into tizen
-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 cf7ddf7..752b021 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);
}