public VectorMbTilesProvider(string path, string stylePath, string cachePath) { this.cachePath = cachePath; style = new Style(stylePath); style.FontFallbackDirectory = @"styles/fonts/"; provider = new VectorTileRenderer.Sources.MbTilesSource(path); style.SetSourceProvider(0, provider); }
public VectorMbTilesProvider(string path, string stylePath, string cachePath) { style = new Style(stylePath); style.FontDirectory = @"styles/fonts/"; this.cachePath = cachePath; provider = new VectorTileRenderer.Sources.MbTilesSource(path); style.SetSourceProvider(0, provider); this.BypassCache = true; }
public MainWindow() { InitializeComponent(); // first, we extract necessary pbf tiles from mbtiles db var coords = gmt.LatLonToTile(47.371143, 8.543924, 14); var tileSource = new VectorTileRenderer.Sources.MbTilesSource(mainDir + @"tiles/zurich.mbtiles"); tileSource.ExtractTile(coords.X, coords.Y, 14, mainDir + @"tiles/zurich.pbf.gz"); coords = gmt.LatLonToTile(33.693189, 73.061415, 11); tileSource = new VectorTileRenderer.Sources.MbTilesSource(mainDir + @"tiles/islamabad.mbtiles"); tileSource.ExtractTile(coords.X, coords.Y, 11, mainDir + @"tiles/islamabad.pbf.gz"); }
async void showMbTiles(string path, string stylePath, int minX, int minY, int maxX, int maxY, int zoom, double size = 512, double scale = 1) { var watch = System.Diagnostics.Stopwatch.StartNew(); // load style and font var style = new VectorTileRenderer.Style(stylePath); style.FontDirectory = mainDir + @"styles/fonts/"; // set pbf as tile provider var provider = new VectorTileRenderer.Sources.MbTilesSource(path); style.SetSourceProvider(0, provider); BitmapSource[,] bitmapSources = new BitmapSource[maxX - minX + 1, maxY - minY + 1]; // loop through tiles and render them Parallel.For(minX, maxX + 1, (int x) => { Parallel.For(minY, maxY + 1, async(int y) => { var canvas = new SkiaCanvas(); var bitmapR = await Renderer.Render(style, canvas, x, y, zoom, size, size, scale); if (bitmapR == null) { } bitmapSources[x - minX, maxY - y] = bitmapR; }); }); // merge the tiles and show it var bitmap = mergeBitmaps(bitmapSources); demoImage.Source = bitmap; scrollViewer.Background = new SolidColorBrush(style.GetBackgroundColor(zoom)); watch.Stop(); var elapsedMs = watch.ElapsedMilliseconds; Console.WriteLine(elapsedMs + "ms time"); }