2

I downloaded a payed .mbtiles file from Open Street Map and managed to create nice maps using openmaptiles-server over Kitematic.

However, I would like to use this .mbtiles file as offline repository of tiles in an Android based application I'm writing.

My plans are to have the mbtiles file stored on an SD card, and let osmdroid MapView read it from there.

However, the file doesn't contain (apparently..) the styling information on its own.

My question is how do I add a styling info such as "OSM Bright" or "Klokantech Basic" to my project so the map on my application looks like a proper map

Many thanks

Haggai
  • 458
  • 1
  • 5
  • 13
  • Osmdroid supports only bitmap tiles so it's not possible to attach style to your mbtiles file (it contains in the end only a lot of png files which are already rendered according to some style). What kind of tiles do you have? Are they bitmap, or vector? In general you need to obtain properly styled bitmap tiles in order to be able to use osmdroid. One way is to render them from openstreetmap database data. – Josef Adamcik Oct 31 '18 at 16:30
  • Thanks @JosefAdamcik. This is the way I'm going now - but in order to support zoom 16-17 I need huge amount of disk space, while the original .mbtiles file is less than 1GB. I was wandering if there is a way to hold only the mbtiles file, and extract the PNG files on the fly (the way the Docker / Kitematic / opentiles-server are doing it) – Haggai Nov 01 '18 at 05:50
  • First: there is not much more in a mbtiles file than those images (it's a sqlite database with a little bit of metadata and PNGs). It can be actually replaced just by proper directory structure on a server. – Josef Adamcik Nov 01 '18 at 12:51
  • Second: I do not have any personal experience with your setup (with opentiles-server in particular) but I am quite sure that on-the fly generation of tiles on the server should be possible with mod_tiles ( check https://wiki.openstreetmap.org/wiki/Mod_tile ) and it seems that the opentiles-server usese it. But you may already now that. I am mentioning this just for the sake of completness. – Josef Adamcik Nov 01 '18 at 13:01
  • Third: You can combine offline(mbtiles) and online tiles, for example smaller mbtiles for lower zooms, and online on the fly generated for those more detialed zooms (16-17). It's just a matter of configuration of the osmdroid library in your app. – Josef Adamcik Nov 01 '18 at 13:05
  • Fourth: as I am reading my comments again I am starting to realize what you actually meant and what is your problem. So my previous comments are actually not relevant that much and I am answering something a little bit different. Sorry for that, but that's why I didn't try to write a propres response. – Josef Adamcik Nov 01 '18 at 13:07
  • I'll try to formualet proper response to that. – Josef Adamcik Nov 01 '18 at 13:10

1 Answers1

1

It's not possible to render bitmap tiles on a device just from information contained in mbtiles data file.

What actually is a mbtiles file?

A mbtiles file is just an SQLite database which contains a very little amount of metadata and rendered bitmap images - tiles Those are the same bitmap files you would be serving online from your openmaptiles-server.

Size of mbtiles file versus size of tiles

MBtiles file size should be almost the same as the overall size of all generated files on your mbtiles server (it's the same number of tiles in each zoom level and the same number of pixels in each tile). If you see a significant difference, it may mean that your mbtiles file doesn't contain the same zoom range (e.g. it doesn't actually contain those most detailed zoom levels) or it contains a smaller area. Some difference may be also caused by a compression algorithm of contained bitmaps and here the actual styling of tiles may play some role (some bitmaps may be easier to compress a resulting PNG may be smaller.

It may be also possible, that the mbtiles file actually contains another image format (jpeg).

If you want to explore what is actually contained in the downloaded mbtiles file, try this tool.

Solution

I don't' think there is a solution when you need to use bitmap tiles. You need to either generate them on a server and download them via network, or you need to prerender them and pack into a mbtile file and download that to a device somehow.

One possible solution would be to use vector maps. It's actually possible to generate vector tiles from Openstreetmap data. Such tiles are than rendered on a device and can actually be styled on the device too.

Unfortunately, Osmdroid library does not support vector tiles at the time of writing (AFAIK). You would have to choose a different map rendering library.

Josef Adamcik
  • 5,620
  • 3
  • 36
  • 42