using System; using ThinkGeo.MapSuite.AndroidEdition; using ThinkGeo.MapSuite.Core; namespace ZoomToTest { public static class Extensions { public static void ZoomTo(this MapView mapView, PointShape center, double scale) { double mapWidth = mapView.Width; double mapHeight = mapView.Height; if (Double.IsNaN(mapWidth) || Double.IsNaN(mapHeight)) { return; } double resolution = GetResolutionFromScale(scale, mapView.MapUnit); double widthInDegree = mapWidth * resolution; double heightInDegree = mapHeight * resolution; double left = center.X - widthInDegree * .5; double right = center.X + widthInDegree * .5; double top = center.Y + heightInDegree * .5; double bottom = center.Y - heightInDegree * .5; mapView.ZoomTo(new RectangleShape(left, top, right, bottom)); } #region private private const int dotsPerInch = 96; private const double feet = 12.0; private const double meter = 39.3701; private const double decimalDegree = 4374754; private static double GetResolutionFromScale(double scale, GeographyUnit unit) { return scale / (GetInchesByUnit(unit) * dotsPerInch); } private static double GetInchesByUnit(GeographyUnit unit) { switch (unit) { case GeographyUnit.Feet: return feet; case GeographyUnit.Meter: return meter; case GeographyUnit.DecimalDegree: return decimalDegree; default: return double.NaN; } } #endregion } }