QtLocation: using offline map tiles with the OpenStreetMap plugin

Published Wednesday May 24th, 2017
7 Comments on QtLocation: using offline map tiles with the OpenStreetMap plugin
Posted in Dev Loop, Qt Location

The OpenStreetMap plugin in QtLocation 5.8 has received a new Plugin Parameter, osm.mapping.offline.directory, to specify a indexable location from which to source offline tiles. Since this new feature seems to have generated some confusion, here is an attempt to clarify how it works.

Until now, when a tile became visible on the map, the QtLocation engine would first attempt to source it from the tile cache. If not present, it would attempt to fetch it from the provider.

With QtLocation 5.8 it is possible to pass an additional offline directory to the OSM plugin. When this parameter is present, tiles will be sourced from the specified directory before being searched in the tile cache, and, after that, being requested to the provider.

The content of such an offline directory is read only, for QtLocation, meaning that the engine will not add, delete or update tiles present therein. Tile filenames have to follow the osm plugin filename pattern, meaning osm_100-<l|h>-<map_id>-<z>-<x>-<y>.<extension>.

The field map_id goes from 1 to 7 (or 8, if a custom map type is specified), referring to the map types street, satellite, cycle, transit, night-transit, terrain and hiking, in this order.
The field before has to contain an l or an h, which stands low-dpi and high-dpi tiles, respectively.

The intended use cases that this feature aims to address are mainly:
– shipping custom maps for limited regions with the application.
– shipping tiles for low zoom levels with the application so to prevent blank maps when the application is run for the first time without internet connection.

To exemplify the usage of this feature, OsmOffline is an example application that uses tiles from the Natural Earth project, which are licensed under very permissive TOS, to address the second scenario.
This example embeds tiles for one map type at zoom levels 0, 1 and 2 using the Qt Resource system, and sources them from the qrc path :/offline_tiles/.

Do you like this? Share it
Share on LinkedInGoogle+Share on FacebookTweet about this on Twitter

Posted in Dev Loop, Qt Location


David says:

Does this new plugin parameter work for the Mapbox plugin as well.

Paolo Angelelli says:

No, this is specific to the Osm plugin.

David says:

Thank you for the reply. Is there a license restriction that stops you from implementing it for the Mapbox plugin. And if one wants this for Mapbox and one has a commercial license for Qt is it legal to implement it yourself.

Paolo Angelelli says:

I believe that Mapbox allows that, at least for certain plans, but you should double check this information on the Mapbox TOS page.
It would be certainly possible to add the same feature to that plugin by yourself (with the same limitations, and given that it truly does not offend Mapbox TOS), or to contribute it to Qt 🙂

tham says:

Nice feature, any plan to support offline routing?

Paolo Angelelli says:

It’s in the roadmap, but without a set date or release. For this, as well, we welcome contributions 🙂

Jacob Kenin says:

Thank god, this explanation was well needed. This functionality is awesome, it was just a struggle for those of us outside the hardcore GIS niche to figure out how the directory / file structure needed to be setup.

Commenting closed.

Get started today with Qt Download now