/// <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(ActualHeight / height), _tileGenerator.GetZoom(ActualWidth / width)); Center(latitude, longitude, zoom); }
/// <summary> /// Updates the starting tile index based on the zoom level. /// </summary> /// <param name="zoom">The zoom level.</param> /// <param name="offset">The distance from the edge to keep the same when changing zoom.</param> public void ChangeZoom(int zoom, double offset) { int currentZoom = _tileGenerator.GetZoom(_mapSize / TileGenerator.TileSize); if (currentZoom != zoom) { _animating = false; double scale = Math.Pow(2, zoom - currentZoom); // 2^delta double location = ((Pixels + offset) * scale) - offset; // Bias new location on the offset _mapSize = _tileGenerator.GetSize(zoom); _maximumTile = (int)((_mapSize - _size) / TileGenerator.TileSize); Translate(Pixels - location); } }