Esempio n. 1
0
        public HashSet <UnwrappedTileId> GetWithWebMerc(Vector2dBounds bounds, int zoom)
        {
            _tiles.Clear();
            _canonicalTiles.Clear();

            if (bounds.IsEmpty())
            {
                return(_tiles);
            }

            //stay within WebMerc bounds
            Vector2d swWebMerc = new Vector2d(Math.Max(bounds.SouthWest.x, -Utils.Constants.WebMercMax), Math.Max(bounds.SouthWest.y, -Utils.Constants.WebMercMax));
            Vector2d neWebMerc = new Vector2d(Math.Min(bounds.NorthEast.x, Utils.Constants.WebMercMax), Math.Min(bounds.NorthEast.y, Utils.Constants.WebMercMax));

            UnwrappedTileId swTile = WebMercatorToTileId(swWebMerc, zoom);
            UnwrappedTileId neTile = WebMercatorToTileId(neWebMerc, zoom);

            for (int x = swTile.X; x <= neTile.X; x++)
            {
                for (int y = neTile.Y; y <= swTile.Y; y++)
                {
                    UnwrappedTileId uwtid = new UnwrappedTileId(zoom, x, y);
                    //hack: currently too many tiles are created at lower zoom levels
                    //investigate formulas, this worked before
                    if (!_canonicalTiles.Contains(uwtid.Canonical))
                    {
                        _tiles.Add(uwtid);
                        _canonicalTiles.Add(uwtid.Canonical);
                    }
                }
            }

            return(_tiles);
        }
Esempio n. 2
0
        /// <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)(() =&gt;
        ///		{
        ///			// 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 IsEmpty()
        {
            var bounds1 = new Vector2dBounds(new Vector2d(10, 10), new Vector2d(0, 0));

            Assert.IsTrue(bounds1.IsEmpty());

            var bounds2 = new Vector2dBounds(new Vector2d(0, 0), new Vector2d(0, 0));

            Assert.IsFalse(bounds2.IsEmpty());

            var bounds3 = new Vector2dBounds(new Vector2d(0, 0), new Vector2d(10, 10));

            Assert.IsFalse(bounds3.IsEmpty());
        }
Esempio n. 4
0
        public static HashSet <UnwrappedTileId> GetWithWebMerc(Vector2dBounds bounds, int zoom)
        {
            HashSet <UnwrappedTileId> tiles          = new HashSet <UnwrappedTileId>();
            HashSet <CanonicalTileId> canonicalTiles = new HashSet <CanonicalTileId>();

            if (bounds.IsEmpty())
            {
                return(tiles);
            }

            //stay within WebMerc bounds
            Vector2d swWebMerc = new Vector2d(Math.Max(bounds.SouthWest.x, -Constants.WebMercMax), Math.Max(bounds.SouthWest.y, -Constants.WebMercMax));
            Vector2d neWebMerc = new Vector2d(Math.Min(bounds.NorthEast.x, Constants.WebMercMax), Math.Min(bounds.NorthEast.y, Constants.WebMercMax));

            //UnityEngine.Debug.LogFormat("swWebMerc:{0}/{1} neWebMerc:{2}/{3}", swWebMerc.x, swWebMerc.y, neWebMerc.x, neWebMerc.y);

            UnwrappedTileId swTile = WebMercatorToTileId(swWebMerc, zoom);
            UnwrappedTileId neTile = WebMercatorToTileId(neWebMerc, zoom);

            //UnityEngine.Debug.LogFormat("swTile:{0} neTile:{1}", swTile, neTile);

            for (int x = swTile.X; x <= neTile.X; x++)
            {
                for (int y = neTile.Y; y <= swTile.Y; y++)
                {
                    UnwrappedTileId uwtid = new UnwrappedTileId(zoom, x, y);
                    //hack: currently too many tiles are created at lower zoom levels
                    //investigate formulas, this worked before
                    if (!canonicalTiles.Contains(uwtid.Canonical))
                    {
                        //Debug.LogFormat("TileCover.GetWithWebMerc: {0}/{1}/{2}", zoom, x, y);
                        tiles.Add(uwtid);
                        canonicalTiles.Add(uwtid.Canonical);
                    }
                }
            }

            return(tiles);
        }