B4A Library OSMDroid - MapView for B4A

Here we have my latest library - OSMDroid provides a MapView for B4A.

More info on the original (native Android) OSMDroid project can be found here: osmdroid - OpenStreetMap-Tools for Android - Google Project Hosting.

Library reference is no longer included in this post due to limits on the number of characters allowed in a single post.

I have created some tutorials to show basic usage of the library and will update this thread with a link to them as soon as i have them all uploaded.

** Your attention is drawn to the included file Apache License Version 2.0.txt, which is a copy of the Apache License Version 2.0 under which the native Android OSMDroid library is released **

Martin.
 

Attachments

  • OSMDroid_3_0_8_v3.60.zip
    361.9 KB · Views: 4,065
Last edited:

udg

Expert
Licensed User
Longtime User
Thank you, Martin.
I see that 4.1 encloses slf4j 1.61 so I guess it is needed again (if it really was dismissed at some point).

@peacemaker : thank you for your comment.
I don't expect a very high number of concurrent markers so I should be relatively safe on that.
When it comes to a choice like harder+freedom vs. easier+legacy I inevitably go for the former. I can't say it's better; it's just my nature.. :)
 

nemiroG1

Member
Licensed User
Longtime User
I have a couple of file related questions.

1. I know once upon a time this was not possible, but perhaps it now is. Can we specify a location for the osmdroid tile cache path? ie, not /mnt/sdcard/osmdroid? I read through several java posts, where people are seemingly renaming their source directory. I also saw other posts where people are putting symlinks into place to point to a different location, thereby 'fooling' OSMDroid into thinking it is using /mnt/sdcard/osmdroid, when in fact it is pointing where the user wants it to go. Any thoughts or new developments for this? I have found a fairly reliable way of determining the proper path to an external SD card, and would like to store all of my files there. This is just a project for a single type of device/version of Android, at this time.

2. Is it possible to modify an offline cache .zip file, by adding tiles to it, as they are downloaded? This way, any time there is online access, it is constantly "building up" the offline cache file.

Thank you so much for all you do on this project!
 

warwound

Expert
Licensed User
Longtime User
1: The b4a library has no methods to set a custom path for the tile cache.
Has the latest version of the android OSMDroid library finally added this feature?

2: There's no need to add freshly downloaded tiles to any offline tile archive.
The offline tile archive should contains all offline tiles in a folder that is the name of the tile source.
And freshly downloaded tiles should be cached in a folder with the name of the tile source.
OSMDroid should treat the offline tiles and the cached tiles the same and use them where they exist.
 

nemiroG1

Member
Licensed User
Longtime User
1. Do not know the answer to this. I will research more, and try to let you know. However, reading through various threads on the subject, it seems that people are declaring/setting the path in their code. I will try to find some snippets and post up.

2. Is it more advantageous to simply place the map tiles within the directory structure of /mnt/sdcard/osmdroid/tiles/ manually, versus containing them in the .zip file? I understand the convenience of the .zip, but I do not want to bog the whole thing down more than it already is. For my application, I have to keep a ridiculous number of tiles on hand (~9GB!), so that is not installing with the app, at the moment, anyway :) While on that subject, if I use another commercial app, that appears to be using the same maps that I am (Chartbundle), their archive is ~2GB vs mine that is nearly 9GB. Zoom levels appear the same. I suppose they are using some other map source/method besides OSMDroid.


Lastly, I thought it would be fun (ha!) to add in the AHViewPager https://www.b4x.com/android/forum/t...ary-sliding-panels-now-perfect.14165/#content sliding tabs/pager library, and I am pleased to report that OSMDroid seems to be playing nice with it, except that if you scroll away too far, and it 'destroys' the page with the Mapview on it, when you come back, the map will no longer update tiles from the online source. Changing map tile sources does not seem to kick it back into gear. Only killing the app and restarting. It will still take updates from GPS, and all other functions work OK. It just won't grab any more tiles from the internet. Is it proper to completely re-initialize the whole mapview, or is there some other way to kick it back in to action?
 

warwound

Expert
Licensed User
Longtime User
Tiles in an archive must need a certain amount of processing - the map needs to extract them from the zip archive.
There's no processing overhead with tiles just cached to the file system BUT storing many small files this way is inefficient.
The file system is likely to be formatted using a FAT32 file system.
FAT32 file systems have a cluster size that defines the minimum amount of space a file will occupy.
Let's say the cluster size is 16KB.
Every tile will occupy at least 16KB of space and always occupy a multiple of 16KB.
Look at your tile sizes - can you see how a large number of small tiles will occupy a large amount of space?
FAT32 also has limits on the number of files that can be stored in a single directory - i read on one site that the limit is 268,173,300.
That might or might not be a problem with directories containing many tiles.

Search the forum for MBTiles.
This is an alternative format for offline tiles.
One advantage of the MBTiles format is that it tries to reduce or eliminate duplicate tiles.
For example, if you have an area of sea you will likely have many identical tiles for many tile positions and many zoom levels.
MBTiles is a solution for this.
Reducing the number of identical tiles might significantly reduce the size of your tile archive.

The b4a OSMDroid library currently has no support for MBTiles.
I could add support for MBTiles - as long as i can find some code examples that show how to implement it.

With AHViewPager i think re-initializing the entire MapView again is the only solution that will work.
It gets destroyed when scrolled more than 1 page away so must be re-created and re-initialized.
Though i seem to remember that you could specify how many pages the AHViewPager keeps in memory at any one time.
If the default is 3 pages - the current page and pages to the left and right of the current page.
If that number could be increased you might be able to avoid the page containing the MapView being destroyed.
 

nemiroG1

Member
Licensed User
Longtime User
Thank You! I have been working this whole evening, and just stumbled upon re-initializing. I am having trouble with it resetting to the default tile source, zoom, and overlay settings. I can probably resolve it, but if I can simply get AHPager to not kill it in the first place, I'd be in great shape. I have five pages, and the mapview is on Page 0. It's getting late, so I will work on it in the morning. As usual, thank you, Martin!
 

nemiroG1

Member
Licensed User
Longtime User
It might be possible using JavaObject.
Can you post in the AHViewPager thread? - I'm sure this has been asked before.


Something similar has been posted, but it didn't work, unfortunately. I have posted asking the question.

If I do have to re-initialize the mapview, what is the best way to go about it? ie, should I completely start over, or are there a subset of commands that should be used, just to keep it down a bit?
 

warwound

Expert
Licensed User
Longtime User
Something similar has been posted, but it didn't work, unfortunately. I have posted asking the question.

If I do have to re-initialize the mapview, what is the best way to go about it? ie, should I completely start over, or are there a subset of commands that should be used, just to keep it down a bit?

I think you'll have to call the MapView Initialize method and completely re-create you map - setting it all up just as if it was being created for the first time.
 

nemiroG1

Member
Licensed User
Longtime User
I think you'll have to call the MapView Initialize method and completely re-create you map - setting it all up just as if it was being created for the first time.
That's what I thought. Working on it right now.


Edit:
Got it working. Thanks, again, Martin! It is a bit slow on the reload, so I will continue on the path to try to get AHPager to keep pages in memory.
 
Last edited:

nemiroG1

Member
Licensed User
Longtime User
Martin,
Did solve my problem above by re-initializing the mapview completely. It is a bit slow, but it does work. Since then, I have also been able to keep AHViewPager to allow more pages in memory, which also solved the problem. However, it does seem that OSMDroid will stop downloading tiles randomly. I have not isolated the exact circumstances that causes this. When I do, I will let you know.


Back to an earlier question, on using the external SDCard to keep the osmdroid tiles folder. I did some searching, and it seems that this had been a problem for several people. Understand that the file path has been hard coded in, in several locations in the code. The brute force method people seem to use is to go in, and reset those hard coding points. Would it not make more sense to change those hard points to a variable that must be declared in the app itself? With that in mind, here's what I have found for other efforts on this issue:

http://code.google.com/p/osmdroid/issues/detail?id=174

In this one, they talk about modifying the tilesource provider. Not sure if we could do some trickery there, where we would initially specify a tile provider we want to use, an then somehow declare a new one that points to the path we want to get it from. Have also thought that perhaps we need to have two instances of a mapview running. One going to the online source, and have it constantly "feed" to a path of our choosing, then have a second instance running that only works offline, grabbing tiles from that specified path? Completely inefficient, but it may prove the concept - perhaps. Anyway, there's this:
http://code.google.com/p/osmdroid/issues/detail?id=234

Then there are these discussions:
http://stackoverflow.com/questions/16120811/how-to-use-osm-offline-maps-saved-on-external-sd
https://groups.google.com/forum/#!topic/osmdroid/2QeSmFMxpvQ


I am taking a crack at compiling OSMDroid myself, just to know how the process works. I see there are some patches and commits that address this issue on Github.
 

warwound

Expert
Licensed User
Longtime User
I am taking a crack at compiling OSMDroid myself, just to know how the process works. I see there are some patches and commits that address this issue on Github.

I won't have time to look at the info on changing the cache path this weekend.
If you'd like copy of the OSMDroid b4a library source then let me know.

Martin.
 

hibrid0

Active Member
Licensed User
Longtime User
Hi Martin, thanks for shared this amazing library.
I like to know how can I change the person icon with SimpleLocationOverlay
 

warwound

Expert
Licensed User
Longtime User
There is only a hackish way to change that icon.
You'd need to open the OsmDroid library .jar file and find the person.png image - in the /org/osmdroid/ folder i think.
So you'd open the .jar with WinRAR or 7zip etc and replace person.png with your own image.
Close the .jar file and recompile your app.
 

PABLO2013

Well-Known Member
Licensed User
Longtime User
greetings, I think I asked this several times , I do not understand if i should not ask ... and if this is not a prohibited question ... as might remove the line connecting two polygons drawn in the same pathoverlay .. .with only a small orientation I think we can resolve the rest , thanks
 

Attachments

  • line.png
    line.png
    5.9 KB · Views: 174

gravel

Member
Licensed User
Longtime User
There was some discussion about Custom Markers being displayed at the wrong size, in this thread and here. https://www.b4x.com/android/forum/threads/mapview-overlay-marker-image-too-large.30629/

I had this difficulty, and Martin's solution https://www.b4x.com/android/forum/threads/osmdroid-mapview-for-b4a.16309/page-3#post-115572
didn't fix it.

I see an OSMDroid issue https://code.google.com/archive/p/osmdroid/issues/331
which seems to accurately describe the problem, and was apparently resolved by revision r1099 of OSMDroid 3.0.8.

I've tried OSMDroid 4.1 and Custom Markers are correctly sized.

Is OSMDroid MapView 3.0.8 from a build prior to r1099?
 
Top