/// <summary> /// Zooms to the given list of markers. /// </summary> /// <param name="markers"></param> /// <param name="percentage"></param> public void ZoomToMarkers(List <MapMarker> markers, double percentage) { float height = this.SurfaceHeight; float width = this.SurfaceWidth; if (width > 0) { PointF2D[] points = new PointF2D[markers.Count]; for (int idx = 0; idx < markers.Count; idx++) { points [idx] = new PointF2D(this.Map.Projection.ToPixel(markers [idx].Location)); } View2D view = this.CreateView(); View2D fittedView = view.Fit(points, percentage); float zoom = (float)this.Map.Projection.ToZoomLevel(fittedView.CalculateZoom( width, height)); GeoCoordinate center = this.Map.Projection.ToGeoCoordinates( fittedView.Center [0], fittedView.Center [1]); this.SetMapView(center, this.MapTilt, zoom); } else { _latestZoomCall = new MapViewMarkerZoomEvent() { Markers = markers, Percentage = percentage }; } }
/// <summary> /// Zoom to the given makers list. /// </summary> /// <param name="marker"></param> public void ZoomToMarkers(List <MapMarker> markers, double percentage) { // float height = _rect.Height; // float width = _rect.Width; float width = this.Frame.Width; float height = this.Frame.Height; RectangleF rect = this.Frame; if (width > 0) { PointF2D[] points = new PointF2D[markers.Count]; for (int idx = 0; idx < markers.Count; idx++) { points[idx] = new PointF2D(this.Map.Projection.ToPixel(markers[idx].Location)); } View2D view = this.CreateView(rect); // View2D view = this.CreateView(this.Frame); View2D fittedView = view.Fit(points, percentage); float zoom = (float)this.Map.Projection.ToZoomLevel(fittedView.CalculateZoom( width, height)); GeoCoordinate center = this.Map.Projection.ToGeoCoordinates( fittedView.Center[0], fittedView.Center[1]); _mapCenter = center; this.MapZoom = zoom; this.Change(false); } }
/// <summary> /// Zooms to the given list of markers. /// </summary> /// <param name="controls"></param> /// <param name="percentage"></param> public void ZoomToControls(List <MapControl> controls, double percentage) { try { float height = this.SurfaceHeight; float width = this.SurfaceWidth; if (width > 0) { PointF2D[] points = new PointF2D[controls.Count]; for (int idx = 0; idx < controls.Count; idx++) { points[idx] = new PointF2D(this.Map.Projection.ToPixel(controls[idx].Location)); } View2D view = this.CreateView(); View2D fittedView = view.Fit(points, percentage); float zoom = (float)this.Map.Projection.ToZoomLevel(fittedView.CalculateZoom( width, height)); GeoCoordinate center = this.Map.Projection.ToGeoCoordinates( fittedView.Center[0], fittedView.Center[1]); this.SetMapView(center, this.MapTilt, zoom); } else { _latestZoomCall = new MapViewControlZoomEvent() { Controls = controls, Percentage = percentage }; } } catch (Exception ex) { OsmSharp.Logging.Log.TraceEvent("MapViewSurface.ZoomToMarkers", TraceEventType.Critical, string.Format("An unhandled exception occured:{0}", ex.ToString())); } }
/// <summary> /// Zooms to the given list of markers. /// </summary> /// <param name="markers"></param> public void ZoomToMarkers(List <MapMarker> markers, double percentage) { float height = this.LayoutParameters.Height; float width = this.LayoutParameters.Width; if (width > 0) { PointF2D[] points = new PointF2D[markers.Count]; for (int idx = 0; idx < markers.Count; idx++) { points[idx] = markers[idx].Location; } View2D view = this.CreateView(); View2D fittedView = view.Fit(points); float zoom = (float)this.Map.Projection.ToZoomLevel(fittedView.CalculateZoom( width, height)); GeoCoordinate center = this.Map.Projection.ToGeoCoordinates( view.Center[0], view.Center[1]); (this as IMapView).SetMapView(center, this.MapTilt, zoom); } }