コード例 #1
0
ファイル: MapLayer.cs プロジェクト: bloritsch/Discarta
        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);
        }
コード例 #2
0
ファイル: Map.cs プロジェクト: 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);
                }
            }
        }
コード例 #3
0
ファイル: Map.cs プロジェクト: 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);
        }