Enroute Flight Navigation
A navigation app for VFR pilots
GeoMaps::TileServer Class Reference

HTTP server for mapbox' MBTiles files. More...

#include <TileServer.h>

Public Slots

void addMbtilesFileSet (const QString &baseName, const QVector< QSharedPointer< FileFormats::MBTILES > > &MBTilesFiles)
 Add a new set of tile files.
void removeMbtilesFileSet (const QString &baseName)
 Removes a set of tile files.
void removeMbtilesFileSets ()
 Removes a set of tile files.

Signals

void serverUrlChanged ()
 Notification signal for the property with the same name.

Public Member Functions

 TileServer (QObject *parent=nullptr)
 Create a new tile server.
QString serverUrl ()
 Getter function for the property with the same name.

Properties

QString serverUrl
 URL under which this server is presently reachable.

Detailed Description

HTTP server for mapbox' MBTiles files.

This class features a simple HTTP server that serves the following files to serverUrl()/path. On Android the server listens on a local socket and the URL has the form unix+http://<socket name>; everywhere else it listens on a TCP port on the loopback interface and the URL has the form http://127.0.0.1:<port>. See the constructor for the reason. The client side is QNetworkAccessManager, which handles both schemes.

  • If path is a file name, the server checks if the file is available in the resource system of the app and serves that file.
  • If path is of the form "flightMap/sprites-night/xyz", the server serves a night-mode version of the flight map sprite sheet found in the resource system under "flightMap/sprites/xyz". The JSON files are served unchanged, the PNG files are recolored for use over the dark map style.
  • If path equals "aviationData.geojson", the server returns a GeoJSON document that contains the full aviation data, as provided by GlobalObject::geoMapProvider()->geoJSON(). The reply carries a "Cache-Control: no-cache, must-revalidate" header, because the document changes with every aviation map update while its URL stays the same, and the map renderer would otherwise keep rendering a cached copy.
  • If path equals the base name of an MBTilesFileSet, then the server returns a JSON document describing the MBTiles.
  • If path equals "baseName/z/x/y.XXX", then the server returns an individual tile from the tile set.

This server is able to handle several sets of MBTiles files. Each set is available under a single URL, and the MBTile files in each set are expected to contain identical metadata. To serve a tile request, the server goes through the MBTiles files in random order and serves the first tile it can find. Tiles contained in more than one file need thus to be identical. A typical use case would be a server that contains to sets of files, one set with vector tiles containing openstreetmap data and one set with raster data used for hillshading. Each set contains two MBTiles files, one for Africa and one for Europe.

Definition at line 70 of file TileServer.h.

Constructor & Destructor Documentation

◆ TileServer()

GeoMaps::TileServer::TileServer ( QObject * parent = nullptr)
explicit

Create a new tile server.

The tile server listens on a local socket (Android) or finds a free port and listens to 127.0.0.1:port (all other platforms). The method serverUrl() returns the precise Url where the server will be available.

Parameters
parentThe standard QObject parent

Member Function Documentation

◆ addMbtilesFileSet

void GeoMaps::TileServer::addMbtilesFileSet ( const QString & baseName,
const QVector< QSharedPointer< FileFormats::MBTILES > > & MBTilesFiles )
slot

Add a new set of tile files.

This method adds a new set of tile files, that will be available under serverUrl()+"/baseName" (typically, this is a URL of the form 'unix+http://enroute-tiles-12345/basename' or 'http://127.0.0.1:3470/basename').

Parameters
baseNameThe path under which the tiles will be available.
MBTilesFilesThe name of one or more mbtile files on the disk, which are expected to conform to the MBTiles Specification 1.3 (https://github.com/mapbox/mbtiles-spec/blob/master/1.3/spec.md). These files must exist until the file set is removed or the sever is destructed, or else replies to tile requests will yield undefined results. The tile files are expected to agree in their metadata, and the metadata (attribution, description, format, name, minzoom, maxzoom) is read only from one of the files (a random one, in fact). If a tile is contained in more than one of the files, the data is expected to be identical in each of the files.

◆ removeMbtilesFileSet

void GeoMaps::TileServer::removeMbtilesFileSet ( const QString & baseName)
inlineslot

Removes a set of tile files.

Parameters
baseNamePath of tiles to remove

Definition at line 144 of file TileServer.h.

◆ removeMbtilesFileSets

void GeoMaps::TileServer::removeMbtilesFileSets ( )
inlineslot

Removes a set of tile files.

Parameters
baseNamePath of tiles to remove

Definition at line 150 of file TileServer.h.

◆ serverUrl()

QString GeoMaps::TileServer::serverUrl ( )
nodiscard

Getter function for the property with the same name.

Returns
Property serverUrl

Property Documentation

◆ serverUrl

QString GeoMaps::TileServer::serverUrl
read

URL under which this server is presently reachable.

The property holds the Url where the server is listening to incoming connections. This is a string of the form "unix+http://enroute-tiles-12345" on Android and "http://127.0.0.1:3470" elsewhere. If the server is not listening to incoming connections, the string is empty.

Definition at line 102 of file TileServer.h.


The documentation for this class was generated from the following file: