/// <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 { if (this.SurfaceWidth > 0 && _bufferFactor > 0) { float height = this.SurfaceHeight / _bufferFactor; float width = this.SurfaceWidth / _bufferFactor; var points = new PointF2D[controls.Count]; for (int idx = 0; idx < controls.Count; idx++) { points[idx] = new PointF2D(this.Map.Projection.ToPixel(controls[idx].Location)); } var view = this.CreateView(); var fittedView = view.Fit(points, percentage); var zoom = (float)this.Map.Projection.ToZoomLevel(fittedView.CalculateZoom( width, height)); var 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="controls"></param> /// <param name="percentage"></param> public void ZoomToControls(List<MapControl> controls, double percentage) { try { if (this.SurfaceWidth > 0 && _bufferFactor > 0) { float height = this.SurfaceHeight / _bufferFactor; float width = this.SurfaceWidth / _bufferFactor; var points = new PointF2D[controls.Count]; for (int idx = 0; idx < controls.Count; idx++) { points[idx] = new PointF2D(this.Map.Projection.ToPixel(controls[idx].Location)); } var view = this.CreateView(); var fittedView = view.Fit(points, percentage); var zoom = (float)this.Map.Projection.ToZoomLevel(fittedView.CalculateZoom( width, height)); var 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> /// Raises the layout event. /// </summary> /// <param name="changed">If set to <c>true</c> changed.</param> /// <param name="left">Left.</param> /// <param name="top">Top.</param> /// <param name="right">Right.</param> /// <param name="bottom">Bottom.</param> protected override void OnLayout(bool changed, int left, int top, int right, int bottom) { // execute suspended events. if (_latestZoomCall != null) { // there was a suspended call. var latestZoomCall = _latestZoomCall; _latestZoomCall = null; this.ZoomToControls( latestZoomCall.Controls, latestZoomCall.Percentage); } if (_onScreenBuffer == null) { this.TriggerRendering(); // force a rendering on the first layout-event. } }