/// <summary>Centers the map on the specified coordinates.</summary> /// <param name="latitude">The latitude cooridinate.</param> /// <param name="longitude">The longitude coordinates.</param> /// <param name="zoom">The zoom level for the map.</param> public void Center(double latitude, double longitude, int zoom) { this.BeginUpdate(); this.Zoom = zoom; var tilex = TileGenerator.GetTileX(longitude, this.Zoom); _offsetX.CenterOn(tilex); var tiley = TileGenerator.GetTileY(latitude, this.Zoom); _offsetY.CenterOn(tiley); Debug.WriteLine(String.Format("CenterZoom: ty={0} tx={1} z={2} lat={3} lon={4}", tilex, tiley, zoom, latitude, longitude)); this.EndUpdate(); }
/// <summary>Centers the map on the specified coordinates, calculating the required zoom level.</summary> /// <param name="latitude">The latitude cooridinate.</param> /// <param name="longitude">The longitude coordinates.</param> /// <param name="size">The minimum size that must be visible, centered on the coordinates.</param> public void Center(double latitude, double longitude, Size size) { double left = TileGenerator.GetTileX(longitude - (size.Width / 2.0), 0); double right = TileGenerator.GetTileX(longitude + (size.Width / 2.0), 0); double top = TileGenerator.GetTileY(latitude - (size.Height / 2.0), 0); double bottom = TileGenerator.GetTileY(latitude + (size.Height / 2.0), 0); double height = (top - bottom) * TileGenerator.TileSize; double width = (right - left) * TileGenerator.TileSize; int zoom = Math.Min(TileGenerator.GetZoom(this.ActualHeight / height), TileGenerator.GetZoom(this.ActualWidth / width)); // todo, hacer un combinador o algo asi. Debug.WriteLine(String.Format("CenterSize: aw={0} ah={1} l={2} r={3} t={4} b={5} h={6} w={7} z={8} lat={9} lon={10}", (int)this.ActualWidth, (int)this.ActualHeight, left, right, top, bottom, height, width, zoom, latitude, longitude)); this.Center(latitude, longitude, zoom); }
private void RepositionChildren() { if (LoadingQuadtree) { return; } foreach (UIElement element in this.Children) { double latitude = GetLatitude(element); double longitude = GetLongitude(element); if (latitude != double.PositiveInfinity && longitude != double.PositiveInfinity) { double x = (TileGenerator.GetTileX(longitude, this.Zoom) - _offsetX.Tile) * TileGenerator.TileSize; double y = (TileGenerator.GetTileY(latitude, this.Zoom) - _offsetY.Tile) * TileGenerator.TileSize; Canvas.SetLeft(element, x); Canvas.SetTop(element, y); element.RenderTransform = _translate; } else { Debug.WriteLine("Descartando Objeto por Type=" + element.GetType().ToString()); } } }