/// <summary> /// Sets the TargetZoomLevel and TargetCenter properties so that the specified bounding box /// fits into the current viewport. The TargetHeading property is set to zero. /// </summary> public void ZoomToBounds(BoundingBox boundingBox) { if (boundingBox != null && boundingBox.HasValidBounds) { var rect = MapProjection.BoundingBoxToRect(boundingBox); var center = new Point(rect.X + rect.Width / 2d, rect.Y + rect.Height / 2d); var scale0 = 1d / MapProjection.GetViewportScale(0d); var lonScale = scale0 * RenderSize.Width / rect.Width; var latScale = scale0 * RenderSize.Height / rect.Height; var lonZoom = Math.Log(lonScale, 2d); var latZoom = Math.Log(latScale, 2d); TargetZoomLevel = Math.Min(lonZoom, latZoom); TargetCenter = MapProjection.PointToLocation(center); TargetHeading = 0d; } }