MapLibre Native for Qt
Loading...
Searching...
No Matches
map.hpp
1// Copyright (C) 2023 MapLibre contributors
2// Copyright (C) 2019 Mapbox, Inc.
3
4// SPDX-License-Identifier: BSD-2-Clause
5
6#ifndef QMAPLIBRE_MAP_H
7#define QMAPLIBRE_MAP_H
8
9#include <QMapLibre/Export>
10#include <QMapLibre/Settings>
11#include <QMapLibre/Types>
12
13#include <QtCore/QMargins>
14#include <QtCore/QObject>
15#include <QtCore/QPointF>
16#include <QtCore/QSize>
17#include <QtCore/QString>
18#include <QtCore/QStringList>
19#include <QtGui/QImage>
20
21#include <functional>
22#include <memory>
23
24namespace QMapLibre {
25
26class MapPrivate;
27
28class Q_MAPLIBRE_CORE_EXPORT Map : public QObject {
29 Q_OBJECT
30 Q_PROPERTY(double latitude READ latitude WRITE setLatitude)
31 Q_PROPERTY(double longitude READ longitude WRITE setLongitude)
32 Q_PROPERTY(double zoom READ zoom WRITE setZoom)
33 Q_PROPERTY(double bearing READ bearing WRITE setBearing)
34 Q_PROPERTY(double pitch READ pitch WRITE setPitch)
35 Q_PROPERTY(QString styleJson READ styleJson WRITE setStyleJson)
36 Q_PROPERTY(QString styleUrl READ styleUrl WRITE setStyleUrl)
37 Q_PROPERTY(double scale READ scale WRITE setScale)
38 Q_PROPERTY(QMapLibre::Coordinate coordinate READ coordinate WRITE setCoordinate)
39 Q_PROPERTY(QMargins margins READ margins WRITE setMargins)
40
41public:
60
67
68 // Determines the orientation of the map.
75
76 explicit Map(QObject *parent = nullptr,
77 const Settings &settings = Settings(),
78 const QSize &size = QSize(),
79 qreal pixelRatio = 1);
80 ~Map() override;
81
82 [[nodiscard]] QString styleJson() const;
83 [[nodiscard]] QString styleUrl() const;
84
85 void setStyleJson(const QString &);
86 void setStyleUrl(const QString &);
87
88 [[nodiscard]] double latitude() const;
89 void setLatitude(double latitude);
90
91 [[nodiscard]] double longitude() const;
92 void setLongitude(double longitude);
93
94 [[nodiscard]] double scale() const;
95 void setScale(double scale, const QPointF &center = QPointF());
96
97 [[nodiscard]] double zoom() const;
98 void setZoom(double zoom);
99
100 [[nodiscard]] double minimumZoom() const;
101 [[nodiscard]] double maximumZoom() const;
102
103 [[nodiscard]] double bearing() const;
104 void setBearing(double degrees);
105 void setBearing(double degrees, const QPointF &center);
106
107 [[nodiscard]] double pitch() const;
108 void setPitch(double pitch);
109 void pitchBy(double pitch);
110
111 [[nodiscard]] NorthOrientation northOrientation() const;
112 void setNorthOrientation(NorthOrientation);
113
114 [[nodiscard]] Coordinate coordinate() const;
115 void setCoordinate(const Coordinate &coordinate);
116 void setCoordinateZoom(const Coordinate &coordinate, double zoom);
117
118 void jumpTo(const CameraOptions &);
119
120 void setGestureInProgress(bool inProgress);
121
122 void setTransitionOptions(qint64 duration, qint64 delay = 0);
123
124 void addAnnotationIcon(const QString &name, const QImage &sprite);
125
126 AnnotationID addAnnotation(const Annotation &annotation);
127 void updateAnnotation(AnnotationID id, const Annotation &annotation);
128 void removeAnnotation(AnnotationID id);
129
130 bool setLayoutProperty(const QString &layerId, const QString &propertyName, const QVariant &value);
131 bool setPaintProperty(const QString &layerId, const QString &propertyName, const QVariant &value);
132
133 [[nodiscard]] bool isFullyLoaded() const;
134
135 void moveBy(const QPointF &offset);
136 void scaleBy(double scale, const QPointF &center = QPointF());
137 void rotateBy(const QPointF &first, const QPointF &second);
138
139 void resize(const QSize &size);
140
141 [[nodiscard]] QPointF pixelForCoordinate(const Coordinate &coordinate) const;
142 [[nodiscard]] Coordinate coordinateForPixel(const QPointF &pixel) const;
143
144 [[nodiscard]] CoordinateZoom coordinateZoomForBounds(const Coordinate &sw, const Coordinate &ne) const;
145 [[nodiscard]] CoordinateZoom coordinateZoomForBounds(const Coordinate &sw,
146 const Coordinate &ne,
147 double bearing,
148 double pitch);
149
150 void setMargins(const QMargins &margins);
151 [[nodiscard]] QMargins margins() const;
152
153 void addSource(const QString &id, const QVariantMap &params);
154 bool sourceExists(const QString &id);
155 void updateSource(const QString &id, const QVariantMap &params);
156 void removeSource(const QString &id);
157
158 void addImage(const QString &id, const QImage &sprite);
159 void removeImage(const QString &id);
160
161 void addCustomLayer(const QString &id,
162 std::unique_ptr<CustomLayerHostInterface> host,
163 const QString &before = QString());
164 void addLayer(const QString &id, const QVariantMap &params, const QString &before = QString());
165 bool layerExists(const QString &id);
166 void removeLayer(const QString &id);
167
168 [[nodiscard]] QVector<QString> layerIds() const;
169
170 void setFilter(const QString &layerId, const QVariant &filter);
171 [[nodiscard]] QVariant getFilter(const QString &layerId) const;
172 // When rendering on a different thread,
173 // should be called on the render thread.
174 void createRenderer();
175 void destroyRenderer();
176 void setOpenGLFramebufferObject(quint32 fbo, const QSize &size);
177
178public slots:
179 void render();
180 void setConnectionEstablished();
181
182 // Commit changes, load all the resources
183 // and renders the map when completed.
184 void startStaticRender();
185
186signals:
189 void mapLoadingFailed(Map::MapLoadingFailure, const QString &reason);
190 void copyrightsChanged(const QString &copyrightsHtml);
191
192 void staticRenderFinished(const QString &error);
193
194private:
195 Q_DISABLE_COPY(Map)
196
197 std::unique_ptr<MapPrivate> d_ptr;
198};
199
200} // namespace QMapLibre
201
202Q_DECLARE_METATYPE(QMapLibre::Map::MapChange);
203Q_DECLARE_METATYPE(QMapLibre::Map::MapLoadingFailure);
204
205#endif // QMAPLIBRE_MAP_H
The Map class is a Qt wrapper for the MapLibre Native engine.
Definition map.hpp:28
void staticRenderFinished(const QString &error)
Signal emitted when a static map is fully drawn.
void copyrightsChanged(const QString &copyrightsHtml)
Signal emitted when the copyrights have changed.
NorthOrientation
Definition map.hpp:69
@ NorthRightwards
Definition map.hpp:71
@ NorthLeftwards
Definition map.hpp:73
@ NorthUpwards
Definition map.hpp:70
@ NorthDownwards
Definition map.hpp:72
MapChange
Definition map.hpp:42
@ MapChangeRegionIsChanging
Definition map.hpp:45
@ MapChangeDidFinishRenderingFrameFullyRendered
Definition map.hpp:53
@ MapChangeDidFailLoadingMap
Definition map.hpp:50
@ MapChangeDidFinishRenderingFrame
Definition map.hpp:52
@ MapChangeDidFinishRenderingMap
Definition map.hpp:55
@ MapChangeWillStartRenderingFrame
Definition map.hpp:51
@ MapChangeRegionDidChangeAnimated
Definition map.hpp:47
@ MapChangeWillStartLoadingMap
Definition map.hpp:48
@ MapChangeDidFinishRenderingMapFullyRendered
Definition map.hpp:56
@ MapChangeWillStartRenderingMap
Definition map.hpp:54
@ MapChangeRegionWillChangeAnimated
Definition map.hpp:44
@ MapChangeRegionDidChange
Definition map.hpp:46
@ MapChangeDidFinishLoadingMap
Definition map.hpp:49
@ MapChangeDidFinishLoadingStyle
Definition map.hpp:57
void mapChanged(Map::MapChange)
Signal emitted when the map has changed.
MapLoadingFailure
Definition map.hpp:61
@ StyleParseFailure
Definition map.hpp:62
@ StyleLoadFailure
Definition map.hpp:63
@ NotFoundFailure
Definition map.hpp:64
void mapLoadingFailed(Map::MapLoadingFailure, const QString &reason)
Signal emitted when a map loading failure happens.
void needsRendering()
Signal emitted when the rendering is needed.
The Settings class stores the initial configuration for Map.
Definition settings.hpp:27
Definition geojson.cpp:10
QPair< Coordinate, double > CoordinateZoom
Coordinate-zoom pair helper type.
Definition types.hpp:21
QPair< double, double > Coordinate
Coordinate helper type.
Definition types.hpp:20
quint32 AnnotationID
Annotation identifier helper type.
Definition types.hpp:162
QVariant Annotation
Annotation helper type.
Definition types.hpp:161
Camera options helper type.
Definition types.hpp:165