Ejemplo n.º 1
0
        protected override Size MeasureOverride(Size constraint)
        {
            Children.Clear();
            //VisualOperations.GetChildren(this).Clear();

            if (double.IsPositiveInfinity(constraint.Width)) { constraint.Width = 500; }
            if (double.IsPositiveInfinity(constraint.Height)) { constraint.Height = 500; }

            double optimalRows = constraint.Height / (double)VETSHelper.TileSizePixels;
            double optimalColumns = constraint.Width / (double)VETSHelper.TileSizePixels;

            int neededRows = (int)(Math.Ceiling(optimalRows + 1.0));
            int neededColumns = (int)(Math.Ceiling(optimalColumns + 1.0));

            WorldCoordinate upperLeft = new WorldCoordinate() { Latitude = CornerLatitude, Longitude = CornerLongitude };

            var pixels = Translator.CoordinateToPixels(upperLeft);
            int tileX, tileY;
            VirtualEarthTileSystem.PixelXYToTileXY((int)pixels.X, (int)pixels.Y, out tileX, out tileY);
            TileCoordinate tileStart = new TileCoordinate(tileX, tileY);

            Dictionary<TileCoordinate, UIElement> oldDisplays = displays;
            displays = new Dictionary<TileCoordinate, UIElement>();

            int maxTiles = VETSHelper.MaxTiles(ZoomLevel);

            for (int y = tileStart.Y; y < Math.Min(tileStart.Y + neededRows, maxTiles); y++)
            {
                for (int x = tileStart.X; x < Math.Min(tileStart.X + neededColumns, maxTiles); x++)
                {
                    TileCoordinate cur = new TileCoordinate(x, y);
                    UIElement child = null;
                    if (!oldDisplays.ContainsKey(cur))
                    {
                        child = CreateChild(cur);
                        if (child != null)
                        {
                            displays[cur] = child;
                        }
                    }
                    else
                    {
                        child = displays[cur] = oldDisplays[cur];
                    }

                    if (child != null)
                    {
                        Children.Add(child);
                        //VisualOperations.GetChildren(this).Add(child);
                        child.Measure(constraint);
                    }
                }
            }
            if (workQueue.Count > 0)
            {
                workQueue.Dequeue().BeginInvoke(null, null);
            }

            return constraint;
        }
Ejemplo n.º 2
0
 protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
 {
     Mouse.Capture(this, CaptureMode.SubTree);
     _upperLeftAtDown = new WorldCoordinate() { Latitude = CornerLatitude, Longitude = CornerLongitude };
     _viewAtDown = GetView();
     _mouseDownPixel = e.GetPosition(this);
     if (e.ClickCount == 2)
     {
         LookAt(ClientToWorld(_mouseDownPixel));
         ZoomLevel = Math.Min(ZoomLevel + 1, 18);
     }
     base.OnMouseLeftButtonDown(e);
 }
Ejemplo n.º 3
0
 public Point CoordinateToPixels(WorldCoordinate coord)
 {
     int x, y;
     VirtualEarthTileSystem.LatLongToPixelXY(coord.Latitude, coord.Longitude, MapSize, out x, out y);
     return new Point(x, y);
 }
Ejemplo n.º 4
0
        void SetViewOnCenter()
        {
            if (!double.IsNaN(ViewLatitude) && !double.IsNaN(ViewLongitude))
            {
                WorldCoordinate lookAt = new WorldCoordinate() { Latitude = ViewLatitude, Longitude = ViewLongitude };
                lookAt.Clamp();

                Point absoluteLoc = Translator.CoordinateToPixels(lookAt);
                Point newCorner = new Point(absoluteLoc.X - ActualWidth / 2, absoluteLoc.Y - ActualHeight / 2);

                WorldCoordinate desiredUpperLeft = Translator.PixelsToCoordinates(newCorner);

                CornerLatitude = desiredUpperLeft.Latitude;
                CornerLongitude = desiredUpperLeft.Longitude;
            }
        }
Ejemplo n.º 5
0
 protected Point WorldToClient(WorldCoordinate value)
 {
     Point virtualLocation = Translator.CoordinateToPixels(value);
     Point offset = Translator.CoordinateToPixels(_upperLeft);
     return new Point(virtualLocation.X - offset.X, virtualLocation.Y - offset.Y);
 }
Ejemplo n.º 6
0
 protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e)
 {
     DependencyProperty dp = e.Property;
     if (dp == ViewLatitudeProperty
         || dp == ViewLongitudeProperty)
     {
         SetViewOnCenter();
     }
     else if (dp == CornerLatitudeProperty
         || dp == CornerLongitudeProperty)
     {
         if (CornerLongitude < -180)
         {
             CornerLongitude = -180;
         }
         else if (CornerLongitude > 180)
         {
             CornerLongitude = 180;
         }
         if (CornerLatitude < -85)
         {
             CornerLatitude = -85;
         }
         else if (CornerLatitude > 85)
         {
             CornerLatitude = 85;
         }
         _upperLeft = new WorldCoordinate() { Longitude = CornerLongitude, Latitude = CornerLatitude };
         InvalidateArrange();
     }
     base.OnPropertyChanged(e);
 }
Ejemplo n.º 7
0
        protected override Size ArrangeOverride(Size finalSize)
        {
            foreach (UIElement child in InternalChildren)
            {
                var wc = new WorldCoordinate()
                {
                    Latitude = GetLatitude(child),
                    Longitude = GetLongitude(child)
                };

                Point client = WorldToClient(wc);
                child.Arrange(new Rect(client, child.DesiredSize));
            }
            return finalSize;
        }
Ejemplo n.º 8
0
 public void LookAt(WorldCoordinate location)
 {
     ViewLatitude = location.Latitude;
     ViewLongitude = location.Longitude;
 }
Ejemplo n.º 9
0
 public WorldCoordinate PixelsToCoordinates(Point pixel)
 {
     WorldCoordinate latLong = new WorldCoordinate();
     double lat, lon;
     VirtualEarthTileSystem.PixelXYToLatLong((int)pixel.X, (int)pixel.Y, MapSize, out lat, out lon);
     latLong.Latitude = lat;
     latLong.Longitude = lon;
     return latLong;
 }