static async Task <int> RunXYZAsync(XYZSeederOptions options) { int ret = 0; try { options.Validate(); var xyz = new XYZTileService(options.UrlTemplate); var walker = new XYZTileWalker(options.MinX, options.MinY, options.MaxX, options.MaxY, options.MaxZoomLevel ?? XYZTileWalker.DEFAULT_MAX_ZOOM_LEVEL); if (options.SpecificZoomLevels != null) { walker.SetSpecificZoomLevels(options.SpecificZoomLevels); } var seederOptions = new TileSeederOptions(); seederOptions.MaxDegreeOfParallelism = options.MaxDegreeOfParallelism; seederOptions.ErrorLogger = ErrorLogger; var seeder = new TileSeeder(xyz, walker, seederOptions); var progress = new ConsoleProgress(); var stats = await seeder.RunAsync(progress); Console.WriteLine($"Rendered {stats.TilesRendered} tiles in {stats.Duration}"); } catch (Exception ex) { Console.WriteLine(ex.ToString()); ret = 1; } finally { if (options.Wait) { Console.WriteLine("Press any key to continue"); Console.Read(); } } return(ret); }
static int RunXYZ(XYZSeederOptions options) { int ret = 0; try { options.Validate(); var xyz = new XYZTileService(options.UrlTemplate); var walker = new XYZTileWalker(options.MinX, options.MinY, options.MaxX, options.MaxY); var seederOptions = new TileSeederOptions(); seederOptions.MaxDegreeOfParallelism = options.MaxDegreeOfParallelism; seederOptions.ErrorLogger = ErrorLogger; var seeder = new TileSeeder(xyz, walker, seederOptions); var progress = new ConsoleProgress(); var stats = seeder.Run(progress); Console.WriteLine($"Rendered {stats.TilesRendered} tiles in {stats.Duration}"); } catch (Exception ex) { Console.WriteLine(ex.ToString()); ret = 1; } finally { if (options.Wait) { Console.WriteLine("Press any key to continue"); Console.Read(); } } return(ret); }
public async Task <int> PublishAsync(IStaticMapPublishingOptions options) { _tileStart = DateTime.UtcNow; string imgDir = null; string utfDir = null; bool downloadedImageTiles = false; bool downloadedUTFGridTiles = false; if (!string.IsNullOrEmpty(options.ImageTileSet?.ResourceID)) { imgDir = GetImageTileSaveDirectory(options, o => o.ImageTileSet.ResourceID); Directory.CreateDirectory(imgDir); } if (!string.IsNullOrEmpty(options.UTFGridTileSet?.ResourceID)) { utfDir = GetImageTileSaveDirectory(options, o => o.UTFGridTileSet.ResourceID); Directory.CreateDirectory(utfDir); } if (!string.IsNullOrEmpty(options.ImageTileSet?.ResourceID)) { if (options.ImageTileSet.Mode == TileSetRefMode.Local && !options.ImageTileSet.SkipTileDownloading) { var tileSvc = new XYZTileService(BuildUrlTemplate(options, o => o.ImageTileSet.ResourceID, o => o.ImageTileSet.GroupName)); var walker = new XYZTileWalker(options.Bounds.MinX, options.Bounds.MinY, options.Bounds.MaxX, options.Bounds.MaxY); var seedOpts = new TileSeederOptions { MaxDegreeOfParallelism = options.MaxDegreeOfParallelism }; if (Directory.Exists(imgDir)) { seedOpts.SaveTile = (tr, stream) => { var tilePath = Path.Combine(imgDir, tr.GroupName, $"{tr.Scale}" /* z */, $"{tr.Row}" /* x */, $"{tr.Col}.png" /* y */); var parentDir = Path.GetDirectoryName(tilePath); if (!Directory.Exists(parentDir)) { Directory.CreateDirectory(parentDir); } using (var fw = File.OpenWrite(tilePath)) { Utility.CopyStream(stream, fw); } }; } else { seedOpts.SaveTile = null; } seedOpts.ErrorLogger = (tr, ex) => { }; var seeder = new TileSeeder(tileSvc, walker, seedOpts); seeder.RandomizeRequests = options.RandomizeRequests; await seeder.RunAsync(this); downloadedImageTiles = true; } else { await _stdout.WriteLineAsync($"Skipping downloading of tiles for: {options.ImageTileSet.ResourceID}"); } } var imageElapsed = DateTime.UtcNow - _tileStart; _tileStart = DateTime.UtcNow; if (!string.IsNullOrEmpty(options.UTFGridTileSet?.ResourceID)) { if (options.UTFGridTileSet.Mode == TileSetRefMode.Local && !options.UTFGridTileSet.SkipTileDownloading) { var tileSvc = new XYZTileService(BuildUrlTemplate(options, o => o.UTFGridTileSet.ResourceID, o => o.UTFGridTileSet.GroupName)); var walker = new XYZTileWalker(options.Bounds.MinX, options.Bounds.MinY, options.Bounds.MaxX, options.Bounds.MaxY); var seedOpts = new TileSeederOptions { MaxDegreeOfParallelism = options.MaxDegreeOfParallelism }; if (Directory.Exists(utfDir)) { seedOpts.SaveTile = (tr, stream) => { var tilePath = Path.Combine(utfDir, tr.GroupName, $"{tr.Scale}" /* z */, $"{tr.Row}" /* x */, $"{tr.Col}.json" /* y */); var parentDir = Path.GetDirectoryName(tilePath); if (!Directory.Exists(parentDir)) { Directory.CreateDirectory(parentDir); } using (var fw = File.OpenWrite(tilePath)) { Utility.CopyStream(stream, fw); } }; } else { seedOpts.SaveTile = null; } seedOpts.ErrorLogger = (tr, ex) => { }; var seeder = new TileSeeder(tileSvc, walker, seedOpts); seeder.RandomizeRequests = options.RandomizeRequests; await seeder.RunAsync(this); downloadedUTFGridTiles = true; } else { await _stdout.WriteLineAsync($"Skipping downloading of tiles for: {options.UTFGridTileSet.ResourceID}"); } } var utfElapsed = DateTime.UtcNow - _tileStart; if (downloadedImageTiles) { await _stdout.WriteLineAsync($"Image tiles downloaded in {(int)imageElapsed.TotalSeconds}s"); } if (downloadedUTFGridTiles) { await _stdout.WriteLineAsync($"UTFGrid tiles downloaded in {(int)utfElapsed.TotalSeconds}s"); } return(0); }