private ImageSource GetImage(MapProjection projection, IEnumerable <IMapDrawingItem> items) { var scale = ParentMap.ViewTransform.Scale; var rotation = ParentMap.ViewTransform.Rotation; var mapRect = projection.BoundingBoxToRect(BoundingBox); var imageRect = new Rect(0, 0, scale * mapRect.Width, scale * mapRect.Height); var drawings = new DrawingGroup(); foreach (var item in items) { var positions = item.Locations.Select(l => projection.LocationToMap(l)).ToList(); if (positions.Any(p => mapRect.Contains(p))) { for (int i = 0; i < positions.Count; i++) { positions[i] = new Point(scale * (positions[i].X - mapRect.X), imageRect.Height - scale * (positions[i].Y - mapRect.Y)); } drawings.Children.Add(item.GetDrawing(positions, scale, rotation)); } } var drawingBrush = new DrawingBrush { Drawing = drawings, ViewboxUnits = BrushMappingMode.Absolute, Viewbox = imageRect, }; var drawing = new GeometryDrawing { Geometry = new RectangleGeometry(imageRect), Brush = drawingBrush }; var image = new DrawingImage(drawing); image.Freeze(); return(image); }
/// <summary> /// Transforms a Location in geographic coordinates to a Point in view coordinates. /// </summary> public Point LocationToView(Location location) { return(ViewTransform.MapToView(MapProjection.LocationToMap(location))); }