private void RenderToBuffer() { var levelIndex = Utilities.GetNearestLevel(_source.Schema.Resolutions, _mapTransform.UnitsPerPixel); using (var g = Graphics.FromImage(_buffer)) { g.Clear(Color.White); foreach (var tileInfo in _source.Schema.GetTileInfos(_mapTransform.Extent, levelIndex)) { var res = _source.GetTile(tileInfo); var extent = _mapTransform.WorldToMap(tileInfo.Extent.MinX, tileInfo.Extent.MinY, tileInfo.Extent.MaxX, tileInfo.Extent.MaxY); if (res != null) { var tileStream = new MemoryStream(res); var tile = (Bitmap)Image.FromStream(tileStream); DrawTile(_source.Schema, g, tile, extent, tileInfo.Index.Level); } var roundedExtent = RoundToPixel(extent); g.DrawRectangle(Pens.Black, roundedExtent); g.DrawString(string.Format("({2}:{0},{1})", tileInfo.Index.Col, tileInfo.Index.Row, tileInfo.Index.Level), new Font("Arial", 8, FontStyle.Regular), Brushes.OrangeRed, roundedExtent, new StringFormat { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center, Trimming = StringTrimming.None }); } g.DrawRectangle(new Pen(Color.Tomato, 2), RoundToPixel(_mapTransform.WorldToMap(_source.Schema.Extent))); } tsslExtent.Text = $@"[({_mapTransform.Extent.MinX:N}/{_mapTransform.Extent.MinY:N})/({_mapTransform.Extent.MaxX:N}/{_mapTransform.Extent.MaxY:N})]"; picMap.Image = _buffer; }
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}"); }
public void FetchTiles() { // arrange MbTilesTileSource.SetPlatform(new SQLitePlatformWin32()); const string path = ".\\Resources\\test.mbtiles"; var tileSource = new MbTilesTileSource(new SQLiteConnectionString(path, false)); var extent = tileSource.Extent; var tileInfos = tileSource.Schema.GetTileInfos(extent, "1").ToList(); // act var data = tileSource.GetTile(tileInfos.First()); // assert Assert.True(data.Length > 0); }
public void SchemaGeneratedFromMbTilesWithSchemaInConstructor() { // arrange SQLitePCL.Batteries.Init(); var path = Path.Combine(Paths.AssemblyDirectory, "Resources", "torrejon-de-ardoz.mbtiles"); // act var tileSource = new MbTilesTileSource(new SQLiteConnectionString(path, false, _encryptionKey), new GlobalSphericalMercator("png", YAxis.TMS, null)); // assert var tile = tileSource.GetTile(new TileInfo { Index = new TileIndex(2006, 2552, "12") }); Assert.NotNull(tile); }
public void SchemaGeneratedFromMbTilesWithSchemaInConstructor() { // arrange SQLitePCL.Batteries.Init(); const string path = ".\\Resources\\torrejon-de-ardoz.mbtiles"; // act var tileSource = new MbTilesTileSource(new SQLiteConnectionString(path, false), new GlobalSphericalMercator("png", YAxis.TMS, null)); // assert var tile = tileSource.GetTile(new TileInfo { Index = new TileIndex(2006, 2552, "12") }); Assert.NotNull(tile); }
public void FetchTiles() { // arrange var path = Path.Combine(Paths.AssemblyDirectory, "Resources", "test.mbtiles"); var tileSource = new MbTilesTileSource(new SQLiteConnectionString(path, false, _encryptionKey)); var extent = tileSource.Schema.Extent; var tileInfos = tileSource.Schema.GetTileInfos(extent, "1").ToList(); tileSource.Attribution = new Attribution("attribution", "url"); // act var data = tileSource.GetTile(tileInfos.First()); // assert Assert.True(data.Length > 0); Assert.AreEqual(MbTilesType.BaseLayer, tileSource.Type); Assert.AreEqual("attribution", tileSource.Attribution.Text); }
public void FetchTiles() { // arrange SQLitePCL.Batteries.Init(); const string path = ".\\Resources\\test.mbtiles"; var tileSource = new MbTilesTileSource(new SQLiteConnectionString(path, false)); var extent = tileSource.Schema.Extent; var tileInfos = tileSource.Schema.GetTileInfos(extent, "1").ToList(); tileSource.Attribution = new Attribution("attribution", "url"); // act var data = tileSource.GetTile(tileInfos.First()); // assert Assert.True(data.Length > 0); Assert.AreEqual(MbTilesType.BaseLayer, tileSource.Type); Assert.AreEqual("attribution", tileSource.Attribution.Text); }