private static void WriteOsmSQlite(byte[] osmData, int zoomIndex, int x, int y, SQLiteConnection conn) { Tiles.Tools.Tile tile = new Tiles.Tools.Tile() { Z = zoomIndex, Y = y, X = x }; MBTilesWriter.WriteTile(conn, tile, osmData); }
public static async Task DownloadMap(Models.Map map) { //Make sure the folder for the offline maps exists InitMBTilesFolder(); //Calculate the the sqlite / mbtiles metadata Point p = Utils.Misc.CalculateCenter(map.BoundsRight, map.BoundsTop, map.BoundsLeft, map.BoundsBottom); metadataValues metadata = new metadataValues { name = map.Name, description = "Created by hajk", version = "1", minzoom = map.ZoomMin.ToString(), maxzoom = map.ZoomMax.ToString(), center = p.X.ToString().Replace(",", ".") + "," + p.Y.ToString().Replace(",", "."), bounds = map.BoundsTop.ToString().Replace(",", ".") + "," + map.BoundsLeft.ToString().Replace(",", ".") + "," + map.BoundsBottom.ToString().Replace(",", ".") + "," + map.BoundsRight.ToString().Replace(",", "."), format = "png", type = "png", }; SQLiteConnection conn = MBTilesWriter.CreateDatabase(MainActivity.rootPath + "/MBTiles/" + map.Name + ".mbtiles", metadata); if (conn == null) { return; } for (int zoom = map.ZoomMin; zoom <= map.ZoomMax; zoom++) { var leftBottom = Tile.CreateAroundLocation(map.BoundsLeft, map.BoundsBottom, zoom); var topRight = Tile.CreateAroundLocation(map.BoundsRight, map.BoundsTop, zoom); var minX = Math.Min(leftBottom.X, topRight.X); var maxX = Math.Max(leftBottom.X, topRight.X); var minY = Math.Min(leftBottom.Y, topRight.Y); var maxY = Math.Max(leftBottom.Y, topRight.Y); var tiles = new AwesomeTiles.TileRange(minX, minY, maxX, maxY, zoom); var tilesCount = tiles.Count; totalTilesCount += tilesCount; Log.Information($"Need to download {tilesCount} tiles for zoom level {zoom}"); await DownloadTiles(tiles, zoom, conn); } conn.Close(); Log.Information($"Done downloading map for {metadata.name}"); }