Ejemplo n.º 1
0
        static void Main()
        {
            // Dear BruTile maintainer,
            // If the code in this file does not compile and needs changes you
            // also need to update the 'getting started' sample in the wiki.

            // 1) Create a tile source

            // This is an example that creates the OpenStreetMap tile source:
            var tileSource = new HttpTileSource(new GlobalSphericalMercator(0, 18),
                                                "http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",
                                                new[] { "a", "b", "c" }, "OSM");

            // 2) Calculate which tiles you need

            // the extent of the visible map changes but lets start with the whole world
            var extent = new Extent(-20037508, -20037508, 20037508, 20037508);
            var screenWidthInPixels = 400; // The width of the map on screen in pixels
            var resolution          = extent.Width / screenWidthInPixels;
            var tileInfos           = tileSource.Schema.GetTileInfos(extent, resolution);

            // 3) Fetch the tiles from the service

            Console.WriteLine("Show tile info");
            foreach (var tileInfo in tileInfos)
            {
                var tile = tileSource.GetTile(tileInfo);

                Console.WriteLine(
                    $"tile col: {tileInfo.Index.Col}, " +
                    $"tile row: {tileInfo.Index.Row}, " +
                    $"tile level: {tileInfo.Index.Level} , " +
                    $"tile size {tile.Length}");
            }

            // 4) Try some of the known tile sources

            // You can easily create an ITileSource for a number of predefined tile servers
            // with single line statements like:
            var tileSource1 = KnownTileSources.Create(); // The default is OpenStreetMap
            var tileSource2 = KnownTileSources.Create(KnownTileSource.BingAerial);
            var tileSource3 = KnownTileSources.Create(KnownTileSource.BingHybrid);
            var tileSource4 = KnownTileSources.Create(KnownTileSource.StamenTonerLite);
            var tileSource5 = KnownTileSources.Create(KnownTileSource.EsriWorldShadedRelief);

            // 6) Use MBTiles, the sqlite format for tile data, to work with tiles stored on your device.

            var mbtilesTilesource = new MbTilesTileSource(new SQLiteConnectionString("Resources/world.mbtiles", false));
            var mbTilesTile       = mbtilesTilesource.GetTile(new TileInfo {
                Index = new TileIndex(0, 0, 0)
            });

            Console.WriteLine();
            Console.WriteLine("MBTiles");
            Console.WriteLine($"This is a byte array of an image file loaded from MBTiles with size: {mbTilesTile.Length}");
        }
Ejemplo n.º 2
0
        private void DownloadMap()
        {
            if (selectedSource.PersistentCache == null || !(selectedSource.PersistentCache is ReadOnlyFileCache))
            {
                return;
            }

            var cache         = (ReadOnlyFileCache)selectedSource.PersistentCache;
            var mapExtent     = mapView.Viewport.Extent.ToExtent();
            var fetchStrategy = new CustomFetchStrategy();
            var tileInfos     = fetchStrategy.Get(
                selectedSource.Schema,
                mapExtent,
                selectedSource.Schema.Resolutions.Count - 1);

            cache.CacheToDisk = true;

            using (var loading = UserDialogs.Instance.Loading())
            {
                int tileCounter = 0;
                foreach (var tileInfo in tileInfos)
                {
                    tileCounter++;
                    int progress = Convert.ToInt32(tileCounter / (float)tileInfos.Count * 100.0);

                    var tileSize = 0;
                    if (!cache.Exists(tileInfo.Index))
                    {
                        var tile = selectedSource.GetTile(tileInfo);
                        tileSize = tile.Length;
                    }

                    var progressString  = $"{progress}% ({tileCounter}/{tileInfos.Count})";
                    var progressMessage = $"Downloading\n{progressString}";
                    Console.WriteLine(
                        $"{progressString} - " +
                        $"tile col: {tileInfo.Index.Col}, " +
                        $"tile row: {tileInfo.Index.Row}, " +
                        $"tile level: {tileInfo.Index.Level}, " +
                        $"tile size {tileSize}");

                    loading.Title = progressMessage;
                }
            }

            cache.CacheToDisk = false;
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            Mapsui.Logging.Logger.LogDelegate += (level, message, ex) =>
            {
                Console.WriteLine($"[{level}]: {message}");
            };

            using var httpClient = new HttpClient();

            var fileCache = new FileCache(Path.Combine(Path.GetTempPath(), "tilecache"), "png");

            HttpTileSource tileSource = KartverketSources.Create(
                KartverketTileSource.SjøkartRaster,
                FetchFactory.CreateRetryFetcher(httpClient),
                fileCache);

            var southWest = SphericalMercator.FromLonLat(22.7962, 70.0910);
            var northEast = SphericalMercator.FromLonLat(22.8618, 70.1205);
            var extent    = new Extent(southWest.X, southWest.Y, northEast.X, northEast.Y);

            Console.WriteLine($"Getting tiles for extent {extent}");

            var fetchStrategy = new DataFetchStrategy();
            var tileInfos     = fetchStrategy.Get(tileSource.Schema, extent, 15);

            //var tileInfos = tileSource.Schema.GetTileInfos(extent, 7);

            Console.WriteLine($"Show tile info ({tileInfos.Count} tiles)");
            int tileCounter = 0;

            foreach (var tileInfo in tileInfos)
            {
                tileCounter++;
                double progress = Math.Round(tileCounter / (float)tileInfos.Count * 100.0f, 2);

                var tile = tileSource.GetTile(tileInfo);
                Console.WriteLine(
                    $"{progress}% ({tileCounter}/{tileInfos.Count}) - " +
                    $"tile col: {tileInfo.Index.Col}, " +
                    $"tile row: {tileInfo.Index.Row}, " +
                    $"tile level: {tileInfo.Index.Level}, " +
                    $"tile size {tile.Length}");
            }
        }
Ejemplo n.º 4
0
        static void Main()
        {
            // 1) Create a tile source

            //This is an example of the open street map tile source:
            var tileSource = new HttpTileSource(new GlobalSphericalMercator(0, 18),
                                                "http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",
                                                new[] { "a", "b", "c" }, "OSM");


            // 2) Calculate which tiles you need

            // the extent of the visible map changes but lets start with the whole world
            var       extent = new Extent(-20037508, -20037508, 20037508, 20037508);
            const int screenWidthInPixels = 400; // The width of the map on screen in pixels
            var       unitsPerPixel       = extent.Width / screenWidthInPixels;
            var       tileInfos           = tileSource.Schema.GetTileInfos(extent, unitsPerPixel);


            // 3) Fetch the tiles from the service

            var tiles = new Dictionary <TileInfo, byte[]>();

            foreach (var tileInfo in tileInfos)
            {
                tiles[tileInfo] = tileSource.GetTile(tileInfo);
            }

            // Show that something actually happended:

            foreach (var tile in tiles)
            {
                System.Console.WriteLine("Column: {0}, Row: {1}, level: {2}, bytes: {3}",
                                         tile.Key.Index.Col, tile.Key.Index.Row, tile.Key.Index.Level, tile.Value.Length);
            }

            System.Console.ReadKey();
        }
Ejemplo n.º 5
0
 public byte[] GetTile(TileInfo tileInfo) => _WrappedSource.GetTile(tileInfo);