コード例 #1
0
 private static void CreateLocalTiles(SourceConfiguration tileSource)
 {
     // Create files Z\X\Y structure
     for (var z = tileSource.MinZoom.Value; z <= tileSource.MaxZoom.Value; z++)
     {
         Directory.CreateDirectory(Path.Join(LocalFilesPath, z.ToString(CultureInfo.InvariantCulture)));
         for (var x = 0; x < 1 << z; x++)
         {
             var zxPath = Path.Join(LocalFilesPath, z.ToString(CultureInfo.InvariantCulture), x.ToString(CultureInfo.InvariantCulture));
             Directory.CreateDirectory(zxPath);
             for (var y = 0; y < 1 << z; y++)
             {
                 var tilePath = Path.Join(zxPath, y.ToString(CultureInfo.InvariantCulture)) + "." + tileSource.Format;
                 var tile     = new TileDataStub(x, y, z);
                 File.WriteAllBytes(tilePath, tile.ToByteArray());
             }
         }
     }
 }
コード例 #2
0
        private static void PrepareTestData()
        {
            if (!Directory.Exists(TestDataPath))
            {
                Directory.CreateDirectory(TestDataPath);
            }

            // Create config file
            var tileSources = new[]
            {
                new TileSourceConfiguration
                {
                    Type     = TileSourceConfiguration.TypeMBTiles,
                    Id       = "source1",
                    Location = Mbtiles1FilePath,
                    MinZoom  = 0,
                    MaxZoom  = 18,
                },
                new TileSourceConfiguration
                {
                    Type     = TileSourceConfiguration.TypeMBTiles,
                    Id       = "source2",
                    Title    = "Tile Source 2",
                    Location = Mbtiles2FilePath,
                },
                new TileSourceConfiguration
                {
                    Type     = TileSourceConfiguration.TypeLocalFiles,
                    Id       = "source3",
                    Title    = "Tile Source 3",
                    Location = LocalFilesPath + "\\{z}\\{x}\\{y}.png",
                    MinZoom  = 0,
                    MaxZoom  = 2,
                    Format   = "png",
                    Tms      = false,
                },
                new TileSourceConfiguration // HTTP proxy to source1
                {
                    Type     = TileSourceConfiguration.TypeXyz,
                    Id       = "source4",
                    Title    = "Tile Source 4",
                    Location = BaseUrl + "/xyz/source1/{z}/{x}/{y}.png",
                    Format   = "png",
                    MinZoom  = 0,
                    MaxZoom  = 2,
                },
            };

            File.WriteAllText(SettingsFilePath, JsonSerializer.Serialize(new { TileSources = tileSources }));

            // TODO: more tiles into database
            // Create and fill MBTiles databases
            var db1 = MBT.Repository.CreateEmptyDatabase(Mbtiles1FilePath);

            db1.AddMetadataItem(new MBT.MetadataItem(MBT.MetadataItem.KeyName, "World Countries"));
            db1.AddMetadataItem(new MBT.MetadataItem(MBT.MetadataItem.KeyFormat, "png"));
            db1.AddTile(0, 0, 0, new TileDataStub(0, 0, 0).ToByteArray());

            var db2 = MBT.Repository.CreateEmptyDatabase(Mbtiles2FilePath);

            db2.AddMetadataItem(new MBT.MetadataItem(MBT.MetadataItem.KeyName, "Satellite Imagery"));
            db2.AddMetadataItem(new MBT.MetadataItem(MBT.MetadataItem.KeyFormat, "jpg"));
            db2.AddMetadataItem(new MBT.MetadataItem(MBT.MetadataItem.KeyMinZoom, "0"));
            db2.AddMetadataItem(new MBT.MetadataItem(MBT.MetadataItem.KeyMaxZoom, "5"));
            db2.AddTile(0, 0, 0, new TileDataStub(0, 0, 0).ToByteArray());

            // Create files Z\X\Y structure
            for (var z = tileSources[2].MinZoom.Value; z <= tileSources[2].MaxZoom.Value; z++)
            {
                Directory.CreateDirectory(Path.Join(LocalFilesPath, z.ToString(CultureInfo.InvariantCulture)));
                for (var x = 0; x < 1 << z; x++)
                {
                    var zxPath = Path.Join(LocalFilesPath, z.ToString(CultureInfo.InvariantCulture), x.ToString(CultureInfo.InvariantCulture));
                    Directory.CreateDirectory(zxPath);
                    for (var y = 0; y < 1 << z; y++)
                    {
                        var tilePath = Path.Join(zxPath, y.ToString(CultureInfo.InvariantCulture)) + "." + tileSources[2].Format;
                        var tile     = new TileDataStub(x, y, z);
                        File.WriteAllBytes(tilePath, tile.ToByteArray());
                    }
                }
            }
        }