Ejemplo n.º 1
0
        private bool PlaceIfArea(UIElement element)
        {
            var elementExtent = GeoArea.Intersection(Geo.GetArea(element), Projection.World);
            var isArea        = !elementExtent.IsEmpty;

            if (isArea)
            {
                var destRect = Projection.ToRect(elementExtent, VisualExtent);
                element.Arrange(destRect);
            }

            return(isArea);
        }
Ejemplo n.º 2
0
Archivo: Map.cs Proyecto: hnjm/Discarta
        private async void VisualExtentValuesChanged(object sender, PropertyChangedEventArgs e)
        {
            if (e.PropertyName == string.Empty || e.PropertyName == nameof(Extent.ZoomLevel))
            {
                PanelExtent = new Rect(Projection.FullMapSizeFor(Extent.ZoomLevel));

                // Measurements only change when the zoom level changes.  Screen size affects the visual port,
                // and GeoArea affects the geographic area under the map
                InvalidateMeasure();
            }

            ScrollOwner?.InvalidateScrollInfo();
            InvalidateArrange();

            foreach (var child in InternalChildren.OfType <UIElement>().Where(c => !(c is MapLayer)).ToList())
            {
                Children.Remove(child);
            }

            var tiles = tileManager.GetTilesForArea(Projection, Extent).ToList();

            while (tiles.Any())
            {
                await Task.WhenAny(tiles);

                foreach (var finishedDrawing in tiles.Where(t => t.IsCompleted).ToList())
                {
                    var tileContent = await finishedDrawing;
                    var visual      = new Rectangle();
                    Geo.SetArea(visual, Geo.GetArea(tileContent));

                    var brush = new DrawingBrush
                    {
                        Drawing = tileContent,
                        Stretch = Stretch.Fill
                    };

                    brush.Freeze();
                    visual.Fill = brush;
                    SetZIndex(visual, int.MaxValue);

                    Children.Add(visual);
                    tiles.Remove(finishedDrawing);
                }
            }
        }
Ejemplo n.º 3
0
Archivo: Map.cs Proyecto: hnjm/Discarta
        protected override Size ArrangeOverride(Size finalSize)
        {
            if (loading || Projection == null || Extent == null || Extent.Area.IsEmpty)
            {
                return(finalSize);
            }

            var offset = PanelExtent.TopLeft - ViewPort.TopLeft;

            if (ViewPort.Width > PanelExtent.Width)
            {
                // center horizontally if the viewport is larger than the map
                offset.X = (ViewPort.Width - PanelExtent.Width) / 2;
            }

            if (ViewPort.Height > PanelExtent.Height)
            {
                // center vertically if the viewport is larger than the map
                offset.Y = (ViewPort.Height - PanelExtent.Height) / 2;
            }

            foreach (UIElement child  in InternalChildren)
            {
                var placement = PanelExtent;

                if (!(child is MapLayer))
                {
                    placement = Projection.ToRect(Geo.GetArea(child), Extent);
                }

                placement.X += offset.X;
                placement.Y += offset.Y;

                child.Arrange(placement);
            }

            return(ViewPort.Size);
        }
Ejemplo n.º 4
0
        private bool PlaceIfPoint(UIElement element)
        {
            var elementLocation = Geo.GetLocation(element);
            var isPoint         = !elementLocation.IsEmpty;

            if (isPoint)
            {
                var hotSpotPoint = Projection.ToPoint(elementLocation, VisualExtent);
                var pointSize    = element.DesiredSize;

                // Until I add HotSpot support, center over the point
                var destRect = new Rect(hotSpotPoint, pointSize);
                var hotSpotX = Geo.GetHotSpotX(element);
                var hotSpotY = Geo.GetHotSpotY(element);

                destRect.X -= hotSpotX.Apply(destRect.Width);
                destRect.Y -= hotSpotY.Apply(destRect.Height);

                element.Arrange(destRect);
            }

            return(isPoint);
        }