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