MapLibre Native for Qt
Loading...
Searching...
No Matches
types.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_TYPES_H
7#define QMAPLIBRE_TYPES_H
8
9#include <QMapLibre/Export>
10
11#include <QtCore/QPair>
12#include <QtCore/QString>
13#include <QtCore/QVariant>
14#include <QtCore/QVector>
15#include <QtGui/QColor>
16#include <utility>
17
18namespace QMapLibre {
19
20using Coordinate = QPair<double, double>;
21using CoordinateZoom = QPair<Coordinate, double>;
22using ProjectedMeters = QPair<double, double>;
23
24using Coordinates = QVector<Coordinate>;
25using CoordinatesCollection = QVector<Coordinates>;
26
27using CoordinatesCollections = QVector<CoordinatesCollection>;
28
29struct Q_MAPLIBRE_CORE_EXPORT Style {
30 enum Type { // Taken from Qt to be in sync with QtLocation
31 NoMap = 0,
32 StreetMap,
33 SatelliteMapDay,
34 SatelliteMapNight,
35 TerrainMap,
36 HybridMap,
37 TransitMap,
38 GrayStreetMap,
39 PedestrianMap,
40 CarNavigationMap,
41 CycleMap,
42 CustomMap = 100
43 };
44
45#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
46 explicit Style(QString url_, QString name_ = QString())
47 : url(std::move(url_)),
48 name(std::move(name_)) {}
49#else
50 explicit Style(QString url_ = QString(), QString name_ = QString())
51 : url(std::move(url_)),
52 name(std::move(name_)) {}
53#endif
54
55 QString url;
56 QString name;
57 QString description;
58 bool night{};
59 Type type{CustomMap};
60};
61
62using Styles = QVector<Style>;
63
64struct Q_MAPLIBRE_CORE_EXPORT Feature {
65 enum Type {
66 PointType = 1,
68 PolygonType
69 };
70
72 explicit Feature(Type type_ = PointType,
74 QVariantMap properties_ = QVariantMap(),
75 QVariant id_ = QVariant())
76 : type(type_),
77 geometry(std::move(geometry_)),
78 properties(std::move(properties_)),
79 id(std::move(id_)) {}
80
83 QVariantMap properties;
84 QVariant id;
85};
86
87struct Q_MAPLIBRE_CORE_EXPORT FeatureProperty {
88 enum Type {
89 LayoutProperty = 1,
91 };
92
94 explicit FeatureProperty(Type type_, QString name_, QVariant value_)
95 : type(type_),
96 name(std::move(name_)),
97 value(std::move(value_)) {}
98
100 QString name;
101 QVariant value;
102};
103
104struct Q_MAPLIBRE_CORE_EXPORT ShapeAnnotationGeometry {
105 enum Type {
106 LineStringType = 1,
109 MultiPolygonType
110 };
111
113 explicit ShapeAnnotationGeometry(Type type_ = LineStringType,
115 : type(type_),
116 geometry(std::move(geometry_)) {}
117
120};
121
122struct Q_MAPLIBRE_CORE_EXPORT SymbolAnnotation {
124 QString icon;
125};
126
127struct Q_MAPLIBRE_CORE_EXPORT LineAnnotation {
130 float opacity_ = 1.0f,
131 float width_ = 1.0f,
132 const QColor &color_ = Qt::black)
133 : geometry(std::move(geometry_)),
134 opacity(opacity_),
135 width(width_),
136 color(color_) {}
137
139 float opacity;
140 float width;
141 QColor color;
142};
143
144struct Q_MAPLIBRE_CORE_EXPORT FillAnnotation {
147 float opacity_ = 1.0f,
148 const QColor &color_ = Qt::black,
149 QVariant outlineColor_ = QVariant())
150 : geometry(std::move(geometry_)),
151 opacity(opacity_),
152 color(color_),
153 outlineColor(std::move(outlineColor_)) {}
154
156 float opacity;
157 QColor color;
158 QVariant outlineColor;
159};
160
161using Annotation = QVariant;
162using AnnotationID = quint32;
163using AnnotationIDs = QVector<AnnotationID>;
164
165struct Q_MAPLIBRE_CORE_EXPORT CameraOptions {
166 QVariant center; // Coordinate
167 QVariant anchor; // QPointF
168 QVariant zoom; // double
169 QVariant bearing; // double
170 QVariant pitch; // double
171};
172
173// This struct is a 1:1 copy of mbgl::CustomLayerRenderParameters.
174struct Q_MAPLIBRE_CORE_EXPORT CustomLayerRenderParameters {
175 double width;
176 double height;
177 double latitude;
178 double longitude;
179 double zoom;
180 double bearing;
181 double pitch;
183};
184
185class Q_MAPLIBRE_CORE_EXPORT CustomLayerHostInterface {
186public:
187 virtual ~CustomLayerHostInterface() = default;
188 virtual void initialize() = 0;
189 virtual void render(const CustomLayerRenderParameters &) = 0;
190 virtual void deinitialize() = 0;
191};
192
193} // namespace QMapLibre
194
195Q_DECLARE_METATYPE(QMapLibre::Coordinate);
196Q_DECLARE_METATYPE(QMapLibre::Coordinates);
197Q_DECLARE_METATYPE(QMapLibre::CoordinatesCollection);
198Q_DECLARE_METATYPE(QMapLibre::CoordinatesCollections);
199Q_DECLARE_METATYPE(QMapLibre::Feature);
200
201Q_DECLARE_METATYPE(QMapLibre::SymbolAnnotation);
202Q_DECLARE_METATYPE(QMapLibre::ShapeAnnotationGeometry);
203Q_DECLARE_METATYPE(QMapLibre::LineAnnotation);
204Q_DECLARE_METATYPE(QMapLibre::FillAnnotation);
205
206#endif // QMAPLIBRE_TYPES_H
Definition types.hpp:185
virtual void render(const CustomLayerRenderParameters &)=0
Renders the custom layer with the given parameters.
virtual void deinitialize()=0
Deinitializes the custom layer.
virtual void initialize()=0
Initializes the custom layer.
Definition geojson.cpp:10
QVector< Style > Styles
Style vector.
Definition types.hpp:62
QVector< AnnotationID > AnnotationIDs
A vector of annotation identifiers.
Definition types.hpp:163
QPair< Coordinate, double > CoordinateZoom
Coordinate-zoom pair helper type.
Definition types.hpp:21
QVector< CoordinatesCollection > CoordinatesCollections
CoordinatesCollection vector.
Definition types.hpp:27
QPair< double, double > Coordinate
Coordinate helper type.
Definition types.hpp:20
QVector< Coordinates > CoordinatesCollection
Coordinates vector.
Definition types.hpp:25
quint32 AnnotationID
Annotation identifier helper type.
Definition types.hpp:162
QVariant Annotation
Annotation helper type.
Definition types.hpp:161
QVector< Coordinate > Coordinates
Coordinate vector.
Definition types.hpp:24
QPair< double, double > ProjectedMeters
Projected meters helper type.
Definition types.hpp:22
Camera options helper type.
Definition types.hpp:165
QVariant zoom
camera zoom level (double)
Definition types.hpp:168
QVariant bearing
camera bearing (double)
Definition types.hpp:169
QVariant center
camera center coordinate (Coordinate)
Definition types.hpp:166
QVariant anchor
camera anchor point (QPointF)
Definition types.hpp:167
QVariant pitch
camera pitch (double)
Definition types.hpp:170
double latitude
rendered latitude
Definition types.hpp:177
double fieldOfView
rendered field of view
Definition types.hpp:182
double width
rendered width
Definition types.hpp:175
double pitch
rendered pitch
Definition types.hpp:181
double longitude
rendered longitude
Definition types.hpp:178
double height
rendered height
Definition types.hpp:176
double bearing
rendered bearing
Definition types.hpp:180
double zoom
rendered zoom level
Definition types.hpp:179
Map feature property helper type.
Definition types.hpp:87
QVariant value
property value
Definition types.hpp:101
FeatureProperty(Type type_, QString name_, QVariant value_)
Definition types.hpp:94
Type type
property type
Definition types.hpp:99
QString name
property name
Definition types.hpp:100
Type
Map feature property type.
Definition types.hpp:88
@ PaintProperty
Definition types.hpp:90
Map feature helper type.
Definition types.hpp:64
Type
Map feature type.
Definition types.hpp:65
@ LineStringType
Definition types.hpp:67
QVariantMap properties
feature properties
Definition types.hpp:83
Type type
feature type
Definition types.hpp:81
QVariant id
feature identifier
Definition types.hpp:84
Feature(Type type_=PointType, CoordinatesCollections geometry_=CoordinatesCollections(), QVariantMap properties_=QVariantMap(), QVariant id_=QVariant())
Definition types.hpp:72
CoordinatesCollections geometry
feature geometry
Definition types.hpp:82
Fill annotation helper type.
Definition types.hpp:144
float opacity
annotation opacity
Definition types.hpp:156
QColor color
annotation color
Definition types.hpp:157
ShapeAnnotationGeometry geometry
annotation geometry
Definition types.hpp:155
FillAnnotation(ShapeAnnotationGeometry geometry_=ShapeAnnotationGeometry(), float opacity_=1.0f, const QColor &color_=Qt::black, QVariant outlineColor_=QVariant())
Definition types.hpp:146
QVariant outlineColor
annotation outline color
Definition types.hpp:158
Line annotation helper type.
Definition types.hpp:127
ShapeAnnotationGeometry geometry
annotation geometry
Definition types.hpp:138
float width
annotation width
Definition types.hpp:140
float opacity
annotation opacity
Definition types.hpp:139
QColor color
annotation color
Definition types.hpp:141
LineAnnotation(ShapeAnnotationGeometry geometry_=ShapeAnnotationGeometry(), float opacity_=1.0f, float width_=1.0f, const QColor &color_=Qt::black)
Definition types.hpp:129
Shape annotation geometry helper type.
Definition types.hpp:104
ShapeAnnotationGeometry(Type type_=LineStringType, CoordinatesCollections geometry_=CoordinatesCollections())
Definition types.hpp:113
Type type
annotation geometry type
Definition types.hpp:118
Type
Shape annotation geometry type.
Definition types.hpp:105
@ PolygonType
Definition types.hpp:107
@ MultiLineStringType
Definition types.hpp:108
CoordinatesCollections geometry
annotation geometry
Definition types.hpp:119
Map style helper type.
Definition types.hpp:29
Type
Map style type enumeration.
Definition types.hpp:30
QString description
style description
Definition types.hpp:57
QString name
style name
Definition types.hpp:56
QString url
style URL
Definition types.hpp:55
Style(QString url_, QString name_=QString())
Constructs a Style object with the given url_ and name_.
Definition types.hpp:46
Symbol annotation helper type.
Definition types.hpp:122
Coordinate geometry
annotation geometry
Definition types.hpp:123
QString icon
annotation icon identifier
Definition types.hpp:124