async void zurichMbTilesHybridStyle()
        {
            var watch = System.Diagnostics.Stopwatch.StartNew();

            // load style and font
            var style = new VectorTileRenderer.Style(mainDir + @"styles/hybrid-style.json");

            style.FontFallbackDirectory = mainDir + @"styles/fonts/";

            // set pbf as tile provider
            var vectorProvider = new VectorTileRenderer.Sources.PbfTileSource(mainDir + @"tiles/zurich.pbf.gz");

            style.SetSourceProvider(0, vectorProvider);

            // load raster source
            var rasterProvider = new VectorTileRenderer.Sources.RasterTileSource(mainDir + @"tiles/zurich.jpg");

            style.SetSourceProvider("satellite", rasterProvider);

            // render it on a skia canvas
            var canvas  = new SkiaCanvas();
            var bitmapR = await Renderer.Render(style, canvas, 0, 0, 14, 256, 256, 1);

            demoImage.Source = bitmapR;

            watch.Stop();
            var elapsedMs = watch.ElapsedMilliseconds;

            Console.WriteLine(elapsedMs + "ms time");
        }
        async void showPbf(string path, string stylePath, double zoom, double size = 512, double scale = 1)
        {
            var watch = System.Diagnostics.Stopwatch.StartNew();

            // load style and font
            var style = new VectorTileRenderer.Style(stylePath);

            style.FontFallbackDirectory = mainDir + @"styles/fonts/";

            // set pbf as tile provider
            var provider = new VectorTileRenderer.Sources.PbfTileSource(path);

            style.SetSourceProvider(0, provider);

            // render it on a skia canvas
            var canvas  = new SkiaCanvas();
            var bitmapR = await Renderer.Render(style, canvas, 0, 0, zoom, size, size, scale);

            demoImage.Source = bitmapR;

            watch.Stop();
            var elapsedMs = watch.ElapsedMilliseconds;

            Console.WriteLine(elapsedMs + "ms time");
        }
Exemplo n.º 3
0
        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");
        }