Beispiel #1
0
        public MBTilesTileSource(TileSetConfiguration configuration)
        {
            this.configuration = configuration;
            this.contentType   = Utils.GetContentType(this.configuration.Format);

            if (this.configuration.UseCoordinatesCache)
            {
                var filePath = GetLocalFilePath(this.configuration.Source);
                if (File.Exists(filePath))
                {
                    // TODO: not the best placement in constructor
                    Task.Run(() =>
                    {
                        var connectionString = GetMBTilesConnectionString(this.configuration.Source);
                        var db = new MBTiles.MBTilesStorage(connectionString);
                        db.ReadTileCoordinates(this.tileKeys).Wait(); // TODO: check presence of rowid
                        this.isTileKeysReady = true;
                    });
                }
            }
        }
Beispiel #2
0
        async Task <byte[]> ITileSource.GetTileAsync(int x, int y, int z)
        {
            if (!this.configuration.Tms)
            {
                y = Utils.FromTmsY(y, z);
            }

            var connectionString = GetMBTilesConnectionString(this.configuration.Source);
            var db = new MBTiles.MBTilesStorage(connectionString);

            // TODO: if database contents were changed, coordinates cache should be invalidated

            if (this.configuration.UseCoordinatesCache)
            {
                var key = MBTiles.MBTilesStorage.CreateTileCoordinatesKey(z, x, y);
                if (tileKeys.ContainsKey(key))
                {
                    // Get rowid from cache, read table record by rowid (very fast, compared to selecting by three columns)
                    return(await db.GetTileAsync(tileKeys[key]));
                }
                else
                {
                    if (this.isTileKeysReady)
                    {
                        // Assuming there is no tile in database, if it not exists in cache
                        return(null);
                    }
                    else
                    {
                        // While cache is not ready, allow simple database read
                        return(await db.GetTileAsync(x, y, z));
                    }
                }
            }
            else
            {
                return(await db.GetTileAsync(x, y, z));
            }
        }