Android Tutorial OSMDroid - MapView for B4A tutorial

You can find the OSMDroid library thread here: http://www.b4x.com/forum/additional...tes/16309-osmdroid-mapview-b4a.html#post92643.

AIM: Create and initialize a MapView, enable the map zoom controller and multitouch controller, set a zoom level then center the map on a location.

B4X:
Sub Process_Globals
End Sub

Sub Globals
   Dim MapView1 As MapView
End Sub

Sub Activity_Create(FirstTime As Boolean)
   If File.ExternalWritable=False Then
      '   OSMDroid requires the use of external storage to cache tiles
      '   if no external storage is available then the MapView will display no tiles
      Log("WARNING NO EXTERNAL STORAGE AVAILABLE")
   End If
   
   '   no EventName is required as we don't need to listen for MapView events
   MapView1.Initialize("")
   Activity.AddView(MapView1, 0, 0, 100%x, 100%y)
   
   '   by default the map will zoom in on a double tap and also be draggable - no other user interface features are enabled
   
   '   enable the built in zoom controller - the map can now be zoomed in and out
   MapView1.SetZoomEnabled(True)
   
   '   enable the built in multi touch controller - the map can now be 'pinch zoomed'
   MapView1.SetMultiTouchEnabled(True)
   
   '   set the zoom level BEFORE the center (otherwise unpredictable map center may be set)
   MapView1.Zoom=14
   MapView1.SetCenter(52.75192, 0.40505)
End Sub

Sub Activity_Resume
End Sub

Sub Activity_Pause (UserClosed As Boolean)
End Sub

The code is pretty self-explanatory.

I've added the code to check if the device has available external storage as OSMDroid will not display any tiles if no external storage is available.
External storage is used to save/cache all downloaded tiles - no external storage means no map!
(I'll omit that check from future tutorials but it's something to bear in mind - not that i know of any Android devices that have no external storage).

Create and initialize a MapView, add it to the Activity 100% width and 100% height.
Enable the zoom and multi-touch controller.
Zoom in to level 14 then set the MapView center to a location (sunny Norfolk, UK!).

I've found that setting the map center and then immediately setting the zoom level does not work as expected.
I think that while the MapView is setting the map center it also zooms in so the end result is unpredictable.

Pan and zoom the map, now rotate your device and you'll see the map returns to it's initial state of zoom level 14, center (52.75192, 0.40505).

I shall show you how to save and restore the MapView state next...

Martin.
 

Attachments

  • 01 - SimpleMap.zip
    5.8 KB · Views: 4,640
Last edited:

BarrySumpter

Active Member
Licensed User
Longtime User
Thats projects 08 and 13.
My favs.

-----

Martin,

Is there anything we can do with the 5 sec blank screen at app start up?

Maybe turn it into a splash screen?

-----

Also, we were discussing how I wanted to create a zip libraryof markers.
And kinda left it at "can't extract a single file from a zip".
Is there a way we can use/take advantage of way a single tile is extracted
from the Offline Tile Source.zip file technique?
Or maybe thats what the 5 second delay is on app startup? i.e. unzipping?
 
Last edited:

dunski

Member
Licensed User
Longtime User
Thanks

Thats just all fantastic stuff. Most enjoyable programming I've done in years.:sign0060:

Another question for you if you don't mind.

Have you done any sample projects of clicking Markers on a map to raise an event?

Again fair play to you... Very enjoyable stuff. Easy to follow and works so good.

Dunski:)
 

warwound

Expert
Licensed User
Longtime User

warwound

Expert
Licensed User
Longtime User
Martin,

Is there anything we can do with the 5 sec blank screen at app start up?

Maybe turn it into a splash screen?

-----

Also, we were discussing how I wanted to create a zip libraryof markers.
And kinda left it at "can't extract a single file from a zip".
Is there a way we can use/take advantage of way a single tile is extracted
from the Offline Tile Source.zip file technique?
Or maybe thats what the 5 second delay is on app startup? i.e. unzipping?

I don't get a 5 second delay here - i just started an Activity which contains a MapView and MyLocationOverlay and it took 2 seconds to start.

That on a device with a single core 1GHz CPU.
What are the specs of the device that you are using?

It may be that you are adding a lot of things to the MapView in Activity_Create and on any device that doesn't have a lot of CPU power a delay is inevitable.

You could try initializing the MapView and setting it's center and zoom level in Activity_Create then adding overlays and/or Markers etc in Activity_Resume.

You'd have to watch that if your Activity is paused and then resumed that you don't execute that code in Activity_Resume a second time.

I see there's a library that can open zip files, i haven't used it myself.
Look here: http://www.b4x.com/forum/additional-libraries-official-updates/7053-zip-unzip-library.html.

Martin.
 

jparkerri

Member
Licensed User
Longtime User
Can you display KML files in MapView?

Your tutorial is great. I need to display a grid of lines that I can follow. I have a KML of the lines and I can display it i Google Earth. How would I display it in your sample?
Thanks.
 

warwound

Expert
Licensed User
Longtime User
Your tutorial is great. I need to display a grid of lines that I can follow. I have a KML of the lines and I can display it i Google Earth. How would I display it in your sample?
Thanks.

There is currently no ready made method to render a KML file using OSMDroid.

I have some plans for B4A and one is to create an XML parsing library based on XOM native java library.

And then once i've learnt how to use XOM i was hoping to create a new OSMDroid overlay layer that can accept a KML file as input and render basic KML features such as markers, polylines and polygons.

Until i have time to do that you'll have to manually parse the KML and manually render the polylines.

The only method currently available to render a polyline is to use the PathOverlay, a single instance of PathOverlay can only render a single polyline.
So if you have a grid composed of 10 vertical and 10 horizontal polylines you'd need 20 instances of PathOverlay!
Not very efficient or elegant to say the least.

Perhaps i could create a new PathsOverlay which would be much like the existing PathOverlay but a single instance of PathsOverlay would draw an Array of polylines instead of a single polyline.
It'd hopefully not be too much work to create the new PathsOverlay as most of the code required exists in PathOverlay.

Can you upload your KML file so i can see how many polylines you need to render?

A lot of polylines could cause performance problems especially if your MapView contains other features.
If performance is an issue then the ultimate solution would be to render the polylines as a custom tile layer.
You'd need to render a set of transparent map tiles for the area which your grid covers and add them to OSMDroid as a new TileSource.

There are various utilities available that can render a tile set from a data source, you'd need to find a utility that can render a tile set from a KML file OR convert your KML file to a different format and use a utility that can render that different format.

But then there is still a problem - OSMDroid only supports display of a single TileSource and you'd want to display an existing TileSource such as Mapnik with your transparent grid tiles on top.
A solution can be found here: Teaching MapTileProviderArray to use multible semi transparent tiles at once « Mapping Developer Blog, i'm not sure how long that would take me to add to the B4A OSMDroid library though.

Time is limited and i have many projects to do work on.

Martin.
 

jparkerri

Member
Licensed User
Longtime User
KML for display with OSMDroid.

I'd better explain what I'm trying to get to. I have a B4A program that logs GPS position and time with the output of a depth finder via serial through an IOIO board to the Uart. I run bathymetric surveys in a small boat. To survey, I need to follow lines on the screen and see my path to know where I've already been.

I did this with Google Earth using the KML for the evenly spaced parallel survey lines and input serial GPS and depth into a laptop. I thought it would be much easier to survey with my Galaxy Tab 7 using its GPS, input depth through the IOIO Uart. I's using your tutorial #8 (OverlayMapMyLocation) and adding your PathOverlay from #7 to show my track. Could I make another PathOverlay for the survey lines.
I wrote the program that made the KML so I could change it to just write a file of points that I read in to populate GeoPoints of a PathOverlay just once. The KML just has 50 to 100 straight lines so only two endpoints each. Would I have to redisplay the PathOverlay of survey lines each time he center moves or will it handle that?

I tried to attach the KML but it was too large for this forum.

Thanks for any suggestions.
 

jparkerri

Member
Licensed User
Longtime User
Parseing KML works good.

I took your advice and parsed the KML with the XML_SAX library then parsed the strings from the KML wit 'Split' into latitude and longitude and then 'AddPoint'ed them to a PathOverlay. Very fast, reads file once, displays and moves with map.

One other question about zooming in. It seems that I'm limited to how much I can Zoom and it also seems to depend on the map source. Is that correct or does your example limit how much you can zoom?

Thanks for your advice.
 

BarrySumpter

Active Member
Licensed User
Longtime User
This is how I select my zoom range after I've created and inlcuded my own map tiles.
B4X:
MyXYTileSource.initialize(MyTileSourceName, 0, 20, 256, ".png",  "http://localhost/")
0 = min zoom level
20 = max zoom level

I did notice when working with Mobile Atlas Creator (MOBAC),
that the max zoom levels were different on each mapping provider.

Where GMaps and MSMaps were the deepest at 19 I think.
And GMaps was the only one that gave street addresses/house numbers.
The rest were 18 and lower.

hth
 
Last edited:

warwound

Expert
Licensed User
Longtime User
It seems that I'm limited to how much I can Zoom and it also seems to depend on the map source. Is that correct or does your example limit how much you can zoom?

Yes, the maximum available zoom level depends on the currently selected TileSource.

Mapnik and most OSM types currently have zoom levels 0 to 18 available for example.

MapsForFree only has levels 0 to 11.

If your MapView is displaying an area of sea then i think most TileSources will display just a plain blue tile - with no detail.
Do you simply want to zoom in more so that your grid lines are more zoomed and the MapView shows distance in greater resolution?

You could create a new custom TileSource and add it to your MapView.
The new TileSource could use a plain sea blue tile for everywhere, you configure it to cover zoom levels 18 to 24 for example and when that new TileSource is selected you'd be able to zoom to whatever maximum zoom level you configure.
So distance changes would display with a greater degree of resolution.

Other options that may be of interest...

It should be possible to add OpenSeaMap: Mainpage as a TileSource if that imagery is useful.

Are there any Shapefiles available for the area you wish to display?
You can render a set of custom tiles from a shapefile using GMapCreator and display them in a MapView as a custom TileSource.
Shapefiles contain vector data and in theory could be used to render tiles for any zoom level.

Martin.
 

jparkerri

Member
Licensed User
Longtime User
Add or create new tilesource.

Yes, that's all I need, to be able to zoom in more to see my track over my survey lines. I don't need any detail.
I looked at OpenSeaMap but couldn't figure out how to download it to add to the tilesources. I can run SeaMap on my Tab and zoom in as much as I want so it seems to have more zoom levels. When I go to download charts from the OpenSeaMap website, there are none for the US. Where would I get the tiles for OpenSeaMap that I see in SeaMap?

What would I need to do to make my own custom tilesource that I could control the zoom? Could I just add more zoom levels to MapNik tilesource?
Thanks.
 

warwound

Expert
Licensed User
Longtime User
Look at the attached project:

B4X:
Sub Process_Globals
   Dim MapCenter As GeoPoint
   Dim TileSource As String
   Dim ZoomLevel As Int
End Sub

Sub Globals
   Dim MapView1 As MapView
   Dim TileSourceSpinner As Spinner
End Sub

Sub Activity_Create(FirstTime As Boolean)
   MapView1.Initialize("")
   
   If FirstTime Then
      MapCenter.Initialize(0, 0)
      ZoomLevel=2
      
      Dim CurrentTilesSources As List
      Dim NewTileSourceName As String
      NewTileSourceName="NewTileSource"
      
      CurrentTilesSources=MapView1.GetTileSources
      If CurrentTilesSources.IndexOf(NewTileSourceName)=-1 Then
         '   NewTileSourceName has not yet been added to the MapView
      
         Dim BlankXYTileSource1 As BlankXYTileSource
         BlankXYTileSource1.Initialize(NewTileSourceName, 0, 21, "http://android.martinpearman.co.uk/b4a/osmdroid/misc/blank_tile.png")
         MapView1.AddXYTileSource(BlankXYTileSource1)
      
         '   **   OR   **
         
         '   add a new TileSource using the existing Mapnik tiles but extend the maximum zoom
         '   no tile will exist past zoom level 18 but the map will zoom to 21
         '   you can increase the maximum zoom from 21 if you wish
'         Dim MyXYTileSource As XYTileSource
'         MyXYTileSource.Initialize(NewTileSourceName, 0, 21, 256, ".png", "http://tile.openstreetmap.org/")
         
         
         '   **   OR   **
         
         '   create a new TileSource using the openseamap tiles
         '   19 is the maximum zoom available - you can increase it but obviously tiles will not exist past level 19
'         MyXYTileSource.Initialize(NewTileSourceName, 0, 19, 256, ".png", "http://tiles.openseamap.org/seamark/")
'         Dim MyXYTileSource As XYTileSource
'         MapView1.AddXYTileSource(MyXYTileSource)
         
         '   note that after Activity_Pause (orientation change for example) the added TileSource will still exist in the MapView
         '   the added TileSorce will exist until the activity process is destroyed
         '   trying to add a TileSource more than once will not cause problems however - the AddXYTileSource method ensures that the TileSource is only added once
      End If
      
      '   set the default initial TileSource
      TileSource=NewTileSourceName
   End If
   
   TileSourceSpinner.Initialize("TileSourceSelect")
   Activity.AddView(TileSourceSpinner, 0, 0, 100%x, 48dip)
   
   TileSourceSpinner.AddAll(MapView1.GetTileSources)
   TileSourceSpinner.Prompt="Select a TileSource"
   TileSourceSpinner.SelectedIndex=TileSourceSpinner.IndexOf(TileSource)
   '   manually call the Spinner ItemClick Sub to sync the MapView TileSource with the spinner SelectedIndex
   TileSourceSelect_ItemClick(TileSourceSpinner.SelectedIndex, TileSourceSpinner.SelectedItem)
   
   MapView1.SetMultiTouchEnabled(True)
   MapView1.SetZoomEnabled(True)
   MapView1.Zoom=ZoomLevel
   MapView1.SetCenter3(MapCenter)
   Activity.AddView(MapView1, 0, 48dip, 100%x, 100%y-48dip)
End Sub

Sub Activity_Resume
End Sub

Sub Activity_Pause (UserClosed As Boolean)
   MapCenter=MapView1.GetCenter
   ZoomLevel=MapView1.Zoom
   
   '   save the currently selected MapView TileSource
   TileSource=MapView1.GetTileSource
End Sub

Sub TileSourceSelect_ItemClick (Position As Int, Value As Object)
   '   set the MapView TileSource
   MapView1.SetTileSource(Value)
End Sub

Here you have three options:

  • Create a new BlankXYTileSource that uses a single tile for all locations.
    You can specify any minimum and maximum zoom level and that single tile will be used for all areas of the map.
  • Create a new XYTileSource that uses the existing Mapnik tiles but specify a maximum zoom level higher than that for which tiles exist.
    As you zoom past level 18 the MapView will display previously visible zoom level 18 tiles stretched - it will request tiles for the higher zoom levels and these will result in 404 file not found errors.
    You can zoom the map in to whatever maximum zoom level you specify - the map will display stretched tiles until you pan the map and then display the blank MapView background.
    Your device will make a lot of network requests for tiles that do not exist.
  • Create a new XYTileSource that uses the OpenSeaMap tiles.
    At low zoom levels you will see the default Mapnik tiles.
    As you zoom in past around level 17 or 18 you'll see the OpenSeaMap tiles in areas of sea.
    These tiles are transparent and meant to be displayed on top of another tile layer, OSMDroid cannot currently do that so the transparent area of the OpenSeamapTiles displays as black.
    OpenSeaMap tiles exist up to level 19, you can specify a higher maximum zoom level as in the Mapnik extra zoom TileSource but will have the same problem - your device will make many network requests for tiles that do not exist.

I think the best solution is to use an existing TileSource as you are already doing and when you need to zoom in more than is available switch to a BlankXYTileSource.
So if your map is at zoom level 18 or less use the Mapnik tiles and only switch to the BlankXYTileSource when you need extra zoom.

BlankXYTileSource is not part of the OSMDroid library - i just created it for this post.
You'll need to copy it from the attachment to your B4A additional libraries folder.

Martin.
 

Attachments

  • TileSourceExtraZoom.zip
    9.1 KB · Views: 587

jparkerri

Member
Licensed User
Longtime User
Using new tilesources.

Thanks for the BlankXYTileSource Code. I've tried all three of your suggestions. I was able to make the 'blank' tilesource and see the blue tile. I only need a zoomlevel of 19 so I tried to remake the Mapnik tilesource both as an XYTileSource and a BlankXYTileSource. It displays my survey lines and zooms to the new level but does not show any detail at any level. There are no 'png' tiles in the cache. I've even made a "NewMapnik" but same issue. It works but no detail. Is there a permission issue downloading the tiles from openstreetmap.org or openseamap.org?

I also tried to switch to the 'blank' tilesource if the zoomlevel goes over 18 (or even 16 or 17) by testing the MapView1.Zoom in Mapview1_ZoomChanged and then running MapView1.SetTileSource("Blank") but it doesn't seem to work. Once the zoom level is 18, the button to increase the zoom is already disabled. What should I have to do to reset the tilesource?

I also installed the program 'Maperitive' and generated *.png tiles for my survey area. I put them in the 'osmdroid/tiles' cache on my tablet but they didn't show. If the 'MyXYTileSource1.Initialize' call fails, will that TileSource use the files in the cache? Do the tiles have to be *.png.tile"? The files from Maperitive are just *.png. Can the 'MyXYTileSource1.Initialize' call use a 'file://' instead of 'http://'?

I renamed all the *.png files to *.png.tile and now they show up from the cache.

Is there any documentation of all this so I won't keep bothering you with questions? (I may have to donate.)

Thanks.
 
Last edited:

warwound

Expert
Licensed User
Longtime User
Hi again.

Maperitive what a find! - never seen that program before but have now got it installed.

If you can get Maperitive tiles working then i guess you'll not bother with the other hacks?

So i'll give you a quick guide to getting Maperitive tiles to work in OSMDroid.

First have a read of these two posts: http://www.b4x.com/forum/basic4andr...smdroid-mapview-b4a-tutorial-2.html#post92702 and http://www.b4x.com/forum/basic4andr...smdroid-mapview-b4a-tutorial-6.html#post96437

You need a ZIP archive with the correctly named tiles in a correctly named folder.

And then you can add your offline tiles to OSMDroid as a new custom offline XYTileSource.

Maperitive generates tiles and saves them in it's Tiles folder.
Hopefully you're using Windows?
Right-click the Tiles folder and Send to Compressed (zipped) folder.
Open the new Tiles.zip archive and rename the Tiles folder to the name you want to use for your new TileSource.
No spaces, and special characters are best avoided.
Let's say you rename it to jparkerri.

Now you need to transfer that ZIP archive to your device's external memory.
You can pack it with your B4A application and use the code in this post to move it from your project's assets folder to your external memory or just plug your device into your computer and use USB to copy it to your device's external memory osmdroid folder.
Do not put it in the tiles folder.
The name of the archive is unimportant - leave it as Tiles.zip or change the name to suit, it makes no difference to OSMDroid.

Now the B4A code:

B4X:
Sub Process_Globals
   Dim MapCenter As GeoPoint
   Dim TileSource As String
   Dim ZoomLevel As Int
End Sub

Sub Globals
   Dim MapView1 As MapView
   Dim NewTileSourceName As String
   Dim TileSourceSpinner As Spinner
End Sub

Sub Activity_Create(FirstTime As Boolean)
   MapView1.Initialize("MapView1")
   
   If FirstTime Then
      MapCenter.Initialize(52.75544, 0.39087)
      ZoomLevel=9
      
      Dim CurrentTilesSources As List
      NewTileSourceName="jparkerri"
      
      CurrentTilesSources=MapView1.GetTileSources
      If CurrentTilesSources.IndexOf(NewTileSourceName)=-1 Then
         '   NewTileSourceName has not yet been added to the MapView
      
         '   create a new TileSource using the Maperitive tiles
         '   i generated tiles for zoom levels 9 to 16
         Dim MyXYTileSource As XYTileSource
         MyXYTileSource.Initialize(NewTileSourceName, 9, 16, 256, ".png", "http://localhost/")
         MapView1.AddXYTileSource(MyXYTileSource)
         
         '   note that after Activity_Pause (orientation change for example) the added TileSource will still exist in the MapView
         '   the added TileSorce will exist until the activity process is destroyed
         '   trying to add a TileSource more than once will not cause problems however - the AddXYTileSource method ensures that the TileSource is only added once
      End If
      
      '   set the default initial TileSource
      TileSource=NewTileSourceName
   End If
   
   TileSourceSpinner.Initialize("TileSourceSelect")
   Activity.AddView(TileSourceSpinner, 0, 0, 100%x, 48dip)
   
   TileSourceSpinner.AddAll(MapView1.GetTileSources)
   TileSourceSpinner.Prompt="Select a TileSource"
   TileSourceSpinner.SelectedIndex=TileSourceSpinner.IndexOf(TileSource)
   '   manually call the Spinner ItemClick Sub to sync the MapView TileSource with the spinner SelectedIndex
   TileSourceSelect_ItemClick(TileSourceSpinner.SelectedIndex, TileSourceSpinner.SelectedItem)
   
   MapView1.SetMultiTouchEnabled(True)
   MapView1.SetZoomEnabled(True)
   MapView1.Zoom=ZoomLevel
   MapView1.SetCenter3(MapCenter)
   Activity.AddView(MapView1, 0, 48dip, 100%x, 100%y-48dip)
End Sub

Sub Activity_Resume
End Sub

Sub Activity_Pause (UserClosed As Boolean)
   MapCenter=MapView1.GetCenter
   ZoomLevel=MapView1.Zoom
   
   '   save the currently selected MapView TileSource
   TileSource=MapView1.GetTileSource
End Sub

Sub TileSourceSelect_ItemClick (Position As Int, Value As Object)
   If Value=NewTileSourceName Then
      MapView1.SetDataConnectionEnabled(False)
   Else
      MapView1.SetDataConnectionEnabled(True)
   End If
   '   set the MapView TileSource
   MapView1.SetTileSource(Value)
End Sub

Works well - i shall be experimenting more with Maperitive over the next few days.

Documentation for the native Android OSMDroid library is pretty much non-existent.
I have javadoc reference for both native Android OSMDroid and my B4A OSMDroid library online here: Index of /b4a/osmdroid/documentation
Other than that remember that Google is your friend LOL!

Martin.
 

jparkerri

Member
Licensed User
Longtime User
Custom tilesource from Maperitive

Thanks for the info. I think I have it working but am not sure what I should be seeing. I made a ZIP file of the Maperitive 'Tiles' folder. The tiles were *.png, not *.png.tile. Is that right or do I have to rename them? I made a copy of the Tiles folder called NewMapnik, then made a ZIP of it called NewMapnik.zip and put that on the Tablet under 'osmdroid'. I get the map detail in my application now under the TileSource called NewMapnik. Should I be seeing a NewMapnik folder under ../osmdroid/tiles with tiles in it? There is none there. So is it just extracting the ZIP file temporarily or isn't it really working? My command is:
MyXYTileSource2.Initialize("NewMapnik", 12, 20, 256, ".png", "http://localhost/").

Thanks.

- Jeff
 

BarrySumpter

Active Member
Licensed User
Longtime User
Yes, the folder osmdroid contains a tile folder based upon the name.
For you based upon the above script would be "jparkerri".
And in the tiles folder is one zoom level folder 17 (for me).
And under that one folder is only ONE 65535.png.tile (for me).

No matter how much I move the map arround and load tiles
there is only the one tile under that folder.

I've deduced that one tile is perhaps a "start up tile".
And my only be from MY version of the app.
 
Last edited:

warwound

Expert
Licensed User
Longtime User
Right one thing at a time...

The tile will need to have the same file extension as used in the MyXYTileSource2.Initialize statement.
There is no need to rename them - .png is perfect.
The reason why some TileSources use .png.tile is to prevent your Android device from finding the tiles and adding them to your Gallery.
Not many users want their Gallery to contain thousands of tile images!

The osmdroid/tiles is where downloaded tiles are cached.
The cached tiles are saved in a folder named after the TileSource.

So if you have a zip tile archive and disable the MapView data connection then the tiles folder will not contain any cached tiles - the MapView fetches all tiles on the fly from the zip archive.

If you don't disable the data connection and you pan and zoom the map to an area where your zip archive contains no tiles then the MapView will try to download those tiles BaseUrl used in the MyXYTileSource2.Initialize statement.

If that BaseUrl is "http://localhost/" and you look at the unfiltered log you will see errors such as Connection refused.
Still nothing should appear in the tiles folder though.
And ideally you should disable the data connection to avoid all these failed requests for tiles.

As for Barry's single tile in the tiles folder...
If you view that tile using Gallery does it fail to load?
Is it a corrupt image file or even a text file containg an error message that has been saved as a tile?

I'd guess that at some point your data connection was enabled and the BaseUrl being used at the time was directing to somewhere that the MapView managed to request a tile from.
The MapView requested a tile and received a response but the response was not a valid tile perhaps?

Try to view that tile let us know if it's a valid image file.

Martin.
 

warwound

Expert
Licensed User
Longtime User
Version 3.21 of OSMDroid supports the TilesOverlay

TilesOverlay is similar to the XYTileSource, you use it to add a new TileSource to your map.
A TilesOverlay however displays on top of the currently selected TileSource.
You use it to add a transparent tile layer to your map.

Take a look at this tile from the OpenSeaMap project:

10962.png


It's a transparent tile created so that it can be displayed on top of another tile layer.
This is the type of tile you'll use a TilesOverlay to display.

Some example code:

B4X:
Sub Process_Globals
End Sub

Sub Globals
   Dim MapView1 As MapView
   Dim TilesOverlay1 As TilesOverlay
End Sub

Sub Activity_Create(FirstTime As Boolean)
   If File.ExternalWritable=False Then
      '   OSMDroid requires the use of external storage to cache tiles
      '   if no external storage is available then the MapView will display no tiles
      Log("WARNING NO EXTERNAL STORAGE AVAILABLE")
   End If
   
   MapView1.Initialize("")
   MapView1.SetMultiTouchEnabled(True)
   MapView1.SetZoomEnabled(True)
   MapView1.Zoom=9
   MapView1.SetCenter(53.024, 0.421)
   Activity.AddView(MapView1, 0, 0, 100%x, 100%y)
   
   '   open sea map tiles are available from zoom levels 11 to 19
   TilesOverlay1.Initialize("SeaMap", 11, 19, 256, ".png", "http://tiles.openseamap.org/seamark/")
   
   '   TilesOverlay1.LoadingBackgroundColor=Colors.LightGray
   '   TilesOverlay1.LoadingLineColor=Colors.DarkGray
   
   MapView1.AddOverlay(TilesOverlay1)
   
End Sub

Sub Activity_Resume
End Sub

Sub Activity_Pause (UserClosed As Boolean)
End Sub

Load the MapView, displaying the default Mapnik tiles and displays the OpenSeaMap tiles on top ofthe Mapnik tiles.

You'll need to pan to an area of sea to see the OpenSeaMap tiles.
(There is a windfarm that should be visible in the demo code).

And you can uncomment the LoadingBackgroundColor and LoadingLineColor lines to experiment with those properties and see how they work.

Note that OpenSeaMap tiles do not exist for many areas and at many zoom levels.
Where an OpenStreetMap tile is requested and it does not exist, the MapView will (internally) generate a 404 tile not found error.
If the LoadingBackgroundColor is set to Colors.TRANSPARENT then no background color is displayed while waiting for a tile to load and there is no problem.
If you set a LoadingBackgroundColor that color is displayed until the requested tile has been downloaded.
So where tiles do not exist and fail to download you will see the background color persist and block the underlying Mapnik tiles.

I have not yet tried offline tiles with a TilesOverlay but it should work - the TilesOverlay should fetch tiles from any tiles archive in the osmdroid folder and display them instead of downloading tiles from the internet.

Martin.
 

Attachments

  • TilesOverlay.zip
    5.8 KB · Views: 534
Last edited:

BarrySumpter

Active Member
Licensed User
Longtime User
That startup tile is a blue green tile
depicting water I'm sure.
I'm curious if I can find 65535 tile in MOBAC.
Or is 65535 an IT number 65536?
Or perhaps its 0,0 lat lon?
i.e. I've touched the map button before the GPS has had a chance to lock in.

Perhaps only the ancient aliens who build atlantis could tell us.
:p

Which brings me to my next todo for this app.
Don't allow map to show without GPS.
And fire GPS as soon as app loads.
Disable GPS as sson as it locks in once.
Then if location changes start it again.
Or is that circular. You have to have GPS on to know loc changes.
Otherwise, if loc does NOT change in say 10 mins turn GPS off until I tap the screen again.
This may assist in battery discharge as well.

And another thought regarding ancient aliens.
There is a "world grid" of energy points.
I wounder where I might find the ley lines for this "world grid"?
I see more research needed.
 
Last edited:

warwound

Expert
Licensed User
Longtime User
That startup tile is a blue green tile
depicting water I'm sure.
I'm curious if I can find 65535 tile in MOBAC.
Or is 65535 an IT number 65536?
Or perhaps its 0,0 lat lon?
i.e. I've touched the map button before the GPS has had a chance to lock in.

Perhaps only the ancient aliens who build atlantis could tell us.
:p

Which brings me to my next todo for this app.
Don't allow map to show without GPS.
And fire GPS as soon as app loads.
Disable GPS as sson as it locks in once.
Then if location changes start it again.
Or is that circular. You have to have GPS on to know loc changes.
Otherwise, if loc does NOT change in say 10 mins turn GPS off until I tap the screen again.
This may assist in battery discharge as well.

And another thought regarding ancient aliens.
There is a "world grid" of energy points.
I wounder where I might find the ley lines for this "world grid"?
I see more research needed.

What's the full path of the tile?

17/?/65535.png

Martin.
 
Top