summaryrefslogtreecommitdiff
path: root/platform/qt/src/qmapbox.cpp
blob: 2180f22d07c22f48e25477751f2b001dce9910d8 (plain)
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
#include "qmapbox.hpp"

#include <mbgl/storage/network_status.hpp>
#include <mbgl/util/default_styles.hpp>
#include <mbgl/util/geometry.hpp>
#include <mbgl/util/traits.hpp>

#if QT_VERSION >= 0x050000
#include <QOpenGLContext>
#else
#include <QGLContext>
#endif

// mbgl::NetworkStatus::Status
static_assert(mbgl::underlying_type(QMapbox::Online) == mbgl::underlying_type(mbgl::NetworkStatus::Status::Online), "error");
static_assert(mbgl::underlying_type(QMapbox::Offline) == mbgl::underlying_type(mbgl::NetworkStatus::Status::Offline), "error");

// mbgl::FeatureType
static_assert(mbgl::underlying_type(QMapbox::Feature::PointType) == mbgl::underlying_type(mbgl::FeatureType::Point), "error");
static_assert(mbgl::underlying_type(QMapbox::Feature::LineStringType) == mbgl::underlying_type(mbgl::FeatureType::LineString), "error");
static_assert(mbgl::underlying_type(QMapbox::Feature::PolygonType) == mbgl::underlying_type(mbgl::FeatureType::Polygon), "error");

namespace QMapbox {

/*!
    \namespace QMapbox
    \inmodule Mapbox Maps SDK for Qt

    Contains miscellaneous Mapbox bindings used throughout QMapboxGL.
*/

/*!
    \typedef QMapbox::Coordinate

    Alias for QPair<double, double>.
    Representation for geographical coordinates - latitude and longitude, respectively.
*/

/*!
    \typedef QMapbox::CoordinateZoom

    Alias for QPair<Coordinate, double>.
    Used as return value in QMapboxGL::coordinateZoomForBounds.
*/

/*!
    \typedef QMapbox::ProjectedMeters

    Alias for QPair<double, double>.
    Representation for projected meters - northing and easting, respectively.
*/

/*!
    \typedef QMapbox::Coordinates

    Alias for QList<QMapbox::Coordinate>.
    A list of QMapbox::Coordinate objects.
*/

/*!
    \typedef QMapbox::CoordinatesCollection

    Alias for QList<QMapbox::Coordinates>.
    A list of QMapbox::Coordinates objects.
*/

/*!
    \typedef QMapbox::CoordinatesCollections

    Alias for QList<QMapbox::CoordinatesCollection>.
    A list of QMapbox::CoordinatesCollection objects.
*/

/*!
    \class QMapbox::Feature

    \inmodule Mapbox Maps SDK for Qt

    Represents \l {https://www.mapbox.com/help/define-features/}{map features}
    via its \a type (PointType, LineStringType or PolygonType), \a geometry, \a
    properties map and \a id (optional).
*/

/*!
    \enum QMapbox::Feature::Type

    This enum is used as basis for geometry disambiguation in QMapbox::Feature.

    \value PointType      A point geometry type. Means a single or a collection of points.
    \value LineStringType A line string geometry type. Means a single or a collection of line strings.
    \value PolygonType    A polygon geometry type. Means a single or a collection of polygons.
*/

/*!
    \class QMapbox::ShapeAnnotationGeometry

    \inmodule Mapbox Maps SDK for Qt

    Represents a shape annotation geometry.
*/

/*!
    \enum QMapbox::ShapeAnnotationGeometry::Type

    This enum is used as basis for shape annotation geometry disambiguation.

    \value PolygonType         A polygon geometry type.
    \value LineStringType      A line string geometry type.
    \value MultiPolygonType    A polygon geometry collection type.
    \value MultiLineStringType A line string geometry collection type.
*/

/*!
    \class QMapbox::SymbolAnnotation

    \inmodule Mapbox Maps SDK for Qt

    A symbol annotation comprises of its geometry and an icon identifier.
*/

/*!
    \class QMapbox::LineAnnotation

    \inmodule Mapbox Maps SDK for Qt

    Represents a line annotation object, along with its properties.

    A line annotation comprises of its geometry and line properties such as opacity, width and color.
*/

/*!
    \class QMapbox::FillAnnotation

    \inmodule Mapbox Maps SDK for Qt

    Represents a fill annotation object, along with its properties.

    A fill annotation comprises of its geometry and fill properties such as opacity, color and outline color.
*/

/*!
    \typedef QMapbox::Annotation

    Alias for QVariant.
    Container that encapsulates either a symbol, a line, a fill or a style sourced annotation.
*/

/*!
    \typedef QMapbox::AnnotationID

    Alias for quint32 representing an annotation identifier.
*/

/*!
    \typedef QMapbox::AnnotationIDs

    Alias for QList<quint32> representing a container of annotation identifiers.
*/

/*!
    \class QMapbox::CustomLayerHostInterface

    Represents a host interface to be implemented for rendering custom layers.

    \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.
*/

/*!
    \enum QMapbox::NetworkMode

    This enum represents whether server requests can be performed via network.

    \value Online  Server network requests are accessible.
    \value Offline Only requests to the local cache are accessible.
*/

/*!
    \class QMapbox::CustomLayerRenderParameters
    \inmodule Mapbox Maps SDK for Qt

    QMapbox::CustomLayerRenderParameters provides the data passed on each render
    pass for a custom layer.
*/

/*!
    \fn QMapbox::NetworkMode QMapbox::networkMode()

    Returns the current QMapbox::NetworkMode.
*/
NetworkMode networkMode()
{
    return static_cast<NetworkMode>(mbgl::NetworkStatus::Get());
}

/*!
    \fn void QMapbox::setNetworkMode(QMapbox::NetworkMode mode)

    Forwards the network status \a mode to Mapbox GL Native engine.

    File source requests uses the available network when \a mode is set to \b
    Online, otherwise scoped to the local cache.
*/
void setNetworkMode(NetworkMode mode)
{
    mbgl::NetworkStatus::Set(static_cast<mbgl::NetworkStatus::Status>(mode));
}

/*!
    \fn QList<QPair<QString, QString> >& QMapbox::defaultStyles()

    Returns a list containing a pair of string objects, representing the style
    URL and name, respectively.
*/
QList<QPair<QString, QString> >& defaultStyles()
{
    static QList<QPair<QString, QString>> styles;

    if (styles.isEmpty()) {
        for (auto style : mbgl::util::default_styles::orderedStyles) {
            styles.append(QPair<QString, QString>(
                QString::fromStdString(style.url), QString::fromStdString(style.name)));
        }
    }

    return styles;
}

} // namespace QMapbox