MapLibre Native for Qt
Loading...
Searching...
No Matches
QMapLibre::Map Class Reference

The Map class is a Qt wrapper for the MapLibre Native engine. More...

#include <QMapLibre/Map>

Inheritance diagram for QMapLibre::Map:

Public Types

enum  MapChange {
  MapChangeRegionWillChange = 0 , MapChangeRegionWillChangeAnimated , MapChangeRegionIsChanging , MapChangeRegionDidChange ,
  MapChangeRegionDidChangeAnimated , MapChangeWillStartLoadingMap , MapChangeDidFinishLoadingMap , MapChangeDidFailLoadingMap ,
  MapChangeWillStartRenderingFrame , MapChangeDidFinishRenderingFrame , MapChangeDidFinishRenderingFrameFullyRendered , MapChangeWillStartRenderingMap ,
  MapChangeDidFinishRenderingMap , MapChangeDidFinishRenderingMapFullyRendered , MapChangeDidFinishLoadingStyle , MapChangeSourceDidChange
}
 
enum  MapLoadingFailure { StyleParseFailure , StyleLoadFailure , NotFoundFailure , UnknownFailure }
 
enum  NorthOrientation { NorthUpwards , NorthRightwards , NorthDownwards , NorthLeftwards }
 

Public Slots

void render ()
 Render.
 
void setConnectionEstablished ()
 Set connection established.
 
void startStaticRender ()
 Start the static renderer.
 

Signals

void needsRendering ()
 Signal emitted when the rendering is needed.
 
void mapChanged (Map::MapChange)
 Signal emitted when the map has changed.
 
void mapLoadingFailed (Map::MapLoadingFailure, const QString &reason)
 Signal emitted when a map loading failure happens.
 
void copyrightsChanged (const QString &copyrightsHtml)
 Signal emitted when the copyrights have changed.
 
void staticRenderFinished (const QString &error)
 Signal emitted when a static map is fully drawn.
 

Public Member Functions

 Map (QObject *parent=nullptr, const Settings &settings=Settings(), const QSize &size=QSize(), qreal pixelRatio=1)
 Main constructor for Map.
 
QString styleJson () const
 Get the map style JSON.
 
QString styleUrl () const
 Get the map style URL.
 
void setStyleJson (const QString &)
 Set a new style from a JSON.
 
void setStyleUrl (const QString &)
 Set the map style URL.
 
double latitude () const
 Get the map latitude.
 
void setLatitude (double latitude)
 Set the map latitude.
 
double longitude () const
 Get the map longitude.
 
void setLongitude (double longitude)
 Set the map longitude.
 
double scale () const
 Get the map scale factor.
 
void setScale (double scale, const QPointF &center=QPointF())
 Set the map scale factor.
 
double zoom () const
 Get the map zoom factor.
 
void setZoom (double zoom)
 Set the map zoom factor.
 
double minimumZoom () const
 Get the minimum zoom level allowed for the map.
 
double maximumZoom () const
 Get the maximum zoom level allowed for the map.
 
double bearing () const
 Get the bearing angle.
 
void setBearing (double degrees)
 Set the bearing angle.
 
void setBearing (double degrees, const QPointF &center)
 Set the bearing angle.
 
double pitch () const
 Get the pitch angle.
 
void setPitch (double pitch)
 Set the pitch angle.
 
void pitchBy (double pitch)
 Pitch the map for an angle.
 
NorthOrientation northOrientation () const
 Get the map north orientation mode.
 
void setNorthOrientation (NorthOrientation)
 Set the north orientation mode.
 
Coordinate coordinate () const
 Get the map center coordinate.
 
void setCoordinate (const Coordinate &coordinate)
 Set the map center coordinate.
 
void setCoordinateZoom (const Coordinate &coordinate, double zoom)
 Convenience method for setting the coordinate and zoom simultaneously.
 
void jumpTo (const CameraOptions &)
 Atomically jump to the camera options.
 
void setGestureInProgress (bool inProgress)
 Set gesture in progress status.
 
void setTransitionOptions (qint64 duration, qint64 delay=0)
 Set transition options.
 
void addAnnotationIcon (const QString &name, const QImage &sprite)
 Add an annotation icon to the map.
 
AnnotationID addAnnotation (const Annotation &annotation)
 Add an annotation to the map.
 
void updateAnnotation (AnnotationID id, const Annotation &annotation)
 Update an existing annotation.
 
void removeAnnotation (AnnotationID id)
 Remove an existing annotation.
 
bool setLayoutProperty (const QString &layerId, const QString &propertyName, const QVariant &value)
 Set layer layout property.
 
bool setPaintProperty (const QString &layerId, const QString &propertyName, const QVariant &value)
 Set layer paint property.
 
bool isFullyLoaded () const
 Get loaded state.
 
void moveBy (const QPointF &offset)
 Pan the map by an offset.
 
void scaleBy (double scale, const QPointF &center=QPointF())
 Scale the map.
 
void rotateBy (const QPointF &first, const QPointF &second)
 Rotate the map.
 
void resize (const QSize &size)
 Resize the map.
 
QPointF pixelForCoordinate (const Coordinate &coordinate) const
 Get pixel for coordinate.
 
Coordinate coordinateForPixel (const QPointF &pixel) const
 Get coordinate for pixel.
 
CoordinateZoom coordinateZoomForBounds (const Coordinate &sw, const Coordinate &ne) const
 Get the coordinate and zoom for required bounds.
 
CoordinateZoom coordinateZoomForBounds (const Coordinate &sw, const Coordinate &ne, double bearing, double pitch)
 Get the coordinate and zoom for required bounds with updated bearing and pitch.
 
void setMargins (const QMargins &margins)
 Set the map margins.
 
QMargins margins () const
 Get the map margins.
 
void addSource (const QString &id, const QVariantMap &params)
 Add a style source.
 
bool sourceExists (const QString &id)
 Check if a style source exists.
 
void updateSource (const QString &id, const QVariantMap &params)
 Update a style source.
 
void removeSource (const QString &id)
 Remove a style source.
 
void addImage (const QString &id, const QImage &sprite)
 Add a style image.
 
void removeImage (const QString &id)
 Remove a style image.
 
void addCustomLayer (const QString &id, std::unique_ptr< CustomLayerHostInterface > host, const QString &before=QString())
 Add a custom style layer.
 
void addLayer (const QString &id, const QVariantMap &params, const QString &before=QString())
 Add a style layer.
 
bool layerExists (const QString &id)
 Check if a style layer exists.
 
void removeLayer (const QString &id)
 Remove a style layer.
 
QVector< QString > layerIds () const
 List all existing layers.
 
void setFilter (const QString &layerId, const QVariant &filter)
 Set a style filter to a layer.
 
QVariant getFilter (const QString &layerId) const
 Get a style filter of a layer.
 
void createRenderer ()
 Create the renderer.
 
void destroyRenderer ()
 Destroy the renderer.
 
void setOpenGLFramebufferObject (quint32 fbo, const QSize &size)
 Set the OpenGL framebuffer object.
 

Properties

double latitude
 The map's current latitude in degrees.
 
double longitude
 The map current longitude in degrees.
 
double zoom
 the map zoom factor.
 
double bearing
 the map bearing in degrees.
 
double pitch
 the map pitch in degrees.
 
QString styleJson
 The map's current style JSON.
 
QString styleUrl
 The map's current style URL.
 
double scale
 The map scale factor.
 
QMapLibre::Coordinate coordinate
 The map center coordinate.
 
QMargins margins
 the map margins in pixels from the corners of the map.
 

Detailed Description

The Map class is a Qt wrapper for the MapLibre Native engine.

Map is a Qt friendly version the MapLibre Native engine using Qt types and deep integration with Qt event loop. Map relies as much as possible on Qt, trying to minimize the external dependencies. For instance it will use QNetworkAccessManager for HTTP requests and QString for UTF-8 manipulation.

Map is not thread-safe and it is assumed that it will be accessed from the same thread as the thread where the OpenGL context lives.

Member Enumeration Documentation

◆ MapChange

This enum represents the last changed occurred to the map state.

See also
mapChanged()
Enumerator
MapChangeRegionWillChange 

A region of the map will change, like when resizing the map.

MapChangeRegionWillChangeAnimated 

Not in use by Map.

MapChangeRegionIsChanging 

A region of the map is changing.

MapChangeRegionDidChange 

A region of the map finished changing.

MapChangeRegionDidChangeAnimated 

Not in use by Map.

MapChangeWillStartLoadingMap 

The map is getting loaded. This state is set only once right after Map is created and a style is set.

MapChangeDidFinishLoadingMap 

All the resources were loaded and parsed and the map is fully rendered. After this state the mapChanged() signal won't fire again unless the is some client side interaction with the map or a tile expires, causing a new resource to be requested from the network.

MapChangeDidFailLoadingMap 

An error occurred when loading the map.

MapChangeWillStartRenderingFrame 

Just before rendering the frame. This is the state of the map just after calling render() and might happened many times before the map is fully loaded.

MapChangeDidFinishRenderingFrame 

The current frame was rendered but was left in a partial state. Some parts of the map might be missing because have not arrived from the network or are being parsed.

MapChangeDidFinishRenderingFrameFullyRendered 

The current frame was fully rendered.

MapChangeWillStartRenderingMap 

Set once when the map is about to get rendered for the first time.

MapChangeDidFinishRenderingMap 

Not in use by Map.

MapChangeDidFinishRenderingMapFullyRendered 

Map is fully loaded and rendered.

MapChangeDidFinishLoadingStyle 

The style was loaded.

MapChangeSourceDidChange 

A source has changed.

◆ MapLoadingFailure

This enum represents map loading failure type.

See also
mapLoadingFailed()
Enumerator
StyleParseFailure 

Failure to parse the style.

StyleLoadFailure 

Failure to load the style data.

NotFoundFailure 

Failure to obtain style resource file.

UnknownFailure 

Unknown map loading failure.

◆ NorthOrientation

This enum sets the orientation of the north bearing. It will directly affect bearing when resetting the north (i.e. setting bearing to 0).

See also
northOrientation()
bearing()
Enumerator
NorthUpwards 

The north is pointing up in the map. This is usually how maps are oriented.

NorthRightwards 

The north is pointing right.

NorthDownwards 

The north is pointing down.

NorthLeftwards 

The north is pointing left.

Constructor & Destructor Documentation

◆ Map()

QMapLibre::Map::Map ( QObject * parent = nullptr,
const Settings & settings = Settings(),
const QSize & size = QSize(),
qreal pixelRatio = 1 )
explicit

Main constructor for Map.

Parameters
parentThe parent object.
settingsThe settings for the map.
sizeThe size of the viewport.
pixelRatioThe initial pixel density of the screen.

Constructs a Map object with settings and sets the parent object. The settings cannot be changed after the object is constructed.

Member Function Documentation

◆ addAnnotation()

AnnotationID QMapLibre::Map::addAnnotation ( const Annotation & annotation)

Add an annotation to the map.

Parameters
annotationThe annotation to add.
Returns
The unique identifier for the new annotation.
See also
addAnnotationIcon()

◆ addAnnotationIcon()

void QMapLibre::Map::addAnnotationIcon ( const QString & name,
const QImage & sprite )

Add an annotation icon to the map.

Parameters
nameThe icon name.
spriteThe icon image.

Adds an sprite to the annotation icon pool. This can be later used by the annotation functions to shown any drawing on the map by referencing its name.

Unlike using addIcon() for runtime styling, annotations added with addAnnotation() will survive style changes.

See also
addAnnotation()

◆ addCustomLayer()

void QMapLibre::Map::addCustomLayer ( const QString & id,
std::unique_ptr< CustomLayerHostInterface > host,
const QString & before = QString() )

Add a custom style layer.

Parameters
idThe layer identifier.
hostThe custom layer host interface.
beforeThe layer identifier before which the new layer will be added.

Adds a custom layer with id with the custom layer host interface host before the existing layer before.

Warning
This is used for delegating the rendering of a layer to the user of this API and is not officially supported. Use at your own risk.

◆ addImage()

void QMapLibre::Map::addImage ( const QString & id,
const QImage & sprite )

Add a style image.

Parameters
idThe image identifier.
spriteThe image.

Adds the sprite with the identifier id that can be used later by a symbol layer.

If the id was already added, it gets replaced by the new image only if the dimensions of the image are the same as the old image, otherwise it has no effect.

See also
addLayer()

◆ addLayer()

void QMapLibre::Map::addLayer ( const QString & id,
const QVariantMap & params,
const QString & before = QString() )

Add a style layer.

Parameters
idThe layer identifier.
paramsThe layer parameters.
beforeThe layer identifier before which the new layer will be added.

Adds a style layer to the map as specified by the MapLibre style specification with parameters. The layer will be added under the layer specified by before, if specified. Otherwise it will be added as the topmost layer.

This example shows how to add a layer that will be used to show a route line on the map. Note that nothing will be drawn until we set paint properties using setPaintProperty().

QVariantMap route;
route["type"] = "line";
route["source"] = "routeSource";
map->addLayer("route", route);
Note
The source must exist prior to adding a layer.

◆ addSource()

void QMapLibre::Map::addSource ( const QString & id,
const QVariantMap & params )

Add a style source.

Parameters
idThe source identifier.
paramsThe source parameters.

Adds a source with id to the map as specified by the MapLibre Style Specification with parameters.

This example reads a GeoJSON from the Qt resource system and adds it as source:

QFile geojson(":source1.geojson");
geojson.open(QIODevice::ReadOnly);
QVariantMap routeSource;
routeSource["type"] = "geojson";
routeSource["data"] = geojson.readAll();
map->addSource("routeSource", routeSource);

◆ bearing()

double QMapLibre::Map::bearing ( ) const
nodiscard

Get the bearing angle.

Returns
The bearing angle in degrees.
See also
margins()

◆ coordinate()

Coordinate QMapLibre::Map::coordinate ( ) const
nodiscard

Get the map center coordinate.

Returns
The map center coordinate.
See also
margins()

◆ coordinateForPixel()

Coordinate QMapLibre::Map::coordinateForPixel ( const QPointF & pixel) const
nodiscard

Get coordinate for pixel.

Parameters
pixelThe pixel coordinate.
Returns
The geographic coordinate.

Returns the geographic coordinate for the pixel coordinate.

◆ coordinateZoomForBounds() [1/2]

CoordinateZoom QMapLibre::Map::coordinateZoomForBounds ( const Coordinate & sw,
const Coordinate & ne ) const
nodiscard

Get the coordinate and zoom for required bounds.

Parameters
swThe southwest coordinate.
neThe northeast coordinate.
Returns
The coordinate and zoom combination.

Returns the coordinate and zoom combination needed in order to make the coordinate bounding box sw and ne visible.

◆ coordinateZoomForBounds() [2/2]

CoordinateZoom QMapLibre::Map::coordinateZoomForBounds ( const Coordinate & sw,
const Coordinate & ne,
double newBearing,
double newPitch )
nodiscard

Get the coordinate and zoom for required bounds with updated bearing and pitch.

Parameters
swThe southwest coordinate.
neThe northeast coordinate.
newBearingThe updated bearing.
newPitchThe updated pitch.
Returns
The coordinate and zoom combination.

Returns the coordinate and zoom combination needed in order to make the coordinate bounding box sw and ne visible taking into account newBearing and newPitch.

◆ copyrightsChanged

void QMapLibre::Map::copyrightsChanged ( const QString & copyrightsHtml)
signal

Signal emitted when the copyrights have changed.

Parameters
copyrightsHtmlThe HTML of the copyrights.

This signal is emitted when the copyrights of the current content of the map have changed. This can be caused by a style change or adding a new source.

◆ createRenderer()

void QMapLibre::Map::createRenderer ( )

Create the renderer.

Creates the infrastructure needed for rendering the map. It should be called before any call to render().

Must be called on the render thread.

◆ destroyRenderer()

void QMapLibre::Map::destroyRenderer ( )

Destroy the renderer.

Destroys the infrastructure needed for rendering the map, releasing resources.

Must be called on the render thread.

◆ getFilter()

QVariant QMapLibre::Map::getFilter ( const QString & layerId) const
nodiscard

Get a style filter of a layer.

Parameters
layerIdThe layer identifier.
Returns
The filter expression.

Returns the current expression-based filter value applied to a layer with ID layerId, if any.

Filter value types are described in the MapLibre Style Spec.

◆ isFullyLoaded()

bool QMapLibre::Map::isFullyLoaded ( ) const
nodiscard

Get loaded state.

Returns
true if the map is completely rendered, false otherwise.

A partially rendered map ranges from nothing rendered at all to only labels missing.

◆ jumpTo()

void QMapLibre::Map::jumpTo ( const CameraOptions & camera)

Atomically jump to the camera options.

Parameters
cameraThe camera options.

◆ latitude()

double QMapLibre::Map::latitude ( ) const
nodiscard

Get the map latitude.

Returns
The map latitude in degrees.

◆ layerExists()

bool QMapLibre::Map::layerExists ( const QString & id)

Check if a style layer exists.

Parameters
idThe layer identifier.
Returns
true if the layer with given id exists, false otherwise.

◆ layerIds()

QVector< QString > QMapLibre::Map::layerIds ( ) const
nodiscard

List all existing layers.

Returns
List of all existing layer IDs from the current style.

◆ longitude()

double QMapLibre::Map::longitude ( ) const
nodiscard

Get the map longitude.

Returns
The map longitude in degrees.

◆ mapChanged

void QMapLibre::Map::mapChanged ( Map::MapChange change)
signal

Signal emitted when the map has changed.

Parameters
changeThe map change mode.

This signal is emitted when the state of the map has changed. This signal may be used for detecting errors when loading a style or detecting when a map is fully loaded by analyzing the parameter change.

◆ mapLoadingFailed

void QMapLibre::Map::mapLoadingFailed ( Map::MapLoadingFailure type,
const QString & description )
signal

Signal emitted when a map loading failure happens.

Parameters
typeThe type of failure.
descriptionThe description of the failure.

This signal is emitted when a map loading failure happens. Details of the failures are provided, including its type and textual description.

◆ margins()

QMargins QMapLibre::Map::margins ( ) const
nodiscard

Get the map margins.

Returns
The map margins in pixels.

◆ maximumZoom()

double QMapLibre::Map::maximumZoom ( ) const
nodiscard

Get the maximum zoom level allowed for the map.

Returns
The maximum zoom level allowed for the map.
See also
minimumZoom()

◆ minimumZoom()

double QMapLibre::Map::minimumZoom ( ) const
nodiscard

Get the minimum zoom level allowed for the map.

Returns
The minimum zoom level allowed for the map.
See also
maximumZoom()

◆ moveBy()

void QMapLibre::Map::moveBy ( const QPointF & offset)

Pan the map by an offset.

Parameters
offsetThe offset in pixels.

The pixel coordinate origin is located at the upper left corner of the map.

◆ needsRendering

void QMapLibre::Map::needsRendering ( )
signal

Signal emitted when the rendering is needed.

This signal is emitted when the visual contents of the map have changed and a redraw is needed in order to keep the map visually consistent with the current state.

See also
render()

◆ northOrientation()

Map::NorthOrientation QMapLibre::Map::northOrientation ( ) const
nodiscard

Get the map north orientation mode.

Returns
The map north orientation mode.

◆ pitch()

double QMapLibre::Map::pitch ( ) const
nodiscard

Get the pitch angle.

Returns
The pitch angle in degrees.
See also
margins()

◆ pitchBy()

void QMapLibre::Map::pitchBy ( double pitch)

Pitch the map for an angle.

Parameters
pitchThe pitch angle in degrees.
See also
setPitch()

◆ pixelForCoordinate()

QPointF QMapLibre::Map::pixelForCoordinate ( const Coordinate & coordinate) const
nodiscard

Get pixel for coordinate.

Parameters
coordinateThe geographic coordinate.
Returns
The pixel coordinate.

Returns the offset in pixels for coordinate. The origin pixel coordinate is located at the top left corner of the map view.

This method returns the correct value for any coordinate, even if the coordinate is not currently visible on the screen.

Note
The return value is affected by the current zoom level, bearing and pitch.

◆ removeAnnotation()

void QMapLibre::Map::removeAnnotation ( AnnotationID id)

Remove an existing annotation.

Parameters
idThe unique identifier for the annotation to remove.

◆ removeImage()

void QMapLibre::Map::removeImage ( const QString & id)

Remove a style image.

Parameters
idThe image identifier.

◆ removeLayer()

void QMapLibre::Map::removeLayer ( const QString & id)

Remove a style layer.

Parameters
idThe layer identifier.

This method has no effect if the style layer does not exist.

◆ removeSource()

void QMapLibre::Map::removeSource ( const QString & id)

Remove a style source.

Parameters
idThe source identifier.

This method has no effect if the style source does not exist.

◆ render

void QMapLibre::Map::render ( )
slot

Render.

Renders the map using OpenGL draw calls. It will make sure to bind the framebuffer object before drawing; otherwise a valid OpenGL context is expected with an appropriate OpenGL viewport state set for the size of the canvas.

This function should be called only after the signal needsRendering() is emitted at least once.

Must be called on the render thread.

◆ resize()

void QMapLibre::Map::resize ( const QSize & size)

Resize the map.

Parameters
sizeThe new size.

Resize the map to size and scale to fit at the framebuffer. For high DPI screens, the size will be smaller than the framebuffer.

◆ rotateBy()

void QMapLibre::Map::rotateBy ( const QPointF & first,
const QPointF & second )

Rotate the map.

Parameters
firstThe first screen coordinate.
secondThe second screen coordinate.

Rotate the map from the first screen coordinate to the second screen coordinate. This method can be used for implementing rotating the map by clicking and dragging, being first the cursor coordinate at the last frame and second the cursor coordinate at the current frame.

◆ scale()

double QMapLibre::Map::scale ( ) const
nodiscard

Get the map scale factor.

Returns
The map scale factor.
See also
zoom()

◆ scaleBy()

void QMapLibre::Map::scaleBy ( double scale,
const QPointF & center = QPointF() )

Scale the map.

Parameters
scaleThe scale factor.
centerThe direction pixel coordinate.

Scale the map by scale in the direction of the center. This function can be used for implementing a pinch gesture.

◆ setBearing() [1/2]

void QMapLibre::Map::setBearing ( double degrees)

Set the bearing angle.

Parameters
degreesThe bearing angle in degrees.

Negative values and values over 360 are valid and will wrap. The direction of the rotation is counterclockwise.

See also
setMargins()

◆ setBearing() [2/2]

void QMapLibre::Map::setBearing ( double degrees,
const QPointF & center )

Set the bearing angle.

Parameters
degreesThe bearing angle in degrees.
centerThe center pixel coordinate.

Negative values and values over 360 are valid and will wrap. The direction of the rotation is counterclockwise.

When center is defined, the map will rotate around the center pixel coordinate respecting the margins if defined.

See also
setMargins()

◆ setConnectionEstablished

void QMapLibre::Map::setConnectionEstablished ( )
slot

Set connection established.

Informs the map that the network connection has been established, causing all network requests that previously timed out to be retried immediately.

◆ setCoordinate()

void QMapLibre::Map::setCoordinate ( const Coordinate & coordinate)

Set the map center coordinate.

Parameters
coordinateThe map center coordinate.

Centers the map at a geographic coordinate respecting the margins, if set.

See also
setMargins()

◆ setCoordinateZoom()

void QMapLibre::Map::setCoordinateZoom ( const Coordinate & coordinate,
double zoom )

Convenience method for setting the coordinate and zoom simultaneously.

Parameters
coordinateThe map center coordinate.
zoomThe map zoom factor.
Note
Setting coordinate and zoom at once is more efficient than doing it in two steps.
See also
zoom()
coordinate()

◆ setFilter()

void QMapLibre::Map::setFilter ( const QString & layerId,
const QVariant & filter )

Set a style filter to a layer.

Parameters
layerIdThe layer identifier.
filterThe filter expression.

Adds a filter to a style layer using the format described in the MapLibre Style Spec.

Given a layer marker from an arbitrary GeoJSON source containing features of type "Point" and "LineString", this example shows how to make sure the layer will only tag features of type "Point".

QVariantList filterExpression;
filterExpression.push_back(QLatin1String("=="));
filterExpression.push_back(QLatin1String("$type"));
filterExpression.push_back(QLatin1String("Point"));
QVariantList filter;
filter.push_back(filterExpression);
map->setFilter(QLatin1String("marker"), filter);

◆ setGestureInProgress()

void QMapLibre::Map::setGestureInProgress ( bool progress)

Set gesture in progress status.

Parameters
progressThe gesture in progress status.

Tells the map rendering engine that there is currently a gesture in progress. This affects how the map renders labels, as it will use different textur filters if a gesture is ongoing.

◆ setLatitude()

void QMapLibre::Map::setLatitude ( double latitude)

Set the map latitude.

Parameters
latitudeThe map latitude in degrees.

Setting a latitude doesn't necessarily mean it will be accepted since Map might constrain it within the limits of the Web Mercator projection.

◆ setLayoutProperty()

bool QMapLibre::Map::setLayoutProperty ( const QString & layerId,
const QString & propertyName,
const QVariant & value )

Set layer layout property.

Parameters
layerIdThe layer identifier.
propertyNameThe layout property name.
valueThe layout property value.
Returns
true if the operation succeeds, false otherwise.

Sets a layout property value to an existing layer. The property string can be any as defined by the MapLibre Style Spec for layout properties.

The implementation attempts to treat value as a JSON string, if the QVariant inner type is a string. If not a valid JSON string, then it'll proceed with the mapping described below.

This example hides the layer route:

map->setLayoutProperty("route", "visibility", "none");

This table describes the mapping between style types and Qt types accepted by setLayoutProperty():

MapLibre style type Qt type
Enum QString
String QString
Boolean bool
Number int, double or float
Array QVariantList

◆ setLongitude()

void QMapLibre::Map::setLongitude ( double longitude)

Set the map longitude.

Parameters
longitudeThe map longitude in degrees.

Setting a longitude beyond the limits of the Web Mercator projection will make the map wrap. As an example, setting the longitude to 360 is effectively the same as setting it to 0.

◆ setMargins()

void QMapLibre::Map::setMargins ( const QMargins & margins)

Set the map margins.

Parameters
marginsThe map margins in pixels.

This sets a new reference center for the map.

◆ setNorthOrientation()

void QMapLibre::Map::setNorthOrientation ( NorthOrientation orientation)

Set the north orientation mode.

Parameters
orientationThe north orientation mode.

◆ setOpenGLFramebufferObject()

void QMapLibre::Map::setOpenGLFramebufferObject ( quint32 fbo,
const QSize & size )

Set the OpenGL framebuffer object.

Parameters
fboThe OpenGL framebuffer object ID.
sizeThe OpenGL framebuffer size.

If MapLibre Native needs to rebind the default fbo, it will use the ID supplied here. size is the size of the framebuffer, which on high DPI screens is usually bigger than the map size.

Must be called on the render thread.

◆ setPaintProperty()

bool QMapLibre::Map::setPaintProperty ( const QString & layerId,
const QString & propertyName,
const QVariant & value )

Set layer paint property.

Parameters
layerIdThe layer identifier.
propertyNameThe paint property name.
valueThe paint property value.
Returns
true if the operation succeeds, false otherwise.

Sets a layout property value to an existing layer. The property string can be any as defined by the MapLibre Style Spec for paint properties.

The implementation attempts to treat value as a JSON string, if the QVariant inner type is a string. If not a valid JSON string, then it'll proceed with the mapping described below.

For paint properties that take a color as value, such as fill-color, a string such as blue can be passed or a QColor.

map->setPaintProperty("route", "line-color", QColor("blue"));

This table describes the mapping between style types and Qt types accepted by setPaintProperty():

MapLibre style type Qt type
Color QString or QColor
Enum QString
String QString
Boolean bool
Number int, double or float
Array QVariantList

If the style specification defines the property's type as Array, use a QVariantList. For example, the following code sets a route layer's line-dasharray property:

QVariantList lineDashArray;
lineDashArray.append(1);
lineDashArray.append(2);
map->setPaintProperty("route","line-dasharray", lineDashArray);

◆ setPitch()

void QMapLibre::Map::setPitch ( double pitch)

Set the pitch angle.

Parameters
pitchThe pitch angle in degrees.

Pitch toward the horizon measured in degrees, with 0 resulting in a two-dimensional map. It will be constrained at 60 degrees.

See also
margins()
pitchBy()

◆ setScale()

void QMapLibre::Map::setScale ( double scale,
const QPointF & center = QPointF() )

Set the map scale factor.

Parameters
scaleThe map scale factor.
centerThe center pixel coordinate.

This property is used to zoom the map. When center is defined, the map will scale in the direction of the center pixel coordinates. The center will remain at the same pixel coordinate after scaling as before calling this method.

Note
This function could be used for implementing a pinch gesture or zooming by using the mouse scroll wheel.
See also
setZoom()

◆ setStyleJson()

void QMapLibre::Map::setStyleJson ( const QString & style)

Set a new style from a JSON.

Parameters
styleThe style JSON.

The JSON must conform to the MapLibre Style spec.

Note
In case of a invalid style it will trigger a mapChanged signal with Map::MapChangeDidFailLoadingMap as argument.

◆ setStyleUrl()

void QMapLibre::Map::setStyleUrl ( const QString & url)

Set the map style URL.

Parameters
urlThe map style URL.

Sets a URL for fetching a JSON that will be later fed to setStyleJson. URLs using the Mapbox scheme (mapbox://) are also accepted and translated automatically to an actual HTTPS request.

The Mapbox scheme is not enforced and a style can be fetched from anything that QNetworkAccessManager can handle.

Note
In case of a invalid style it will trigger a mapChanged signal with Map::MapChangeDidFailLoadingMap as argument.

◆ setTransitionOptions()

void QMapLibre::Map::setTransitionOptions ( qint64 duration,
qint64 delay = 0 )

Set transition options.

Parameters
durationThe transition duration in milliseconds.
delayThe transition delay in milliseconds.

Style paint property values transition to new values with animation when they are updated.

◆ setZoom()

void QMapLibre::Map::setZoom ( double zoom)

Set the map zoom factor.

Parameters
zoomThe map zoom factor.

This property is used to zoom the map. When center is defined, the map will zoom in the direction of the center. This function could be used for implementing a pinch gesture or zooming by using the mouse scroll wheel.

See also
setZoom()

◆ sourceExists()

bool QMapLibre::Map::sourceExists ( const QString & id)

Check if a style source exists.

Parameters
idThe source identifier.
Returns
true if the layer with given id exists, false otherwise.

◆ startStaticRender

void QMapLibre::Map::startStaticRender ( )
slot

Start the static renderer.

Start a static rendering of the current state of the map. This should only be called when the map is initialized in static mode.

See also
Settings::MapMode

◆ staticRenderFinished

void QMapLibre::Map::staticRenderFinished ( const QString & error)
signal

Signal emitted when a static map is fully drawn.

Parameters
errorThe error message.

This signal is emitted when a static map is fully drawn. Usually the next step is to extract the map from a framebuffer into a container like a QImage. error is set to a message when an error occurs.

See also
startStaticRender()

◆ styleJson()

QString QMapLibre::Map::styleJson ( ) const
nodiscard

Get the map style JSON.

Returns
The map style JSON.

◆ styleUrl()

QString QMapLibre::Map::styleUrl ( ) const
nodiscard

Get the map style URL.

Returns
The map style URL.

◆ updateAnnotation()

void QMapLibre::Map::updateAnnotation ( AnnotationID id,
const Annotation & annotation )

Update an existing annotation.

Parameters
idThe unique identifier for the annotation to update.
annotationThe updated annotation.
See also
addAnnotationIcon()

◆ updateSource()

void QMapLibre::Map::updateSource ( const QString & id,
const QVariantMap & params )

Update a style source.

Parameters
idThe source identifier.
paramsThe source parameters.

If the source does not exist, it will be added like in addSource(). Only image and GeoJSON sources can be updated.

◆ zoom()

double QMapLibre::Map::zoom ( ) const
nodiscard

Get the map zoom factor.

Returns
The map zoom factor.
See also
scale()

Property Documentation

◆ bearing

double QMapLibre::Map::bearing
readwrite

the map bearing in degrees.

See also
bearing()
setBearing()

◆ coordinate

QMapLibre::Coordinate QMapLibre::Map::coordinate
readwrite

The map center coordinate.

See also
coordinate()
setCoordinate()

◆ latitude

double QMapLibre::Map::latitude
readwrite

The map's current latitude in degrees.

See also
latitude()
setLatitude()

◆ longitude

double QMapLibre::Map::longitude
readwrite

The map current longitude in degrees.

See also
longitude()
setLongitude()

◆ margins

QMargins QMapLibre::Map::margins
readwrite

the map margins in pixels from the corners of the map.

See also
margins()
setMargins()

◆ pitch

double QMapLibre::Map::pitch
readwrite

the map pitch in degrees.

See also
pitch()
setPitch()

◆ scale

double QMapLibre::Map::scale
readwrite

The map scale factor.

See also
scale()
setScale()

◆ styleJson

QString QMapLibre::Map::styleJson
readwrite

The map's current style JSON.

See also
styleJson()
setStyleJson()

◆ styleUrl

QString QMapLibre::Map::styleUrl
readwrite

The map's current style URL.

See also
styleUrl()
setStyleUrl()

◆ zoom

double QMapLibre::Map::zoom
readwrite

the map zoom factor.

See also
zoom()
setZoom()