This geo services plugin integrates Maplibre mapping library into the Qt Location API.
This plugin differs from all the other plugins because it uses the Maplibre map engine for rendering vector tiles in real-time. The benefits are: text staying upright, font antialiasing, labels flowing between zoom levels, smooth pan, tilt, rotation and continuous zoom.
The appearance and behavior of vector maps can be customized by creating custom map styles. This can be done with tools like Mapbox Studio.
The Maplibre geo services plugin can be loaded by using the plugin key "maplibre".
This plugin requires custom backend or service provider for providing vector tiles. Read more OpenMaptiles about setting up custom backend.
Note: This API uses the {https://github.com/maplibre/maplibre-native-qt/tree/v3.0.0}{Maplibre} 3.0.0 version.
Qt Location Maplibre Plugin has the following support for platforms:
The following table lists optional parameters that can be passed to the Maplibre plugin.
| Parameter | Description |
|---|---|
| maplibre.api.provider | Different backends (tile providers) have different ways to serve information. Base URL, HTTP paths for style, fonts, tiles, etc. Maplibre library has predefined sets of settings for most popular providers. This parameter can be used to use one of these predefined settings for values "mapbox", "maptiler" or "maplibre". |
| maplibre.api.key | Access token, if needed by service provider. |
| maplibre.api.base_url | Set a custom API base URL. When not set, the URL defaults to the value set by maplibre.api.provider. |
| maplibre.map.styles | Additional, comma separated, style URLs to be added to the available style URLs. Additional styles will be appended to the supportedMapTypes property of the Map item. |
| maplibre.cache.directory |
Absolute path to map tile cache directory used as network disk cache.
The default place for the cache is the This is an ambient cache, meaning it will get populated on the fly until it reaches the size limit, and when that happens, it will evict the least used tiles. |
| maplibre.cache.memory | Whether or not the cache should be in-memory only. Valid values are true and false. The default value is false. When set to true, the disk cache is never created. The ambient cache will work in-memory, but the offline database cannot be used with this option enabled. |
| maplibre.cache.size | Cache size for map resources in bytes. The default size of this cache is 50 MiB. |
| maplibre.items.insert_before | Some map items such as MapPolyline, MapPolygon and MapRectangle will be rendered after the topmost layer of the style. With this parameter set, the map items will be rendered before the layer ID specified, unless the layer is not present on the current style, which will fallback to the default behavior. This parameter can be used to display route lines under labels. |
| maplibre.client.name | The name of the client |
| maplibre.client.version | The version of the client |
The Map item using this plugin, can also be customized using {https://maplibre.org/maplibre-native-qt/docs/classStyle.html}{StyleParameters}, allowing runtime changes to the map style and data.
Examples of what can be currently controlled using {https://maplibre.org/maplibre-native-qt/docs/classStyle.html}{StyleParameters} are:
With the exception of extrusion and data driven style properties, every property described at the Maplibre Style Specification can be changed at runtime.
The {https://maplibre.org/maplibre-native-qt/docs/classStyle.html}{StyleParameters}, used to control the style of the map at runtime, always have a type property and a styleId property, followed by user defined properties that try to match the Maplibre Style Specification naming as much as possible, replacing the dash with camel case for technical reasons (i.e. line-cap will be translated to lineCap).
| Parameter type | Description |
|---|---|
| A style data source. When using a source of sourceType geojson, the data property can be both inlined or sourced from qrc. Supported source types are: vector, raster, raster-dem, image and geojson. | |
| Adds a new style layer to the map. On a Maplibre map, layers are used in styles for adding styling rules to specific subsets of data. A layer will contain a reference to the data for which they are defining a style. Use the before attribute to insert a layer before an existing layer. | |
| Adds a sprite to the map to be used by a style layer. This property is required if any style layer uses the properties such as backgroundPattern, fillPattern, linePattern, or iconImage. | |
| A filter selects specific features from a layer. This can be used for adding a layer from a GeoJSON source based on specific parts of the data source, like by using only the points in the GeoJSON. |
This is an example of how to use the Style item.
MapView {
id: mapView
anchors.fill: parent
map.plugin: Plugin {
id: mapPlugin
name: "maplibre"
PluginParameter {
name: "maplibre.map.styles"
value: "https://demotiles.maplibre.org/style.json"
}
}
map.zoomLevel: 5
map.center: QtPositioning.coordinate(41.874, -75.789)
MapLibre.style: Style {
id: style
SourceParameter {
id: radarSourceParam
styleId: "radar"
type: "image"
property string url: "https://maplibre.org/maplibre-gl-js/docs/assets/radar1.gif"
property var coordinates: [
[-80.425, 46.437],
[-71.516, 46.437],
[-71.516, 37.936],
[-80.425, 37.936]
]
}
LayerParameter {
id: radarLayerParam
styleId: "radar-layer"
type: "raster"
property string source: "radar"
paint: {
"raster-opacity": 0.9
}
}
}
}
Note that the order we add the parameters is important, because there is dependency between the parameters. Adding a layer before adding a source will create an invalid layer, same goes for adding a paint property for a layer that doesn't exist.
Paint and layout properties can also be used for styling existing layers of the current style, and not only layers created at runtime. Mapbox Studio can be used for inspecting layers of a given style.