Ejemplo n.º 1
0
        /// <summary>
        /// Sets the TargetZoomLevel and TargetCenter properties so that the specified bounding box
        /// fits into the current view. The TargetHeading property is set to zero.
        /// </summary>
        public void ZoomToBounds(BoundingBox boundingBox)
        {
            var rect   = MapProjection.BoundingBoxToRect(boundingBox);
            var center = new Point(rect.X + rect.Width / 2d, rect.Y + rect.Height / 2d);
            var scale  = Math.Min(RenderSize.Width / rect.Width, RenderSize.Height / rect.Height);

            TargetZoomLevel = ViewTransform.ScaleToZoomLevel(scale);
            TargetCenter    = MapProjection.MapToLocation(center);
            TargetHeading   = 0d;
        }
Ejemplo n.º 2
0
        /// <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)
        {
            var rect   = MapProjection.BoundingBoxToRect(boundingBox);
            var center = new Point(rect.X + rect.Width / 2d, rect.Y + rect.Height / 2d);
            var scale  = Math.Min(RenderSize.Width / rect.Width, RenderSize.Height / rect.Height)
                         * MapProjection.TrueScale / MapProjection.PixelPerDegree;

            TargetZoomLevel = Math.Log(scale, 2d);
            TargetCenter    = MapProjection.PointToLocation(center);
            TargetHeading   = 0d;
        }
Ejemplo n.º 3
0
        /// <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;
            }
        }
Ejemplo n.º 4
0
        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);
        }