public static void ZoomTo(this DevExpress.XtraMap.Services.IZoomToRegionService zoomService, IEnumerable <Address> addresses, double margin = 0.25) { GeoPoint ptA = null; GeoPoint ptB = null; foreach (var address in addresses) { if (ptA == null) { ptA = address.ToGeoPoint(); ptB = address.ToGeoPoint(); continue; } GeoPoint pt = address.ToGeoPoint(); if (pt == null || object.Equals(pt, new GeoPoint(0, 0))) { continue; } ptA.Latitude = Math.Min(ptA.Latitude, pt.Latitude); ptA.Longitude = Math.Min(ptA.Longitude, pt.Longitude); ptB.Latitude = Math.Max(ptB.Latitude, pt.Latitude); ptB.Longitude = Math.Max(ptB.Longitude, pt.Longitude); } ZoomCore(zoomService, ptA, ptB, margin); }
static void ZoomCore(DevExpress.XtraMap.Services.IZoomToRegionService zoomService, GeoPoint ptA, GeoPoint ptB, double margin) { if (ptA == null || ptB == null || zoomService == null) { return; } double latPadding = CalculatePadding(ptB.Latitude - ptA.Latitude, margin); double longPadding = CalculatePadding(ptB.Longitude - ptA.Longitude, margin); zoomService.ZoomToRegion( new GeoPoint(ptA.Latitude - latPadding, ptA.Longitude - longPadding), new GeoPoint(ptB.Latitude + latPadding, ptB.Longitude + longPadding), new GeoPoint(0.5 * (ptA.Latitude + ptB.Latitude), 0.5 * (ptA.Longitude + ptB.Longitude))); }
public static void ZoomTo(this DevExpress.XtraMap.Services.IZoomToRegionService zoomService, Address pointA, Address pointB, double margin = 0.2) { ZoomCore(zoomService, pointA.ToGeoPoint(), pointB.ToGeoPoint(), margin); }