Пример #1
0
        public Collection <TileInfo> GetTiles(BoundingBox boundingBox)
        {
            var tileWorldUnits = ZoomLevel.Resolution * TileWidth;

            Collection <TileInfo> tiles = new Collection <TileInfo>();

            var tileRange = new TileRange(-1, -1);

            if (TileSchema.IsYAxisReversed)
            {
                var firstCol = (int)Math.Floor((boundingBox.MinX - TileSchema.MaxExtent.MinX) / tileWorldUnits);
                var firstRow = (int)Math.Floor((-boundingBox.MaxY + TileSchema.MaxExtent.MaxY) / tileWorldUnits);
                var lastCol  = (int)Math.Ceiling((boundingBox.MaxX - TileSchema.MaxExtent.MinX) / tileWorldUnits);
                var lastRow  = (int)Math.Ceiling((-boundingBox.MinY + TileSchema.MaxExtent.MaxY) / tileWorldUnits);

                tileRange = new TileRange(firstCol, firstRow, lastCol - firstCol, lastRow - firstRow);
            }
            else
            {
                var firstCol = (int)Math.Floor((boundingBox.MinX - TileSchema.MaxExtent.MinX) / tileWorldUnits);
                var firstRow = (int)Math.Floor((boundingBox.MinY - TileSchema.MaxExtent.MaxY) / tileWorldUnits);
                var lastCol  = (int)Math.Ceiling((boundingBox.MaxX - TileSchema.MaxExtent.MinX) / tileWorldUnits);
                var lastRow  = (int)Math.Ceiling((boundingBox.MaxY - TileSchema.MaxExtent.MaxY) / tileWorldUnits);

                tileRange = new TileRange(firstCol, firstRow, lastCol - firstCol, lastRow - firstRow);
            }

            for (var x = tileRange.StartColumn; x < tileRange.StartColumn + tileRange.NumberOfColumns; x++)
            {
                for (var y = tileRange.StartRow; y < tileRange.StartRow + tileRange.NumberOfRows; y++)
                {
                    tiles.Add(new TileInfo(x, y, ZoomLevel.Resolution, TileSchema));
                }
            }

            return(tiles);
        }