/// <summary> /// Calculates the scale at the center of a polygon, at a given pixel size /// </summary> /// <remarks> /// A pixel is a device independent logical pixel - ie 1/96 inches. /// </remarks> /// <param name="visibleArea">The area which center the scale will be calculated for.</param> /// <param name="unitsPerPixel">The size of a device indepedent pixel in the units of the spatial reference</param> /// <returns>The MapScale for the center of the view</returns> public static double CalculateScale(Esri.ArcGISRuntime.Geometry.Polygon visibleArea, double unitsPerPixel) { if (visibleArea == null) { return(double.NaN); } if (visibleArea.SpatialReference == null) { return(double.NaN); } if (double.IsNaN(unitsPerPixel) || unitsPerPixel <= 0) { return(double.NaN); } var center = visibleArea.Extent.GetCenter(); var centerOnePixelOver = new Geometry.MapPoint(center.X + unitsPerPixel, center.Y, center.SpatialReference); // Calculate the geodedetic distance between two points one 'pixel' apart var result = Geometry.GeometryEngine.DistanceGeodetic(center, centerOnePixelOver, Geometry.LinearUnits.Inches, Geometry.AngularUnits.Degrees, Geometry.GeodeticCurveType.Geodesic); double distanceInInches = result.Distance; return(distanceInInches * 96); }
/// <summary> /// Calculates the scale at the center of a polygon, at a given pixel size. /// </summary> /// <remarks> /// A pixel is a device independent logical pixel - ie 1/96 inches. /// </remarks> /// <param name="visibleArea">The area which center the scale will be calculated for.</param> /// <param name="unitsPerPixel">The size of a device indepedent pixel in the units of the spatial reference.</param> /// <returns>The MapScale for the center of the view.</returns> public static double CalculateScale(Esri.ArcGISRuntime.Geometry.Polygon?visibleArea, double unitsPerPixel) { if (visibleArea == null) { return(double.NaN); } if (visibleArea.SpatialReference == null) { return(double.NaN); } if (double.IsNaN(unitsPerPixel) || unitsPerPixel <= 0) { return(double.NaN); } #if __ANDROID__ // Need to convert the value to DIPs unitsPerPixel /= Android.Util.TypedValue.ApplyDimension(Android.Util.ComplexUnitType.Dip, 1, Internal.ViewExtensions.GetDisplayMetrics()); #endif var center = visibleArea.Extent.GetCenter(); var centerOnePixelOver = new Geometry.MapPoint(center.X + unitsPerPixel, center.Y, center.SpatialReference); // Calculate the geodedetic distance between two points one 'pixel' apart var result = Geometry.GeometryEngine.DistanceGeodetic(center, centerOnePixelOver, Geometry.LinearUnits.Inches, Geometry.AngularUnits.Degrees, Geometry.GeodeticCurveType.Geodesic); double distanceInInches = result !.Distance; return(distanceInInches * 96); }