/// <summary> Get a tile cover for the specified bounds and zoom. </summary> /// <param name="bounds"> Geographic bounding box.</param> /// <param name="zoom"> Zoom level. </param> /// <returns> The tile cover set. </returns> /// <example> /// Build a map of Colorado using TileCover: /// <code> /// var sw = new Vector2d(36.997749, -109.0524961); /// var ne = new Vector2d(41.0002612, -102.0609668); /// var coloradoBounds = new Vector2dBounds(sw, ne); /// var tileCover = TileCover.Get(coloradoBounds, 8); /// Console.Write("Tiles Needed: " + tileCover.Count); /// foreach (var id in tileCover) /// { /// var tile = new RasterTile(); /// var parameters = new Tile.Parameters(); /// parameters.Id = id; /// parameters.Fs = MapboxAccess.Instance; /// parameters.MapId = "mapbox://styles/mapbox/outdoors-v10"; /// tile.Initialize(parameters, (Action)(() => /// { /// // Place tiles and load textures. /// })); /// } /// </code> /// </example> public static HashSet <CanonicalTileId> Get(Vector2dBounds bounds, int zoom) { var tiles = new HashSet <CanonicalTileId>(); if (bounds.IsEmpty() || bounds.South > Constants.LatitudeMax || bounds.North < -Constants.LatitudeMax) { return(tiles); } var hull = Vector2dBounds.FromCoordinates( new Vector2d(Math.Max(bounds.South, -Constants.LatitudeMax), bounds.West), new Vector2d(Math.Min(bounds.North, Constants.LatitudeMax), bounds.East)); var sw = CoordinateToTileId(hull.SouthWest, zoom); var ne = CoordinateToTileId(hull.NorthEast, zoom); // Scanlines. for (var x = sw.X; x <= ne.X; ++x) { for (var y = ne.Y; y <= sw.Y; ++y) { tiles.Add(new UnwrappedTileId(zoom, x, y).Canonical); } } return(tiles); }
public void Hull() { var bounds1 = new Vector2dBounds(new Vector2d(-10, -10), new Vector2d(10, 10)); var bounds2 = Vector2dBounds.FromCoordinates(new Vector2d(10, 10), new Vector2d(-10, -10)); Assert.AreEqual(bounds1.South, bounds2.South); Assert.AreEqual(bounds1.West, bounds2.West); Assert.AreEqual(bounds1.North, bounds2.North); Assert.AreEqual(bounds1.East, bounds2.East); }