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; }
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); }
public Point CoordinateToPixels(WorldCoordinate coord) { int x, y; VirtualEarthTileSystem.LatLongToPixelXY(coord.Latitude, coord.Longitude, MapSize, out x, out y); return new Point(x, y); }
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; } }
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); }
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); }
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; }
public void LookAt(WorldCoordinate location) { ViewLatitude = location.Latitude; ViewLongitude = location.Longitude; }
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; }