Using this very nice OSM map viewer:
I didn't like the blue diagonals that will show for the area outside the map, so added some code that will prevent that
and also avoids trips to the map DB, looking for tiles that are not there:
In clsMapTileManager:
In code module MapUtilities:
In cvMap:
RBS
B4XMap (Open Street Map viewer)
Just came across this and thinking about moving to this from OSMDroid. Trying to figure out how to download a map area based on min and max latitude and longitude and can't figure out how to get from latitude and longitude to the Open Street Map x and y tile numbers, so I can do something like...
www.b4x.com
I didn't like the blue diagonals that will show for the area outside the map, so added some code that will prevent that
and also avoids trips to the map DB, looking for tiles that are not there:
In clsMapTileManager:
B4X:
'open db, create it if necessary
Private Sub dbInit
Dim strSQL As String
strSQL = "CREATE TABLE tiles(" & _
"zoom_level INTEGER NOT NULL, " & _
"tile_column INTEGER Not Null, " & _
"tile_row INTEGER Not Null, " & _
"tile_data BLOB Not Null, primary key (zoom_level, tile_column, tile_row))"
fXUI.SetDataFolder("")
If Not(File.Exists(fXUI.DefaultFolder,"tiles.db3")) Then
#if B4A or B4i
fDB.Initialize(fXUI.DefaultFolder,"tiles.db3",True)
#else if B4J
fDB.InitializeSQLite(fXUI.DefaultFolder,"tiles.db3",True)
#end if
fDB.ExecNonQuery(strSQL)
Else
Dim strSQL As String
Dim RS1 As ResultSet
#if B4A or B4i
fDB.Initialize(fXUI.DefaultFolder, "tiles.db3", False)
strSQL = "select zoom_level, min(tile_column), max(tile_column), min(tile_row), max(tile_row) from tiles group by zoom_level"
RS1 = fDB.ExecQuery(strSQL)
MapUtilities.SetupMapDBRowsColumns(RS1)
#else if B4J
fDB.InitializeSQLite(fXUI.DefaultFolder,"tiles.db3",False)
#End If
End If
End Sub
In
In code module MapUtilities:
B4X:
Sub Process_Globals
Private mapDBRowsColumns As Map
Sub SetupMapDBRowsColumns(RS1 As ResultSet)
Dim c As Int
mapDBRowsColumns.Initialize
Do While RS1.NextRow
Dim arrInt(4) As Int
For c = 0 To 3
arrInt(c) = RS1.GetInt2(c + 1)
Next
mapDBRowsColumns.Put(RS1.GetInt2(0), arrInt)
Loop
End Sub
Public Sub TileInDB(iZoom As Int, iColumn As Int, iRow As Int) As Boolean
Dim arrInt() As Int
arrInt = mapDBRowsColumns.Get(iZoom)
Return iColumn >= arrInt(0) And iColumn <= arrInt(1) And iRow >= arrInt(2) And iRow <= arrInt(3)
End Sub
In cvMap:
B4X:
'add tile to the mapview
private Sub addTile(aLeft As Int,aTop As Int,aTileX As Long,aTileY As Long,aZ As Int)
aTileX=checkTile(aTileX,fTilesCount)
aTileY=checkTile(aTileY,fTilesCount)
'view for the tile
Dim xpt As B4XView = fxui.CreatePanel("tile")
xpt.Tag=MapUtilities.initTileXY(aTileX,aTileY)
fViewTiles.AddView(xpt,aLeft,aTop,MapUtilities.cTileSize,MapUtilities.cTileSize)
'view for the tile's image
'only put image on tile panel if that tile is in the DB
'------------------------------------------------------
If MapUtilities.TileInDB(aZ,aTileX,aTileY) Then '<<<< added RBS 14/03/2022
Dim iv As ImageView
iv.Initialize("itile")
xpt.AddView(iv,0,0,MapUtilities.cTileSize,MapUtilities.cTileSize)
drawTile(iv,aZ,aTileX,aTileY)
End If
'view for the grid
Dim pg As B4XView = fxui.CreatePanel("gtile")
xpt.AddView(pg,0,0,MapUtilities.cTileSize,MapUtilities.cTileSize)
drawGridOnTile(pg)
pg.Visible=fMap.fShowGrid
End Sub
RBS