private void DrawCylindricalGraticule(DrawingContext drawingContext, double lineDistance, string labelFormat) { var boundingBox = ParentMap.ViewRectToBoundingBox(new Rect(ParentMap.RenderSize)); var latLabelStart = Math.Ceiling(boundingBox.South / lineDistance) * lineDistance; var lonLabelStart = Math.Ceiling(boundingBox.West / lineDistance) * lineDistance; var latLabels = new List <Label>((int)((boundingBox.North - latLabelStart) / lineDistance) + 1); var lonLabels = new List <Label>((int)((boundingBox.East - lonLabelStart) / lineDistance) + 1); var typeface = new Typeface(FontFamily, FontStyle, FontWeight, FontStretch); var pixelsPerDip = VisualTreeHelper.GetDpi(this).PixelsPerDip; var pen = CreatePen(); for (var lat = latLabelStart; lat <= boundingBox.North; lat += lineDistance) { latLabels.Add(new Label(lat, new FormattedText( GetLabelText(lat, labelFormat, "NS"), CultureInfo.InvariantCulture, FlowDirection.LeftToRight, typeface, FontSize, Foreground, pixelsPerDip))); drawingContext.DrawLine(pen, ParentMap.LocationToView(new Location(lat, boundingBox.West)), ParentMap.LocationToView(new Location(lat, boundingBox.East))); } for (var lon = lonLabelStart; lon <= boundingBox.East; lon += lineDistance) { lonLabels.Add(new Label(lon, new FormattedText( GetLabelText(Location.NormalizeLongitude(lon), labelFormat, "EW"), CultureInfo.InvariantCulture, FlowDirection.LeftToRight, typeface, FontSize, Foreground, pixelsPerDip))); drawingContext.DrawLine(pen, ParentMap.LocationToView(new Location(boundingBox.South, lon)), ParentMap.LocationToView(new Location(boundingBox.North, lon))); } foreach (var latLabel in latLabels) { foreach (var lonLabel in lonLabels) { var position = ParentMap.LocationToView(new Location(latLabel.Position, lonLabel.Position)); drawingContext.PushTransform(new RotateTransform(ParentMap.ViewTransform.Rotation, position.X, position.Y)); drawingContext.DrawText(latLabel.Text, new Point(position.X + StrokeThickness / 2d + 2d, position.Y - StrokeThickness / 2d - latLabel.Text.Height)); drawingContext.DrawText(lonLabel.Text, new Point(position.X + StrokeThickness / 2d + 2d, position.Y + StrokeThickness / 2d)); drawingContext.Pop(); } } }
private void UpdateBoundingBox() { var width = ParentMap.RenderSize.Width * RelativeImageSize; var height = ParentMap.RenderSize.Height * RelativeImageSize; var x = (ParentMap.RenderSize.Width - width) / 2d; var y = (ParentMap.RenderSize.Height - height) / 2d; var rect = new Rect(x, y, width, height); BoundingBox = ParentMap.ViewRectToBoundingBox(rect); if (BoundingBox != null) { if (!double.IsNaN(MinLatitude) && BoundingBox.South < MinLatitude) { BoundingBox.South = MinLatitude; } if (!double.IsNaN(MinLongitude) && BoundingBox.West < MinLongitude) { BoundingBox.West = MinLongitude; } if (!double.IsNaN(MaxLatitude) && BoundingBox.North > MaxLatitude) { BoundingBox.North = MaxLatitude; } if (!double.IsNaN(MaxLongitude) && BoundingBox.East > MaxLongitude) { BoundingBox.East = MaxLongitude; } if (!double.IsNaN(MaxBoundingBoxWidth) && BoundingBox.Width > MaxBoundingBoxWidth) { var d = (BoundingBox.Width - MaxBoundingBoxWidth) / 2d; BoundingBox.West += d; BoundingBox.East -= d; } } }