1 #include "qmapbox.hpp"
2
3 #include <mbgl/storage/network_status.hpp>
4 #include <mbgl/util/default_styles.hpp>
5 #include <mbgl/util/geometry.hpp>
6 #include <mbgl/util/traits.hpp>
7
8 #if QT_VERSION >= 0x050000
9 #include <QOpenGLContext>
10 #else
11 #include <QGLContext>
12 #endif
13
14 // mbgl::NetworkStatus::Status
15 static_assert(mbgl::underlying_type(QMapbox::Online) == mbgl::underlying_type(mbgl::NetworkStatus::Status::Online), "error");
16 static_assert(mbgl::underlying_type(QMapbox::Offline) == mbgl::underlying_type(mbgl::NetworkStatus::Status::Offline), "error");
17
18 // mbgl::FeatureType
19 static_assert(mbgl::underlying_type(QMapbox::Feature::PointType) == mbgl::underlying_type(mbgl::FeatureType::Point), "error");
20 static_assert(mbgl::underlying_type(QMapbox::Feature::LineStringType) == mbgl::underlying_type(mbgl::FeatureType::LineString), "error");
21 static_assert(mbgl::underlying_type(QMapbox::Feature::PolygonType) == mbgl::underlying_type(mbgl::FeatureType::Polygon), "error");
22
23 namespace QMapbox {
24
25 /*!
26 \namespace QMapbox
27 \inmodule Mapbox Maps SDK for Qt
28
29 Contains miscellaneous Mapbox bindings used throughout QMapboxGL.
30 */
31
32 /*!
33 \typedef QMapbox::Coordinate
34
35 Alias for QPair<double, double>.
36 Representation for geographical coordinates - latitude and longitude, respectively.
37 */
38
39 /*!
40 \typedef QMapbox::CoordinateZoom
41
42 Alias for QPair<Coordinate, double>.
43 Used as return value in QMapboxGL::coordinateZoomForBounds.
44 */
45
46 /*!
47 \typedef QMapbox::ProjectedMeters
48
49 Alias for QPair<double, double>.
50 Representation for projected meters - northing and easting, respectively.
51 */
52
53 /*!
54 \typedef QMapbox::Coordinates
55
56 Alias for QList<QMapbox::Coordinate>.
57 A list of QMapbox::Coordinate objects.
58 */
59
60 /*!
61 \typedef QMapbox::CoordinatesCollection
62
63 Alias for QList<QMapbox::Coordinates>.
64 A list of QMapbox::Coordinates objects.
65 */
66
67 /*!
68 \typedef QMapbox::CoordinatesCollections
69
70 Alias for QList<QMapbox::CoordinatesCollection>.
71 A list of QMapbox::CoordinatesCollection objects.
72 */
73
74 /*!
75 \class QMapbox::Feature
76
77 \inmodule Mapbox Maps SDK for Qt
78
79 Represents \l {https://www.mapbox.com/help/define-features/}{map features}
80 via its \a type (PointType, LineStringType or PolygonType), \a geometry, \a
81 properties map and \a id (optional).
82 */
83
84 /*!
85 \enum QMapbox::Feature::Type
86
87 This enum is used as basis for geometry disambiguation in QMapbox::Feature.
88
89 \value PointType A point geometry type. Means a single or a collection of points.
90 \value LineStringType A line string geometry type. Means a single or a collection of line strings.
91 \value PolygonType A polygon geometry type. Means a single or a collection of polygons.
92 */
93
94 /*!
95 \class QMapbox::ShapeAnnotationGeometry
96
97 \inmodule Mapbox Maps SDK for Qt
98
99 Represents a shape annotation geometry.
100 */
101
102 /*!
103 \enum QMapbox::ShapeAnnotationGeometry::Type
104
105 This enum is used as basis for shape annotation geometry disambiguation.
106
107 \value PolygonType A polygon geometry type.
108 \value LineStringType A line string geometry type.
109 \value MultiPolygonType A polygon geometry collection type.
110 \value MultiLineStringType A line string geometry collection type.
111 */
112
113 /*!
114 \class QMapbox::SymbolAnnotation
115
116 \inmodule Mapbox Maps SDK for Qt
117
118 A symbol annotation comprises of its geometry and an icon identifier.
119 */
120
121 /*!
122 \class QMapbox::LineAnnotation
123
124 \inmodule Mapbox Maps SDK for Qt
125
126 Represents a line annotation object, along with its properties.
127
128 A line annotation comprises of its geometry and line properties such as opacity, width and color.
129 */
130
131 /*!
132 \class QMapbox::FillAnnotation
133
134 \inmodule Mapbox Maps SDK for Qt
135
136 Represents a fill annotation object, along with its properties.
137
138 A fill annotation comprises of its geometry and fill properties such as opacity, color and outline color.
139 */
140
141 /*!
142 \typedef QMapbox::Annotation
143
144 Alias for QVariant.
145 Container that encapsulates either a symbol, a line, a fill or a style sourced annotation.
146 */
147
148 /*!
149 \typedef QMapbox::AnnotationID
150
151 Alias for quint32 representing an annotation identifier.
152 */
153
154 /*!
155 \typedef QMapbox::AnnotationIDs
156
157 Alias for QList<quint32> representing a container of annotation identifiers.
158 */
159
160 /*!
161 \class QMapbox::CustomLayerHostInterface
162
163 Represents a host interface to be implemented for rendering custom layers.
164
165 \warning This is used for delegating the rendering of a layer to the user of
166 this API and is not officially supported. Use at your own risk.
167 */
168
169 /*!
170 \enum QMapbox::NetworkMode
171
172 This enum represents whether server requests can be performed via network.
173
174 \value Online Server network requests are accessible.
175 \value Offline Only requests to the local cache are accessible.
176 */
177
178 /*!
179 \class QMapbox::CustomLayerRenderParameters
180 \inmodule Mapbox Maps SDK for Qt
181
182 QMapbox::CustomLayerRenderParameters provides the data passed on each render
183 pass for a custom layer.
184 */
185
186 /*!
187 \fn QMapbox::NetworkMode QMapbox::networkMode()
188
189 Returns the current QMapbox::NetworkMode.
190 */
networkMode()191 NetworkMode networkMode()
192 {
193 return static_cast<NetworkMode>(mbgl::NetworkStatus::Get());
194 }
195
196 /*!
197 \fn void QMapbox::setNetworkMode(QMapbox::NetworkMode mode)
198
199 Forwards the network status \a mode to Mapbox GL Native engine.
200
201 File source requests uses the available network when \a mode is set to \b
202 Online, otherwise scoped to the local cache.
203 */
setNetworkMode(NetworkMode mode)204 void setNetworkMode(NetworkMode mode)
205 {
206 mbgl::NetworkStatus::Set(static_cast<mbgl::NetworkStatus::Status>(mode));
207 }
208
209 /*!
210 \fn QList<QPair<QString, QString> >& QMapbox::defaultStyles()
211
212 Returns a list containing a pair of string objects, representing the style
213 URL and name, respectively.
214 */
defaultStyles()215 QList<QPair<QString, QString> >& defaultStyles()
216 {
217 static QList<QPair<QString, QString>> styles;
218
219 if (styles.isEmpty()) {
220 for (auto style : mbgl::util::default_styles::orderedStyles) {
221 styles.append(QPair<QString, QString>(
222 QString::fromStdString(style.url), QString::fromStdString(style.name)));
223 }
224 }
225
226 return styles;
227 }
228
229 } // namespace QMapbox
230