Android Tutorial OSMDroid - MapView for B4A tutorial

Sam H

Member
Licensed User
Longtime User
Ok, not to worry, do you have an example of the TileSourceSpinner using OSMDroid_4_1 as I can only find the one for the older version which I can't get to work since Mapview1.SetTileSource() requires an Object rather than a string "" like the old version.

How would I define "mapnik", "CycleMap", "OSMPublicTransport", "MapquestOSM" etc. as OSMDroid_MapTile's?

Thanks

Sam
 

warwound

Expert
Licensed User
Longtime User
@Sam H

Attached is the updated 'select a TileSource' demo, updated to work with OSMDroid 4.1.
Tested and working here on my Moto G (KitKat).

B4X:
Sub Process_Globals
	Dim InitialTileSourceName As String="Mapnik"
	Dim MapCenter As OSMDroid_GeoPoint
	Dim SelectedTileSource As OSMDroid_TileSource
	Dim ZoomLevel As Int
End Sub

Sub Globals
	Dim MapView1 As OSMDroid_MapView
	Dim TileSourceFactory1 As OSMDroid_TileSourceFactory
	Dim TileSourceSpinner As Spinner
End Sub

Sub Activity_Create(FirstTime As Boolean)
	If FirstTime Then
		MapCenter.Initialize(52.75192, 0.40505)
		ZoomLevel=14
		
		'	set the default initial TileSource
		SelectedTileSource=TileSourceFactory1.GetTileSource(InitialTileSourceName)
	End If
	
	MapView1.Initialize("")
	
	MapView1.SetBuiltInZoomControls(True)
	MapView1.SetMultiTouchControls(True)
	
	MapView1.GetController.SetZoom(ZoomLevel)
	MapView1.GetController.SetCenter(MapCenter)
	
	Activity.AddView(MapView1, 0, 48dip, 100%x, 100%y-48dip)
	
	TileSourceSpinner.Initialize("TileSourceSelect")
	
	Dim TileSourceFactory1 As OSMDroid_TileSourceFactory
	Dim AvailableTileSources() As OSMDroid_TileSource
	AvailableTileSources=TileSourceFactory1.GetTileSources
	
	For Each AvailableTileSource As OSMDroid_TileSource In AvailableTileSources
		TileSourceSpinner.Add(AvailableTileSource.Name)
	Next
	
	TileSourceSpinner.Prompt="Select a TileSource"
	TileSourceSpinner.SelectedIndex=TileSourceSpinner.IndexOf(SelectedTileSource.Name)
	Activity.AddView(TileSourceSpinner, 0, 0, 100%x, 48dip)
	
	'	manually call the Spinner ItemClick Sub to sync the MapView TileSource with the spinner SelectedIndex
	TileSourceSelect_ItemClick(TileSourceSpinner.SelectedIndex, TileSourceSpinner.SelectedItem)
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)
	MapCenter=MapView1.GetMapCenter
	ZoomLevel=MapView1.GetZoomLevel
End Sub

Sub TileSourceSelect_ItemClick (Position As Int, Value As Object)
	'	set the MapView TileSource
	Dim TileSourceName As String=Value
	SelectedTileSource=TileSourceFactory1.GetTileSource(TileSourceName)
	MapView1.SetTileSource(SelectedTileSource)
End Sub

Martin.
 

Attachments

  • SimpleMapTileSources.zip
    6.6 KB · Views: 564

Sam H

Member
Licensed User
Longtime User
Thanks again for such a quick response, I have got it working on my Nexus 7 (Android Jelly Bean). Some of the tileSources that are displayed on the spinner such as "base", "topo" and "hills" don't show anything, although I was able to remove them.

Thanks

Sam
 

PABLO2013

Well-Known Member
Licensed User
Longtime User
greetings martin
few weeks back , i post to how how could see the scala overlay again in my projects ... I can not make it look ... I have followed the forum about it can be a problem in the manifest file, but do not I can fix, I use windows 7, jdk1.7.0_67 \ bin \ javac.exe, android-10 \ android.jar, osm 3.6 (I tried 4.0 with no result) B4A 3.82, tks , plz helpme.
 

jamesnz

Active Member
Licensed User
Longtime User
Is there a possibility of setting up a custom tile server. I have made customised tiles ( way too many to store on device) . How would one store these on a web server and have the mapview make the appropriate requests. I'm presuming I could set up a directory on my server and designthe file structure the same as the x/y calls
 

warwound

Expert
Licensed User
Longtime User

How are your customised tiles named?
Are they named using the slippy map tile naming convention:

folder named after zoom level > folder named after tile x parameter > tile named after tile y parameter.

If so move all the folders named after the zoom level to a single new folder.
Now add this new folder to a new zip archive and upload it to your server.
Your server hopefully has a control panel where you can now unzip the archive.

Nothing special needs to be done, just establish the path to the un-zipped tiles on your server and update your OSMDroid code to use the online custom tiles.

If your server has no way for you to unzip an archive then you'll have to upload all your custom tiles one by one using FTP and that will take a long while if you have lots of tiles.

Martin.
 

jamesnz

Active Member
Licensed User
Longtime User
yes , I just use the standard slippymap convention.( tiles made by maperative ).png
Question was how to tell the mapview what my server address is eg "www.myserver.co.nz/mymaptiles"/x/y/etc
I assume I have to change the tile source factory to a custom address somehow ?
 

jamesnz

Active Member
Licensed User
Longtime User
I have zoom 18 tiles so I just changed the maximum zoom in the mytilesource.initialize to 0,18,256
works fine - and I'm still ftping to the server
cheers for the help
 

PABLO2013

Well-Known Member
Licensed User
Longtime User
greetings martin
few weeks back , i post to how how could see the scala overlay again in my projects ... I can not make it look ... I have followed the forum about it can be a problem in the manifest file, but do not I can fix, I use windows 7, jdk1.7.0_67 \ bin \ javac.exe, android-10 \ android.jar, osm 3.6 (I tried 4.0 with no result) B4A 3.82, tks , plz helpme.
 

georm

Member
Licensed User
Longtime User
Hello
About OSMDroid_UrlTileSource. I'd use the server tiles from IGN (French service). The url use a key, i's not a problem, but use an authentication with user and password.
When I program in Microsoft .Net. I use a HttpWebRequest object with a NetworkCredential to pass the User and the Password.
Is there a equivalence en b4a, I'm a beginner.
Sample IGN url:

B4X:
https://gpp3-wxs.ign.fr/my_ignkey/wmts?LAYER=ORTHOIMAGERY.ORTHOPHOTOS&EXCEPTIONS=text/xml&FORMAT=image/jpeg&SERVICE=WMTS&VERSION=1.0.0&REQUEST=GetTile&STYLE=normal&TILEMATRIXSET=PM&TILEMATRIX=18&TILEROW=90241&TILECOL=132877

Thanks
Laurent
 

warwound

Expert
Licensed User
Longtime User
@georm

Are you saying that you send the auth username and password to the tileserver using an HTTP request and you get a 'token' back.
And then when you request a tile, that token must be part of the tile request url?
 

georm

Member
Licensed User
Longtime User
I must just use HTTP with ExecuteCredentials and pass a httpRequest with username and password and recup the taskid ?

Thanks
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…