forked from mapbox/mapbox-gl-native
-
Notifications
You must be signed in to change notification settings - Fork 0
/
qmapboxgl.hpp
279 lines (214 loc) · 8.34 KB
/
qmapboxgl.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
#ifndef QMAPBOXGL_H
#define QMAPBOXGL_H
#include <QImage>
#include <QMapbox>
#include <QMargins>
#include <QObject>
#include <QPointF>
#include <QSize>
#include <QString>
#include <QStringList>
#include <functional>
class QMapboxGLPrivate;
// This header follows the Qt coding style: https://wiki.qt.io/Qt_Coding_Style
class Q_MAPBOXGL_EXPORT QMapboxGLSettings
{
public:
QMapboxGLSettings();
enum GLContextMode {
UniqueGLContext = 0,
SharedGLContext
};
enum MapMode {
Continuous = 0,
Static
};
enum ConstrainMode {
NoConstrain = 0,
ConstrainHeightOnly,
ConstrainWidthAndHeight
};
enum ViewportMode {
DefaultViewport = 0,
FlippedYViewport
};
GLContextMode contextMode() const;
void setContextMode(GLContextMode);
MapMode mapMode() const;
void setMapMode(MapMode);
ConstrainMode constrainMode() const;
void setConstrainMode(ConstrainMode);
ViewportMode viewportMode() const;
void setViewportMode(ViewportMode);
unsigned cacheDatabaseMaximumSize() const;
void setCacheDatabaseMaximumSize(unsigned);
QString cacheDatabasePath() const;
void setCacheDatabasePath(const QString &);
QString assetPath() const;
void setAssetPath(const QString &);
QString accessToken() const;
void setAccessToken(const QString &);
QString apiBaseUrl() const;
void setApiBaseUrl(const QString &);
QString localFontFamily() const;
void setLocalFontFamily(const QString &);
std::function<std::string(const std::string &&)> resourceTransform() const;
void setResourceTransform(const std::function<std::string(const std::string &&)> &);
private:
GLContextMode m_contextMode;
MapMode m_mapMode;
ConstrainMode m_constrainMode;
ViewportMode m_viewportMode;
unsigned m_cacheMaximumSize;
QString m_cacheDatabasePath;
QString m_assetPath;
QString m_accessToken;
QString m_apiBaseUrl;
QString m_localFontFamily;
std::function<std::string(const std::string &&)> m_resourceTransform;
};
struct Q_MAPBOXGL_EXPORT QMapboxGLCameraOptions {
QVariant center; // Coordinate
QVariant anchor; // QPointF
QVariant zoom; // double
QVariant bearing; // double
QVariant pitch; // double
};
class Q_MAPBOXGL_EXPORT QMapboxGL : public QObject
{
Q_OBJECT
Q_PROPERTY(double latitude READ latitude WRITE setLatitude)
Q_PROPERTY(double longitude READ longitude WRITE setLongitude)
Q_PROPERTY(double zoom READ zoom WRITE setZoom)
Q_PROPERTY(double bearing READ bearing WRITE setBearing)
Q_PROPERTY(double pitch READ pitch WRITE setPitch)
Q_PROPERTY(QString styleJson READ styleJson WRITE setStyleJson)
Q_PROPERTY(QString styleUrl READ styleUrl WRITE setStyleUrl)
Q_PROPERTY(double scale READ scale WRITE setScale)
Q_PROPERTY(QMapbox::Coordinate coordinate READ coordinate WRITE setCoordinate)
Q_PROPERTY(QMargins margins READ margins WRITE setMargins)
public:
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
};
// Determines the orientation of the map.
enum NorthOrientation {
NorthUpwards, // Default
NorthRightwards,
NorthDownwards,
NorthLeftwards,
};
QMapboxGL(QObject* parent = 0,
const QMapboxGLSettings& = QMapboxGLSettings(),
const QSize& size = QSize(),
qreal pixelRatio = 1);
virtual ~QMapboxGL();
void cycleDebugOptions();
QString styleJson() const;
QString styleUrl() const;
void setStyleJson(const QString &);
void setStyleUrl(const QString &);
double latitude() const;
void setLatitude(double latitude);
double longitude() const;
void setLongitude(double longitude);
double scale() const;
void setScale(double scale, const QPointF ¢er = QPointF());
double zoom() const;
void setZoom(double zoom);
double minimumZoom() const;
double maximumZoom() const;
double bearing() const;
void setBearing(double degrees);
void setBearing(double degrees, const QPointF ¢er);
double pitch() const;
void setPitch(double pitch);
void pitchBy(double pitch);
NorthOrientation northOrientation() const;
void setNorthOrientation(NorthOrientation);
QMapbox::Coordinate coordinate() const;
void setCoordinate(const QMapbox::Coordinate &);
void setCoordinateZoom(const QMapbox::Coordinate &, double zoom);
void jumpTo(const QMapboxGLCameraOptions&);
void setGestureInProgress(bool inProgress);
void setTransitionOptions(qint64 duration, qint64 delay = 0);
void addAnnotationIcon(const QString &name, const QImage &sprite);
QMapbox::AnnotationID addAnnotation(const QMapbox::Annotation &);
void updateAnnotation(QMapbox::AnnotationID, const QMapbox::Annotation &);
void removeAnnotation(QMapbox::AnnotationID);
bool setLayoutProperty(const QString &layer, const QString &property, const QVariant &value);
bool setPaintProperty(const QString &layer, const QString &property, const QVariant &value);
bool isFullyLoaded() const;
void moveBy(const QPointF &offset);
void scaleBy(double scale, const QPointF ¢er = QPointF());
void rotateBy(const QPointF &first, const QPointF &second);
void resize(const QSize &size);
double metersPerPixelAtLatitude(double latitude, double zoom) const;
QMapbox::ProjectedMeters projectedMetersForCoordinate(const QMapbox::Coordinate &) const;
QMapbox::Coordinate coordinateForProjectedMeters(const QMapbox::ProjectedMeters &) const;
QPointF pixelForCoordinate(const QMapbox::Coordinate &) const;
QMapbox::Coordinate coordinateForPixel(const QPointF &) const;
QMapbox::CoordinateZoom coordinateZoomForBounds(const QMapbox::Coordinate &sw, QMapbox::Coordinate &ne) const;
QMapbox::CoordinateZoom coordinateZoomForBounds(const QMapbox::Coordinate &sw, QMapbox::Coordinate &ne, double bearing, double pitch);
void setMargins(const QMargins &margins);
QMargins margins() const;
void addSource(const QString &sourceID, const QVariantMap& params);
bool sourceExists(const QString &sourceID);
void updateSource(const QString &sourceID, const QVariantMap& params);
void removeSource(const QString &sourceID);
void addImage(const QString &name, const QImage &sprite);
void removeImage(const QString &name);
void addCustomLayer(const QString &id,
QScopedPointer<QMapbox::CustomLayerHostInterface>& host,
const QString& before = QString());
void addLayer(const QVariantMap ¶ms, const QString& before = QString());
bool layerExists(const QString &id);
void removeLayer(const QString &id);
QVector<QString> layerIds() const;
void setFilter(const QString &layer, const QVariant &filter);
QVariant getFilter(const QString &layer) const;
// When rendering on a different thread,
// should be called on the render thread.
void createRenderer();
void destroyRenderer();
void setFramebufferObject(quint32 fbo, const QSize &size);
public slots:
void render();
void connectionEstablished();
// Commit changes, load all the resources
// and renders the map when completed.
void startStaticRender();
signals:
void needsRendering();
void mapChanged(QMapboxGL::MapChange);
void mapLoadingFailed(QMapboxGL::MapLoadingFailure, const QString &reason);
void copyrightsChanged(const QString ©rightsHtml);
void staticRenderFinished(const QString &error);
private:
Q_DISABLE_COPY(QMapboxGL)
QMapboxGLPrivate *d_ptr;
};
Q_DECLARE_METATYPE(QMapboxGL::MapChange);
Q_DECLARE_METATYPE(QMapboxGL::MapLoadingFailure);
#endif // QMAPBOXGL_H