I spent last week and part of this one making tests to see how Marble gets on with Vector Tiles. There are vector tiles up to 5.8MB size depending on the planet zone and its detail level, so the need for a new logic for storing and managing tiles was obvious.
As talked in the previous blog entrance, TextureLayer keeps all the image tiles in memory and that would be impossible for vector tiles. Depending on the map projection selected (Marble’s map can be viewed as a Globe, Plane Map or Mercator) image tiles had three different mappers that “blended” the images to fit the map and a logic for downloading image tiles. In our case, parsed geometries are inserted into Marble’s treeModel which takes care of those three projections so we didn’t have to worry about that and it made possible to create a single mapper (VectorTileMapper) and create it’s logic in it.
When VectorTileLayer detects the map has moved, currently asks the VectorTileMapper to download all the tiles contained inside the screen’s LatLonBox and according to the screen’s zoom level. The following functions translate latitude and longitude coordinates to OpenStreetMaps X and Y coordinates.
int VectorTileMapper::RenderJob::lon2tilex(double lon, int zoom)
{ return (int)(floor((lon + 180.0) / 360.0 * pow(2.0, zoom))); }
int VectorTileMapper::RenderJob::lat2tiley(double lat, int zoom)
{ return (int)(floor((1.0 – log( tan(lat * M_PI/180.0) + 1.0 / cos(lat * M_PI/180.0)) / M_PI) / 2.0 * pow(2.0, zoom))); }
VectorTileMapper will ask Marble’s TileLoader for those tiles and the TileLoader will work as usual returning the StackedTile (if it was already parsed and stored in TileLoaders cache) or downloading, creating a new StackedTile from parsing the file, storing it in its cache and returning it. VectorTileMapper will then send the tile to VectorTileLayer.
Now that the tiles have arrived to the layer, their GeoDataDocuments are inserted into the TreeModel to be displayed and also to the layers QCache that will manage the displaying geometries. Currently for testing, everytime the map is moved, this QCache checks if the displaying GeoDataDocuments intersect with the screen’s LatLonBox and if they don’t they are removed from the TreeModel. For testing also, when changing between zoom levels, all GeoDataDocuments are removed from the TreeModel and QCache is cleared.
Here is a video test with the current status.
As you can see, although not downloading all the tiles in the screen sometimes it is difficult to move the map because Amsterdam has big detail level. Now we will have to start adjusting the download logic (to download more “neighbour” tiles), the parser and how many tiles can be kept in cache to find a performance balance.
