B4A Library OSMDroid - MapView for B4A

Discussion in 'Additional libraries, classes and official updates' started by warwound, Mar 26, 2012.

  1. peacemaker

    peacemaker Well-Known Member Licensed User

    I use OSMdroid lib v.3.x in some game, where markers are the main part, represent the gamers and their bases. Tested with qty up to about 100 markers. I have to say that OSM is very "heavy" solution, need lot's of memory, app is slow very often even on modern devices (even with several markers). OutOfMemory error is regular thing, ecpecially on Android 4.0.x.
    But no implementing limitations, comparing to Google Maps.
    But Google Map v.2 requiring the registration and existing Google Services - works with 500 markers without any speed issues.
     
  2. udg

    udg Expert Licensed 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.. :)
     
  3. nemiroG1

    nemiroG1 Member Licensed 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!
     
  4. warwound

    warwound Expert Licensed 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 likes this.
  5. nemiroG1

    nemiroG1 Member Licensed 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 http://www.b4x.com/android/forum/th...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?
     
  6. warwound

    warwound Expert Licensed 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 likes this.
  7. nemiroG1

    nemiroG1 Member Licensed 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!
     
  8. nemiroG1

    nemiroG1 Member Licensed User

  9. warwound

    warwound Expert Licensed User

    nemiroG1 likes this.
  10. nemiroG1

    nemiroG1 Member Licensed 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?
     
  11. warwound

    warwound Expert Licensed 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.
     
    nemiroG1 likes this.
  12. nemiroG1

    nemiroG1 Member Licensed User

    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: Mar 16, 2015
  13. nemiroG1

    nemiroG1 Member Licensed 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.
     
  14. warwound

    warwound Expert Licensed User

    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.
     
    nemiroG1 likes this.
  15. nemiroG1

    nemiroG1 Member Licensed User

    Martin,
    Would Love to try this! I PM'd you.
     
  16. BarryW

    BarryW Active Member Licensed User

    How to download the complete mapnik tiles? Tnx...
     
  17. warwound

    warwound Expert Licensed User

    Search the forum for mobac.
    It's a program that allows you to download tiles and create offline tile archives.
     
  18. hibrid0

    hibrid0 Active Member Licensed User

    Hi Martin, thanks for shared this amazing library.
    I like to know how can I change the person icon with SimpleLocationOverlay
     
  19. warwound

    warwound Expert Licensed 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.
     
    hibrid0 likes this.
  20. PABLO2013

    PABLO2013 Active Member Licensed 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
     

    Attached Files:

Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice