[qt] Rename QMapboxGL to QMapLibreGL (#338)

* Rename QMapboxGL to QMapLibreGL

* Add missing QDebug includes

* Fix Qt CMake config

* Fix geojson warning

* Remove redundant OpenGL dependency

* Put everything under QMapLibreGL namespace

* Reorganise headers

Co-authored-by: Rinigus <rinigus.git@gmail.com>
This commit is contained in:
Tadej Novak
2022-07-03 20:30:46 +02:00
committed by GitHub
parent 7a40d4cbd3
commit 5b3d936521
66 changed files with 1740 additions and 1637 deletions

View File

@@ -6,10 +6,10 @@ find_dependency(Qt@QT_VERSION_MAJOR@
find_dependency(Qt@QT_VERSION_MAJOR@
COMPONENTS Network @REQUIRED_QT_VERSION@)
if(@MBGL_WITH_QT_HEADLESS@ OR NOT @MBGL_WITH_QT_LIB_ONLY@)
find_dependency(Qt@QT_VERSION_MAJOR@
COMPONENTS OpenGL @REQUIRED_QT_VERSION@)
if(@MBGL_QT_STATIC@ AND NOT @MBGL_QT_INSIDE_PLUGIN@ AND NOT @MBGL_QT_WITH_INTERNAL_SQLITE@)
find_dependency(Qt@QT_VERSION_MAJOR@
COMPONENTS Sql @REQUIRED_QT_VERSION@)
endif()
include("${CMAKE_CURRENT_LIST_DIR}/QMapboxGLTargets.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/QMapLibreGLTargets.cmake")
@PACKAGE_INCLUDE_QCHTARGETS@

View File

@@ -6,7 +6,7 @@ int main(int argc, char **argv)
{
QApplication app(argc, argv);
QMapboxGLSettings settings;
QMapLibreGL::Settings settings;
settings.setCacheDatabasePath("/tmp/mbgl-cache.db");
settings.setCacheDatabaseMaximumSize(20 * 1024 * 1024);

View File

@@ -11,7 +11,7 @@
int kAnimationDuration = 10000;
MapWindow::MapWindow(const QMapboxGLSettings &settings)
MapWindow::MapWindow(const QMapLibreGL::Settings &settings)
: m_settings(settings)
{
setWindowIcon(QIcon(":icon.png"));
@@ -20,7 +20,7 @@ MapWindow::MapWindow(const QMapboxGLSettings &settings)
MapWindow::~MapWindow()
{
// Make sure we have a valid context so we
// can delete the QMapboxGL.
// can delete the QMapLibreGL::Map.
makeCurrent();
}
@@ -64,7 +64,7 @@ void MapWindow::changeStyle()
auto& styles = m_map->defaultStyles();
m_map->setStyleUrl(styles[currentStyleIndex].first);
setWindowTitle(QString("Mapbox GL: ") + styles[currentStyleIndex].second);
setWindowTitle(QString("MapLibre GL: ") + styles[currentStyleIndex].second);
if (++currentStyleIndex == styles.size()) {
currentStyleIndex = 0;
@@ -250,10 +250,10 @@ void MapWindow::keyPressEvent(QKeyEvent *ev)
break;
case Qt::Key_1: {
if (m_symbolAnnotationId.isNull()) {
QMapbox::Coordinate coordinate = m_map->coordinate();
QMapbox::SymbolAnnotation symbol { coordinate, "default_marker" };
QMapLibreGL::Coordinate coordinate = m_map->coordinate();
QMapLibreGL::SymbolAnnotation symbol { coordinate, "default_marker" };
m_map->addAnnotationIcon("default_marker", QImage(":default_marker.svg"));
m_symbolAnnotationId = m_map->addAnnotation(QVariant::fromValue<QMapbox::SymbolAnnotation>(symbol));
m_symbolAnnotationId = m_map->addAnnotation(QVariant::fromValue<QMapLibreGL::SymbolAnnotation>(symbol));
} else {
m_map->removeAnnotation(m_symbolAnnotationId.toUInt());
m_symbolAnnotationId.clear();
@@ -262,24 +262,24 @@ void MapWindow::keyPressEvent(QKeyEvent *ev)
break;
case Qt::Key_2: {
if (m_lineAnnotationId.isNull()) {
QMapbox::Coordinates coordinates;
QMapLibreGL::Coordinates coordinates;
coordinates.push_back(m_map->coordinateForPixel({ 0, 0 }));
coordinates.push_back(m_map->coordinateForPixel({ qreal(size().width()), qreal(size().height()) }));
QMapbox::CoordinatesCollection collection;
QMapLibreGL::CoordinatesCollection collection;
collection.push_back(coordinates);
QMapbox::CoordinatesCollections lineGeometry;
QMapLibreGL::CoordinatesCollections lineGeometry;
lineGeometry.push_back(collection);
QMapbox::ShapeAnnotationGeometry annotationGeometry(QMapbox::ShapeAnnotationGeometry::LineStringType, lineGeometry);
QMapLibreGL::ShapeAnnotationGeometry annotationGeometry(QMapLibreGL::ShapeAnnotationGeometry::LineStringType, lineGeometry);
QMapbox::LineAnnotation line;
QMapLibreGL::LineAnnotation line;
line.geometry = annotationGeometry;
line.opacity = 0.5f;
line.width = 1.0f;
line.color = Qt::red;
m_lineAnnotationId = m_map->addAnnotation(QVariant::fromValue<QMapbox::LineAnnotation>(line));
m_lineAnnotationId = m_map->addAnnotation(QVariant::fromValue<QMapLibreGL::LineAnnotation>(line));
} else {
m_map->removeAnnotation(m_lineAnnotationId.toUInt());
m_lineAnnotationId.clear();
@@ -288,26 +288,26 @@ void MapWindow::keyPressEvent(QKeyEvent *ev)
break;
case Qt::Key_3: {
if (m_fillAnnotationId.isNull()) {
QMapbox::Coordinates coordinates;
QMapLibreGL::Coordinates coordinates;
coordinates.push_back(m_map->coordinateForPixel({ qreal(size().width()), 0 }));
coordinates.push_back(m_map->coordinateForPixel({ qreal(size().width()), qreal(size().height()) }));
coordinates.push_back(m_map->coordinateForPixel({ 0, qreal(size().height()) }));
coordinates.push_back(m_map->coordinateForPixel({ 0, 0 }));
QMapbox::CoordinatesCollection collection;
QMapLibreGL::CoordinatesCollection collection;
collection.push_back(coordinates);
QMapbox::CoordinatesCollections fillGeometry;
QMapLibreGL::CoordinatesCollections fillGeometry;
fillGeometry.push_back(collection);
QMapbox::ShapeAnnotationGeometry annotationGeometry(QMapbox::ShapeAnnotationGeometry::PolygonType, fillGeometry);
QMapLibreGL::ShapeAnnotationGeometry annotationGeometry(QMapLibreGL::ShapeAnnotationGeometry::PolygonType, fillGeometry);
QMapbox::FillAnnotation fill;
QMapLibreGL::FillAnnotation fill;
fill.geometry = annotationGeometry;
fill.opacity = 0.5f;
fill.color = Qt::green;
fill.outlineColor = QVariant::fromValue<QColor>(QColor(Qt::black));
m_fillAnnotationId = m_map->addAnnotation(QVariant::fromValue<QMapbox::FillAnnotation>(fill));
m_fillAnnotationId = m_map->addAnnotation(QVariant::fromValue<QMapLibreGL::FillAnnotation>(fill));
} else {
m_map->removeAnnotation(m_fillAnnotationId.toUInt());
m_fillAnnotationId.clear();
@@ -319,20 +319,20 @@ void MapWindow::keyPressEvent(QKeyEvent *ev)
m_map->removeLayer("circleLayer");
m_map->removeSource("circleSource");
} else {
QMapbox::Coordinates coordinates;
QMapLibreGL::Coordinates coordinates;
coordinates.push_back(m_map->coordinate());
QMapbox::CoordinatesCollection collection;
QMapLibreGL::CoordinatesCollection collection;
collection.push_back(coordinates);
QMapbox::CoordinatesCollections point;
QMapLibreGL::CoordinatesCollections point;
point.push_back(collection);
QMapbox::Feature feature(QMapbox::Feature::PointType, point, {}, {});
QMapLibreGL::Feature feature(QMapLibreGL::Feature::PointType, point, {}, {});
QVariantMap circleSource;
circleSource["type"] = "geojson";
circleSource["data"] = QVariant::fromValue<QMapbox::Feature>(feature);
circleSource["data"] = QVariant::fromValue<QMapLibreGL::Feature>(feature);
m_map->addSource("circleSource", circleSource);
QVariantMap circle;
@@ -357,12 +357,12 @@ void MapWindow::keyPressEvent(QKeyEvent *ev)
auto coordinate = m_map->coordinate();
coordinate.first += dx;
coordinate.second += dy;
return QMapbox::Feature{QMapbox::Feature::PointType,
return QMapLibreGL::Feature{QMapLibreGL::Feature::PointType,
{{{coordinate}}}, {{"color", color}}, {}};
};
// multiple features by QVector<QMapbox::Feature>
QVector<QMapbox::Feature> inner{
// multiple features by QVector<QMapLibreGL::Feature>
QVector<QMapLibreGL::Feature> inner{
makePoint(0.001, 0, "red"),
makePoint(0, 0.001, "green"),
makePoint(0, -0.001, "blue")
@@ -376,8 +376,8 @@ void MapWindow::keyPressEvent(QKeyEvent *ev)
{"source", "innerCirclesSource"}
});
// multiple features by QList<QMapbox::Feature>
QList<QMapbox::Feature> outer{
// multiple features by QList<QMapLibreGL::Feature>
QList<QMapLibreGL::Feature> outer{
makePoint( 0.002, 0.002, "cyan"),
makePoint(-0.002, 0.002, "magenta"),
makePoint( 0.002, -0.002, "yellow"),
@@ -476,11 +476,11 @@ void MapWindow::wheelEvent(QWheelEvent *ev)
void MapWindow::initializeGL()
{
m_map.reset(new QMapboxGL(nullptr, m_settings, size(), pixelRatio()));
m_map.reset(new QMapLibreGL::Map(nullptr, m_settings, size(), pixelRatio()));
connect(m_map.get(), SIGNAL(needsRendering()), this, SLOT(update()));
// Set default location to Helsinki.
m_map->setCoordinateZoom(QMapbox::Coordinate(60.170448, 24.942046), 5);
m_map->setCoordinateZoom(QMapLibreGL::Coordinate(60.170448, 24.942046), 5);
QString styleUrl = qgetenv("MGL_STYLE_URL");
if (styleUrl.isEmpty()) {

View File

@@ -1,11 +1,12 @@
#ifndef MAPWINDOW_H
#define MAPWINDOW_H
#include <QMapboxGL>
#include <QMapLibreGL/Map>
#include <QMapLibreGL/Settings>
#include <QtGlobal>
#include <QOpenGLWidget>
#include <QPropertyAnimation>
#include <QtGlobal>
#include <memory>
@@ -18,7 +19,7 @@ class MapWindow : public QOpenGLWidget
Q_OBJECT
public:
MapWindow(const QMapboxGLSettings &);
MapWindow(const QMapLibreGL::Settings &);
~MapWindow();
void selfTest();
@@ -43,20 +44,20 @@ private:
QPointF m_lastPos;
QMapboxGLSettings m_settings;
std::unique_ptr<QMapboxGL> m_map{};
QMapLibreGL::Settings m_settings;
std::unique_ptr<QMapLibreGL::Map> m_map{};
QPropertyAnimation *m_bearingAnimation;
QPropertyAnimation *m_zoomAnimation;
QPropertyAnimation *m_bearingAnimation{};
QPropertyAnimation *m_zoomAnimation{};
unsigned m_animationTicks = 0;
unsigned m_frameDraws = 0;
unsigned m_animationTicks{};
unsigned m_frameDraws{};
QVariant m_symbolAnnotationId;
QVariant m_lineAnnotationId;
QVariant m_fillAnnotationId;
bool m_sourceAdded = false;
bool m_sourceAdded{};
};
#endif

View File

@@ -4,10 +4,10 @@ include($QT_INSTALL_DOCS/global/compat.qdocconf)
include($QT_INSTALL_DOCS/global/fileextensions.qdocconf)
include($QT_INSTALL_DOCS/global/qt-html-templates-online.qdocconf)
Cpp.ignoretokens = Q_MAPBOXGL_EXPORT
Cpp.ignoretokens = Q_MAPLIBRE_EXPORT
project = QMapboxGL
description = Mapbox Maps SDK for Qt
project = QMapLibreGL
description = MapLibre GL Maps SDK for Qt
language = Cpp
outputdir = docs

View File

@@ -0,0 +1 @@
#include "map.hpp"

View File

@@ -0,0 +1 @@
#include "settings.hpp"

View File

@@ -0,0 +1 @@
#include "types.hpp"

View File

@@ -0,0 +1 @@
#include "utils.hpp"

View File

@@ -0,0 +1,16 @@
#ifndef QMAPLIBRE_EXPORT_H
#define QMAPLIBRE_EXPORT_H
// This header follows the Qt coding style: https://wiki.qt.io/Qt_Coding_Style
#if !defined(QT_MAPLIBREGL_STATIC)
# if defined(QT_BUILD_MAPLIBREGL_LIB)
# define Q_MAPLIBREGL_EXPORT Q_DECL_EXPORT
# else
# define Q_MAPLIBREGL_EXPORT Q_DECL_IMPORT
# endif
#else
# define Q_MAPLIBREGL_EXPORT
#endif
#endif // QMAPLIBRE_EXPORT_H

View File

@@ -1,8 +1,10 @@
#ifndef QMAPBOXGL_H
#define QMAPBOXGL_H
#ifndef QMAPLIBREGL_MAP_H
#define QMAPLIBREGL_MAP_H
#include <QMapLibreGL/Settings>
#include <QMapLibreGL/Types>
#include <QImage>
#include <QMapbox>
#include <QMargins>
#include <QObject>
#include <QPointF>
@@ -13,113 +15,13 @@
#include <functional>
#include <memory>
class QMapboxGLPrivate;
namespace QMapLibreGL {
class MapPrivate;
// This header follows the Qt coding style: https://wiki.qt.io/Qt_Coding_Style
// TODO: this will be wrapped at some point
namespace mbgl
{
class TileServerOptions;
}
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
};
enum SettingsTemplate {
DefaultSettings = 0,
MapLibreSettings,
MapTilerSettings,
MapboxSettings
};
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 apiKey() const;
void setApiKey(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 &)> &);
void resetToTemplate(SettingsTemplate);
QVector<QPair<QString, QString>> defaultStyles() const;
mbgl::TileServerOptions *tileServerOptionsInternal() const;
private:
GLContextMode m_contextMode;
MapMode m_mapMode;
ConstrainMode m_constrainMode;
ViewportMode m_viewportMode;
unsigned m_cacheMaximumSize;
QString m_cacheDatabasePath;
QString m_assetPath;
QString m_apiKey;
QString m_localFontFamily;
std::function<std::string(const std::string &)> m_resourceTransform;
mbgl::TileServerOptions *m_tileServerOptionsInternal{};
};
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
class Q_MAPLIBREGL_EXPORT Map : public QObject
{
Q_OBJECT
Q_PROPERTY(double latitude READ latitude WRITE setLatitude)
@@ -130,7 +32,7 @@ class Q_MAPBOXGL_EXPORT QMapboxGL : public QObject
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(QMapLibreGL::Coordinate coordinate READ coordinate WRITE setCoordinate)
Q_PROPERTY(QMargins margins READ margins WRITE setMargins)
public:
@@ -168,11 +70,11 @@ public:
NorthLeftwards,
};
QMapboxGL(QObject* parent = 0,
const QMapboxGLSettings& = QMapboxGLSettings(),
const QSize& size = QSize(),
qreal pixelRatio = 1);
virtual ~QMapboxGL();
Map(QObject* parent = 0,
const Settings& = Settings(),
const QSize& size = QSize(),
qreal pixelRatio = 1);
virtual ~Map();
QString styleJson() const;
QString styleUrl() const;
@@ -206,11 +108,11 @@ public:
NorthOrientation northOrientation() const;
void setNorthOrientation(NorthOrientation);
QMapbox::Coordinate coordinate() const;
void setCoordinate(const QMapbox::Coordinate &);
void setCoordinateZoom(const QMapbox::Coordinate &, double zoom);
Coordinate coordinate() const;
void setCoordinate(const Coordinate &);
void setCoordinateZoom(const Coordinate &, double zoom);
void jumpTo(const QMapboxGLCameraOptions&);
void jumpTo(const CameraOptions&);
void setGestureInProgress(bool inProgress);
@@ -218,9 +120,9 @@ public:
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);
AnnotationID addAnnotation(const Annotation &);
void updateAnnotation(AnnotationID, const Annotation &);
void removeAnnotation(AnnotationID);
bool setLayoutProperty(const QString &layer, const QString &property, const QVariant &value);
bool setPaintProperty(const QString &layer, const QString &property, const QVariant &value);
@@ -233,17 +135,14 @@ public:
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;
QPointF pixelForCoordinate(const Coordinate &) const;
Coordinate coordinateForPixel(const QPointF &) const;
QMapbox::CoordinateZoom coordinateZoomForBounds(const QMapbox::Coordinate &sw, const QMapbox::Coordinate &ne) const;
QMapbox::CoordinateZoom coordinateZoomForBounds(const QMapbox::Coordinate &sw,
const QMapbox::Coordinate &ne,
double bearing,
double pitch);
CoordinateZoom coordinateZoomForBounds(const Coordinate &sw, const Coordinate &ne) const;
CoordinateZoom coordinateZoomForBounds(const Coordinate &sw,
const Coordinate &ne,
double bearing,
double pitch);
void setMargins(const QMargins &margins);
QMargins margins() const;
@@ -257,7 +156,7 @@ public:
void removeImage(const QString &name);
void addCustomLayer(const QString &id,
std::unique_ptr<QMapbox::CustomLayerHostInterface> host,
std::unique_ptr<CustomLayerHostInterface> host,
const QString &before = QString());
void addLayer(const QVariantMap &params, const QString& before = QString());
bool layerExists(const QString &id);
@@ -285,19 +184,21 @@ public slots:
signals:
void needsRendering();
void mapChanged(QMapboxGL::MapChange);
void mapLoadingFailed(QMapboxGL::MapLoadingFailure, const QString &reason);
void mapChanged(Map::MapChange);
void mapLoadingFailed(Map::MapLoadingFailure, const QString &reason);
void copyrightsChanged(const QString &copyrightsHtml);
void staticRenderFinished(const QString &error);
private:
Q_DISABLE_COPY(QMapboxGL)
Q_DISABLE_COPY(Map)
QMapboxGLPrivate *d_ptr;
MapPrivate *d_ptr;
};
Q_DECLARE_METATYPE(QMapboxGL::MapChange);
Q_DECLARE_METATYPE(QMapboxGL::MapLoadingFailure);
} // namespace QMapLibreGL
#endif // QMAPBOXGL_H
Q_DECLARE_METATYPE(QMapLibreGL::Map::MapChange);
Q_DECLARE_METATYPE(QMapLibreGL::Map::MapLoadingFailure);
#endif // QMAPLIBREGL_MAP_H

View File

@@ -0,0 +1,112 @@
#ifndef QMAPLIBREGL_SETTINGS_H
#define QMAPLIBREGL_SETTINGS_H
#include <QImage>
#include <QString>
#include <functional>
#include "export.hpp"
// This header follows the Qt coding style: https://wiki.qt.io/Qt_Coding_Style
// TODO: this will be wrapped at some point
namespace mbgl
{
class TileServerOptions;
}
namespace QMapLibreGL {
class Q_MAPLIBREGL_EXPORT Settings
{
public:
Settings();
enum GLContextMode {
UniqueGLContext = 0,
SharedGLContext
};
enum MapMode {
Continuous = 0,
Static
};
enum ConstrainMode {
NoConstrain = 0,
ConstrainHeightOnly,
ConstrainWidthAndHeight
};
enum ViewportMode {
DefaultViewport = 0,
FlippedYViewport
};
enum SettingsTemplate {
DefaultSettings = 0,
MapLibreSettings,
MapTilerSettings,
MapboxSettings
};
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 apiKey() const;
void setApiKey(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 &)> &);
void resetToTemplate(SettingsTemplate);
QVector<QPair<QString, QString>> defaultStyles() const;
mbgl::TileServerOptions *tileServerOptionsInternal() const;
private:
GLContextMode m_contextMode;
MapMode m_mapMode;
ConstrainMode m_constrainMode;
ViewportMode m_viewportMode;
unsigned m_cacheMaximumSize;
QString m_cacheDatabasePath;
QString m_assetPath;
QString m_apiKey;
QString m_localFontFamily;
std::function<std::string(const std::string &)> m_resourceTransform;
mbgl::TileServerOptions *m_tileServerOptionsInternal{};
};
} // namespace QMapLibreGL
#endif // QMAPLIBREGL_SETTINGS_H

View File

@@ -1,5 +1,5 @@
#ifndef QMAPBOX_H
#define QMAPBOX_H
#ifndef QMAPLIBREGL_TYPES_H
#define QMAPLIBREGL_TYPES_H
#include <QColor>
#include <QPair>
@@ -7,19 +7,9 @@
#include <QVariant>
#include <QVector>
// This header follows the Qt coding style: https://wiki.qt.io/Qt_Coding_Style
#include "export.hpp"
#if !defined(QT_MAPBOXGL_STATIC)
# if defined(QT_BUILD_MAPBOXGL_LIB)
# define Q_MAPBOXGL_EXPORT Q_DECL_EXPORT
# else
# define Q_MAPBOXGL_EXPORT Q_DECL_IMPORT
# endif
#else
# define Q_MAPBOXGL_EXPORT
#endif
namespace QMapbox {
namespace QMapLibreGL {
typedef QPair<double, double> Coordinate;
typedef QPair<Coordinate, double> CoordinateZoom;
@@ -30,7 +20,7 @@ typedef QVector<Coordinates> CoordinatesCollection;
typedef QVector<CoordinatesCollection> CoordinatesCollections;
struct Q_MAPBOXGL_EXPORT Feature {
struct Q_MAPLIBREGL_EXPORT Feature {
enum Type {
PointType = 1,
LineStringType,
@@ -48,7 +38,7 @@ struct Q_MAPBOXGL_EXPORT Feature {
QVariant id;
};
struct Q_MAPBOXGL_EXPORT ShapeAnnotationGeometry {
struct Q_MAPLIBREGL_EXPORT ShapeAnnotationGeometry {
enum Type {
LineStringType = 1,
PolygonType,
@@ -64,12 +54,12 @@ struct Q_MAPBOXGL_EXPORT ShapeAnnotationGeometry {
CoordinatesCollections geometry;
};
struct Q_MAPBOXGL_EXPORT SymbolAnnotation {
struct Q_MAPLIBREGL_EXPORT SymbolAnnotation {
Coordinate geometry;
QString icon;
};
struct Q_MAPBOXGL_EXPORT LineAnnotation {
struct Q_MAPLIBREGL_EXPORT LineAnnotation {
/*! Class constructor. */
LineAnnotation(const ShapeAnnotationGeometry& geometry_ = ShapeAnnotationGeometry(), float opacity_ = 1.0f,
float width_ = 1.0f, const QColor& color_ = Qt::black)
@@ -81,7 +71,7 @@ struct Q_MAPBOXGL_EXPORT LineAnnotation {
QColor color;
};
struct Q_MAPBOXGL_EXPORT FillAnnotation {
struct Q_MAPLIBREGL_EXPORT FillAnnotation {
/*! Class constructor. */
FillAnnotation(const ShapeAnnotationGeometry& geometry_ = ShapeAnnotationGeometry(), float opacity_ = 1.0f,
const QColor& color_ = Qt::black, const QVariant& outlineColor_ = QVariant())
@@ -97,16 +87,16 @@ typedef QVariant Annotation;
typedef quint32 AnnotationID;
typedef QVector<AnnotationID> AnnotationIDs;
enum NetworkMode {
Online, // Default
Offline,
struct Q_MAPLIBREGL_EXPORT CameraOptions {
QVariant center; // Coordinate
QVariant anchor; // QPointF
QVariant zoom; // double
QVariant bearing; // double
QVariant pitch; // double
};
Q_MAPBOXGL_EXPORT NetworkMode networkMode();
Q_MAPBOXGL_EXPORT void setNetworkMode(NetworkMode);
// This struct is a 1:1 copy of mbgl::CustomLayerRenderParameters.
struct Q_MAPBOXGL_EXPORT CustomLayerRenderParameters {
struct Q_MAPLIBREGL_EXPORT CustomLayerRenderParameters {
double width;
double height;
double latitude;
@@ -117,7 +107,7 @@ struct Q_MAPBOXGL_EXPORT CustomLayerRenderParameters {
double fieldOfView;
};
class Q_MAPBOXGL_EXPORT CustomLayerHostInterface {
class Q_MAPLIBREGL_EXPORT CustomLayerHostInterface {
public:
virtual ~CustomLayerHostInterface() = default;
virtual void initialize() = 0;
@@ -125,21 +115,17 @@ public:
virtual void deinitialize() = 0;
};
Q_MAPBOXGL_EXPORT double metersPerPixelAtLatitude(double latitude, double zoom);
Q_MAPBOXGL_EXPORT ProjectedMeters projectedMetersForCoordinate(const Coordinate &);
Q_MAPBOXGL_EXPORT Coordinate coordinateForProjectedMeters(const ProjectedMeters &);
} // namespace QMapLibreGL
} // namespace QMapbox
Q_DECLARE_METATYPE(QMapLibreGL::Coordinate);
Q_DECLARE_METATYPE(QMapLibreGL::Coordinates);
Q_DECLARE_METATYPE(QMapLibreGL::CoordinatesCollection);
Q_DECLARE_METATYPE(QMapLibreGL::CoordinatesCollections);
Q_DECLARE_METATYPE(QMapLibreGL::Feature);
Q_DECLARE_METATYPE(QMapbox::Coordinate);
Q_DECLARE_METATYPE(QMapbox::Coordinates);
Q_DECLARE_METATYPE(QMapbox::CoordinatesCollection);
Q_DECLARE_METATYPE(QMapbox::CoordinatesCollections);
Q_DECLARE_METATYPE(QMapbox::Feature);
Q_DECLARE_METATYPE(QMapLibreGL::SymbolAnnotation);
Q_DECLARE_METATYPE(QMapLibreGL::ShapeAnnotationGeometry);
Q_DECLARE_METATYPE(QMapLibreGL::LineAnnotation);
Q_DECLARE_METATYPE(QMapLibreGL::FillAnnotation);
Q_DECLARE_METATYPE(QMapbox::SymbolAnnotation);
Q_DECLARE_METATYPE(QMapbox::ShapeAnnotationGeometry);
Q_DECLARE_METATYPE(QMapbox::LineAnnotation);
Q_DECLARE_METATYPE(QMapbox::FillAnnotation);
#endif // QMAPBOX_H
#endif // QMAPLIBREGL_TYPES_H

View File

@@ -0,0 +1,25 @@
#ifndef QMAPLIBREGL_UTILS_H
#define QMAPLIBREGL_UTILS_H
#include "export.hpp"
#include "types.hpp"
// This header follows the Qt coding style: https://wiki.qt.io/Qt_Coding_Style
namespace QMapLibreGL {
enum NetworkMode {
Online, // Default
Offline,
};
Q_MAPLIBREGL_EXPORT NetworkMode networkMode();
Q_MAPLIBREGL_EXPORT void setNetworkMode(NetworkMode);
Q_MAPLIBREGL_EXPORT double metersPerPixelAtLatitude(double latitude, double zoom);
Q_MAPLIBREGL_EXPORT ProjectedMeters projectedMetersForCoordinate(const Coordinate &);
Q_MAPLIBREGL_EXPORT Coordinate coordinateForProjectedMeters(const ProjectedMeters &);
} // namespace QMapLibreGL
#endif // QMAPLIBREGL_UTILS_H

View File

@@ -1 +0,0 @@
#include "qmapbox.hpp"

View File

@@ -1 +0,0 @@
#include "qmapboxgl.hpp"

Binary file not shown.

View File

@@ -7,25 +7,22 @@ set(MBGL_QT_VERSION_COMPATIBILITY 2.0.0)
message(STATUS "Version ${MBGL_QT_VERSION}")
option(MBGL_QT_LIBRARY_ONLY "Build only libraries" OFF)
option(MBGL_QT_STATIC "Build Mapbox GL Qt bindings staticly" OFF)
option(MBGL_QT_INSIDE_PLUGIN "Build qmapboxgl as OBJECT library, so it can be bundled into separate single plugin lib." OFF)
option(MBGL_WITH_QT_HEADLESS "Build Mapbox GL Qt with headless support" ON)
option(MBGL_QT_WITH_INTERNAL_SQLITE "Build Mapbox GL Qt bindings with internal sqlite" OFF)
option(MBGL_QT_STATIC "Build MapLibre GL Qt bindings staticly" OFF)
option(MBGL_QT_INSIDE_PLUGIN "Build QMapLibreGL as OBJECT library, so it can be bundled into separate single plugin lib." OFF)
option(MBGL_QT_WITH_HEADLESS "Build MapLibre GL Qt with headless support" ON)
option(MBGL_QT_WITH_INTERNAL_SQLITE "Build MapLibre GL Qt bindings with internal sqlite" OFF)
find_package(QT NAMES Qt6 Qt5 COMPONENTS Core REQUIRED)
find_package(Qt${QT_VERSION_MAJOR}
COMPONENTS Gui
Network
REQUIRED)
if (Qt6_FOUND)
find_package(Qt${QT_VERSION_MAJOR}OpenGLWidgets REQUIRED)
endif()
if(MBGL_WITH_QT_HEADLESS OR NOT MBGL_QT_LIBRARY_ONLY)
find_package(Qt${QT_VERSION_MAJOR}
COMPONENTS OpenGL
Widgets
REQUIRED)
if(NOT MBGL_QT_LIBRARY_ONLY)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets REQUIRED)
if (Qt6_FOUND)
find_package(Qt${QT_VERSION_MAJOR}OpenGLWidgets REQUIRED)
endif()
endif()
if(NOT MBGL_QT_WITH_INTERNAL_SQLITE)
@@ -36,7 +33,7 @@ else()
endif()
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
option(MBGL_QT_WITH_INTERNAL_ICU "Build Mapbox GL Qt bindings with internal ICU" OFF)
option(MBGL_QT_WITH_INTERNAL_ICU "Build MapLibre GL Qt bindings with internal ICU" OFF)
if(NOT MBGL_QT_WITH_INTERNAL_ICU)
find_package(ICU COMPONENTS uc REQUIRED)
else()
@@ -72,7 +69,7 @@ endif()
target_sources(
mbgl-core
PRIVATE
${PROJECT_SOURCE_DIR}/platform/$<IF:$<PLATFORM_ID:Linux>,default/src/mbgl/text/bidi.cpp,qt/src/bidi.cpp>
${PROJECT_SOURCE_DIR}/platform/$<IF:$<PLATFORM_ID:Linux>,default/src/mbgl/text/bidi.cpp,qt/src/mbgl/bidi.cpp>
${PROJECT_SOURCE_DIR}/platform/default/include/mbgl/gfx/headless_backend.hpp
${PROJECT_SOURCE_DIR}/platform/default/include/mbgl/gfx/headless_frontend.hpp
${PROJECT_SOURCE_DIR}/platform/default/include/mbgl/gl/headless_backend.hpp
@@ -94,43 +91,31 @@ target_sources(
${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/storage/offline_database.cpp
${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/storage/offline_download.cpp
${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/storage/online_file_source.cpp
${PROJECT_SOURCE_DIR}/platform/$<IF:$<BOOL:${MBGL_QT_WITH_INTERNAL_SQLITE}>,default/src/mbgl/storage/sqlite3.cpp,qt/src/sqlite3.cpp>
${PROJECT_SOURCE_DIR}/platform/$<IF:$<BOOL:${MBGL_QT_WITH_INTERNAL_SQLITE}>,default/src/mbgl/storage/sqlite3.cpp,qt/src/mbgl/sqlite3.cpp>
${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/util/compression.cpp
${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/util/monotonic_timer.cpp
${PROJECT_SOURCE_DIR}/platform/qt/src/async_task.cpp
${PROJECT_SOURCE_DIR}/platform/qt/src/async_task_impl.hpp
${PROJECT_SOURCE_DIR}/platform/qt/src/number_format.cpp
${PROJECT_SOURCE_DIR}/platform/qt/src/gl_functions.cpp
$<$<BOOL:${MBGL_PUBLIC_BUILD}>:${PROJECT_SOURCE_DIR}/platform/qt/src/http_file_source.cpp>
$<$<BOOL:${MBGL_PUBLIC_BUILD}>:${PROJECT_SOURCE_DIR}/platform/qt/src/http_file_source.hpp>
$<$<BOOL:${MBGL_PUBLIC_BUILD}>:${PROJECT_SOURCE_DIR}/platform/qt/src/http_request.cpp>
$<$<BOOL:${MBGL_PUBLIC_BUILD}>:${PROJECT_SOURCE_DIR}/platform/qt/src/http_request.hpp>
${PROJECT_SOURCE_DIR}/platform/qt/src/local_glyph_rasterizer.cpp
${PROJECT_SOURCE_DIR}/platform/qt/src/qt_image.cpp
${PROJECT_SOURCE_DIR}/platform/qt/src/qt_logging.cpp
${PROJECT_SOURCE_DIR}/platform/qt/src/run_loop.cpp
${PROJECT_SOURCE_DIR}/platform/qt/src/run_loop_impl.hpp
${PROJECT_SOURCE_DIR}/platform/qt/src/string_stdlib.cpp
${PROJECT_SOURCE_DIR}/platform/qt/src/thread.cpp
${PROJECT_SOURCE_DIR}/platform/qt/src/thread_local.cpp
${PROJECT_SOURCE_DIR}/platform/qt/src/timer.cpp
${PROJECT_SOURCE_DIR}/platform/qt/src/timer_impl.hpp
${PROJECT_SOURCE_DIR}/platform/qt/src/utf.cpp
$<$<BOOL:${MBGL_QT_WITH_HEADLESS}>:${PROJECT_SOURCE_DIR}/platform/qt/src/mbgl/headless_backend_qt.cpp>
${PROJECT_SOURCE_DIR}/platform/qt/src/mbgl/async_task.cpp
${PROJECT_SOURCE_DIR}/platform/qt/src/mbgl/async_task_impl.hpp
${PROJECT_SOURCE_DIR}/platform/qt/src/mbgl/gl_functions.cpp
$<$<BOOL:${MBGL_PUBLIC_BUILD}>:${PROJECT_SOURCE_DIR}/platform/qt/src/mbgl/http_file_source.cpp>
$<$<BOOL:${MBGL_PUBLIC_BUILD}>:${PROJECT_SOURCE_DIR}/platform/qt/src/mbgl/http_file_source.hpp>
$<$<BOOL:${MBGL_PUBLIC_BUILD}>:${PROJECT_SOURCE_DIR}/platform/qt/src/mbgl/http_request.cpp>
$<$<BOOL:${MBGL_PUBLIC_BUILD}>:${PROJECT_SOURCE_DIR}/platform/qt/src/mbgl/http_request.hpp>
${PROJECT_SOURCE_DIR}/platform/qt/src/mbgl/image.cpp
${PROJECT_SOURCE_DIR}/platform/qt/src/mbgl/number_format.cpp
${PROJECT_SOURCE_DIR}/platform/qt/src/mbgl/local_glyph_rasterizer.cpp
${PROJECT_SOURCE_DIR}/platform/qt/src/mbgl/logging_qt.cpp
${PROJECT_SOURCE_DIR}/platform/qt/src/mbgl/run_loop.cpp
${PROJECT_SOURCE_DIR}/platform/qt/src/mbgl/run_loop_impl.hpp
${PROJECT_SOURCE_DIR}/platform/qt/src/mbgl/string_stdlib.cpp
${PROJECT_SOURCE_DIR}/platform/qt/src/mbgl/thread.cpp
${PROJECT_SOURCE_DIR}/platform/qt/src/mbgl/thread_local.cpp
${PROJECT_SOURCE_DIR}/platform/qt/src/mbgl/timer.cpp
${PROJECT_SOURCE_DIR}/platform/qt/src/mbgl/timer_impl.hpp
${PROJECT_SOURCE_DIR}/platform/qt/src/mbgl/utf.cpp
)
if(MBGL_WITH_QT_HEADLESS OR NOT MBGL_QT_LIBRARY_ONLY)
target_sources(
mbgl-core
PRIVATE
${PROJECT_SOURCE_DIR}/platform/qt/src/headless_backend_qt.cpp
)
target_link_libraries(
mbgl-core
PRIVATE
Qt${QT_VERSION_MAJOR}::OpenGL
)
endif()
target_compile_definitions(
mbgl-core
PRIVATE QT_IMAGE_DECODERS
@@ -159,84 +144,100 @@ target_link_libraries(
mbgl-vendor-nunicode
)
set(qmapboxgl_headers
${PROJECT_SOURCE_DIR}/platform/qt/include/QMapbox
${PROJECT_SOURCE_DIR}/platform/qt/include/QMapboxGL
${PROJECT_SOURCE_DIR}/platform/qt/include/qmapbox.hpp
${PROJECT_SOURCE_DIR}/platform/qt/include/qmapboxgl.hpp
set(qmaplibregl_headers
${PROJECT_SOURCE_DIR}/platform/qt/include/QMapLibreGL/export.hpp
${PROJECT_SOURCE_DIR}/platform/qt/include/QMapLibreGL/map.hpp
${PROJECT_SOURCE_DIR}/platform/qt/include/QMapLibreGL/Map
${PROJECT_SOURCE_DIR}/platform/qt/include/QMapLibreGL/settings.hpp
${PROJECT_SOURCE_DIR}/platform/qt/include/QMapLibreGL/Settings
${PROJECT_SOURCE_DIR}/platform/qt/include/QMapLibreGL/types.hpp
${PROJECT_SOURCE_DIR}/platform/qt/include/QMapLibreGL/Types
${PROJECT_SOURCE_DIR}/platform/qt/include/QMapLibreGL/utils.hpp
${PROJECT_SOURCE_DIR}/platform/qt/include/QMapLibreGL/Utils
)
if (MBGL_QT_INSIDE_PLUGIN)
add_library(qmapboxgl OBJECT)
add_library(qmaplibregl OBJECT)
elseif(MBGL_QT_STATIC)
add_library(qmapboxgl STATIC)
add_library(qmaplibregl STATIC)
else()
add_library(qmapboxgl SHARED)
add_library(qmaplibregl SHARED)
endif()
target_sources(
qmapboxgl
qmaplibregl
PRIVATE
${qmapboxgl_headers}
${PROJECT_SOURCE_DIR}/platform/qt/src/qmapbox.cpp
${PROJECT_SOURCE_DIR}/platform/qt/src/qmapboxgl.cpp
${PROJECT_SOURCE_DIR}/platform/qt/src/qmapboxgl_map_observer.cpp
${PROJECT_SOURCE_DIR}/platform/qt/src/qmapboxgl_map_observer.hpp
${PROJECT_SOURCE_DIR}/platform/qt/src/qmapboxgl_map_renderer.cpp
${PROJECT_SOURCE_DIR}/platform/qt/src/qmapboxgl_map_renderer.hpp
${PROJECT_SOURCE_DIR}/platform/qt/src/qmapboxgl_p.hpp
${PROJECT_SOURCE_DIR}/platform/qt/src/qmapboxgl_renderer_backend.cpp
${PROJECT_SOURCE_DIR}/platform/qt/src/qmapboxgl_renderer_backend.hpp
${PROJECT_SOURCE_DIR}/platform/qt/src/qmapboxgl_scheduler.cpp
${PROJECT_SOURCE_DIR}/platform/qt/src/qmapboxgl_scheduler.hpp
${PROJECT_SOURCE_DIR}/platform/qt/src/qt_conversion.hpp
${PROJECT_SOURCE_DIR}/platform/qt/src/qt_geojson.cpp
${PROJECT_SOURCE_DIR}/platform/qt/src/qt_geojson.hpp
${qmaplibregl_headers}
${PROJECT_SOURCE_DIR}/platform/qt/src/map.cpp
${PROJECT_SOURCE_DIR}/platform/qt/src/map_p.hpp
${PROJECT_SOURCE_DIR}/platform/qt/src/settings.cpp
${PROJECT_SOURCE_DIR}/platform/qt/src/types.cpp
${PROJECT_SOURCE_DIR}/platform/qt/src/utils.cpp
${PROJECT_SOURCE_DIR}/platform/qt/src/utils/map_observer.cpp
${PROJECT_SOURCE_DIR}/platform/qt/src/utils/map_observer.hpp
${PROJECT_SOURCE_DIR}/platform/qt/src/utils/map_renderer.cpp
${PROJECT_SOURCE_DIR}/platform/qt/src/utils/map_renderer.hpp
${PROJECT_SOURCE_DIR}/platform/qt/src/utils/renderer_backend.cpp
${PROJECT_SOURCE_DIR}/platform/qt/src/utils/renderer_backend.hpp
${PROJECT_SOURCE_DIR}/platform/qt/src/utils/renderer_observer.hpp
${PROJECT_SOURCE_DIR}/platform/qt/src/utils/scheduler.cpp
${PROJECT_SOURCE_DIR}/platform/qt/src/utils/scheduler.hpp
${PROJECT_SOURCE_DIR}/platform/qt/src/utils/conversion.hpp
${PROJECT_SOURCE_DIR}/platform/qt/src/utils/geojson.cpp
${PROJECT_SOURCE_DIR}/platform/qt/src/utils/geojson.hpp
)
# Linux/Mac: Set framework, version and headers
set_target_properties(
qmapboxgl PROPERTIES
qmaplibregl PROPERTIES
AUTOMOC ON
EXPORT_NAME QMapboxGL
OUTPUT_NAME QMapboxGL
EXPORT_NAME QMapLibreGL
OUTPUT_NAME QMapLibreGL
VERSION ${MBGL_QT_VERSION}
SOVERSION ${MBGL_QT_VERSION_COMPATIBILITY}
PUBLIC_HEADER "${qmapboxgl_headers}"
PUBLIC_HEADER "${qmaplibregl_headers}"
)
if (NOT MBGL_QT_STATIC AND NOT MBGL_QT_INSIDE_PLUGIN)
if (APPLE AND NOT MBGL_QT_STATIC AND NOT MBGL_QT_INSIDE_PLUGIN)
set_target_properties(
qmapboxgl PROPERTIES
qmaplibregl PROPERTIES
FRAMEWORK ON
FRAMEWORK_VERSION A
MACOSX_FRAMEWORK_IDENTIFIER org.maplibre.QMapLibreGL
MACOSX_FRAMEWORK_BUNDLE_VERSION ${MBGL_QT_VERSION}
MACOSX_FRAMEWORK_SHORT_VERSION_STRING ${MBGL_QT_VERSION}
)
target_include_directories(
qmaplibregl
INTERFACE
$<INSTALL_INTERFACE:lib/QMapLibreGL.framework>
)
endif()
include(CMakePackageConfigHelpers)
set(CMAKECONFIG_INSTALL_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/QMapboxGL/)
set(CMAKECONFIG_INSTALL_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/QMapLibreGL/)
configure_package_config_file(
"platform/qt/QMapboxGLConfig.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/QMapboxGLConfig.cmake"
INSTALL_DESTINATION ${CMAKECONFIG_INSTALL_DIR}
PATH_VARS CMAKE_INSTALL_PREFIX CMAKE_INSTALL_INCLUDEDIR
CMAKE_INSTALL_LIBDIR NO_CHECK_REQUIRED_COMPONENTS_MACRO)
"platform/qt/QMapLibreGLConfig.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/QMapLibreGLConfig.cmake"
INSTALL_DESTINATION ${CMAKECONFIG_INSTALL_DIR}
PATH_VARS CMAKE_INSTALL_PREFIX CMAKE_INSTALL_INCLUDEDIR
CMAKE_INSTALL_LIBDIR NO_CHECK_REQUIRED_COMPONENTS_MACRO)
write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/QMapboxGLConfigVersion.cmake
VERSION ${MBGL_QT_VERSION}
COMPATIBILITY AnyNewerVersion)
write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/QMapLibreGLConfigVersion.cmake
VERSION ${MBGL_QT_VERSION}
COMPATIBILITY AnyNewerVersion)
install(EXPORT QMapboxGLTargets
DESTINATION ${CMAKECONFIG_INSTALL_DIR}
COMPONENT development)
install(EXPORT QMapLibreGLTargets
DESTINATION ${CMAKECONFIG_INSTALL_DIR}
COMPONENT development)
export(EXPORT QMapboxGLTargets)
export(EXPORT QMapLibreGLTargets)
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/QMapboxGLConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/QMapboxGLConfigVersion.cmake"
DESTINATION ${CMAKECONFIG_INSTALL_DIR}
COMPONENT development)
"${CMAKE_CURRENT_BINARY_DIR}/QMapLibreGLConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/QMapLibreGLConfigVersion.cmake"
DESTINATION ${CMAKECONFIG_INSTALL_DIR}
COMPONENT development)
install(
DIRECTORY include/mbgl
@@ -246,43 +247,54 @@ install(
# FIXME: Because of rapidjson conversion
target_include_directories(
qmapboxgl
qmaplibregl
PRIVATE
${PROJECT_SOURCE_DIR}/src
${PROJECT_SOURCE_DIR}/platform/qt/include
INTERFACE
"$<INSTALL_INTERFACE:include>"
${PROJECT_SOURCE_DIR}/src
${PROJECT_SOURCE_DIR}/platform/qt/include
)
target_compile_definitions(
qmapboxgl
qmaplibregl
PRIVATE
QT_BUILD_MAPBOXGL_LIB
QT_BUILD_MAPLIBREGL_LIB
)
target_link_libraries(
qmapboxgl
qmaplibregl
PUBLIC
Qt${QT_VERSION_MAJOR}::Core
Qt${QT_VERSION_MAJOR}::Gui
Qt${QT_VERSION_MAJOR}::Network
PRIVATE
"$<BUILD_INTERFACE:mbgl-compiler-options>"
"$<BUILD_INTERFACE:mbgl-core>"
"$<BUILD_INTERFACE:mbgl-vendor-parsedate>"
"$<BUILD_INTERFACE:mbgl-vendor-nunicode>"
"$<BUILD_INTERFACE:mbgl-vendor-csscolorparser>"
$<BUILD_INTERFACE:mbgl-compiler-options>
$<BUILD_INTERFACE:mbgl-core>
$<BUILD_INTERFACE:mbgl-vendor-parsedate>
$<BUILD_INTERFACE:mbgl-vendor-nunicode>
$<BUILD_INTERFACE:mbgl-vendor-csscolorparser>
)
# Do not use generator expressions for cleaner output
if (MBGL_QT_STATIC AND NOT MBGL_QT_INSIDE_PLUGIN)
target_link_libraries(
qmaplibregl
PUBLIC
$<$<NOT:$<BOOL:${MBGL_QT_WITH_INTERNAL_SQLITE}>>:Qt${QT_VERSION_MAJOR}::Sql>
$<$<NOT:$<OR:$<PLATFORM_ID:Windows>,$<PLATFORM_ID:Emscripten>>>:z>
)
target_compile_definitions(
qmaplibregl
PUBLIC QT_MAPLIBREGL_STATIC
)
endif()
install(TARGETS qmapboxgl
EXPORT QMapboxGLTargets
install(TARGETS qmaplibregl
EXPORT QMapLibreGLTargets
# Explicit set of DESTINATION is needed for older CMake versions.
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
FRAMEWORK DESTINATION "${CMAKE_INSTALL_LIBDIR}"
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/QMapLibreGL"
)
if(NOT MBGL_QT_LIBRARY_ONLY)
@@ -302,12 +314,6 @@ if(NOT MBGL_QT_LIBRARY_ONLY)
set_property(TARGET mbgl-qt PROPERTY CXX_STANDARD 98)
set_property(TARGET mbgl-qt PROPERTY AUTOMOC ON)
target_compile_definitions(
mbgl-qt
PRIVATE
$<$<OR:$<BOOL:${MBGL_QT_STATIC}>,$<BOOL:${MBGL_QT_INSIDE_PLUGIN}>>:QT_MAPBOXGL_STATIC>
)
target_link_libraries(
mbgl-qt
PRIVATE
@@ -315,7 +321,7 @@ if(NOT MBGL_QT_LIBRARY_ONLY)
Qt${QT_VERSION_MAJOR}::Gui
$<$<BOOL:${Qt6_FOUND}>:Qt${QT_VERSION_MAJOR}::OpenGLWidgets>
mbgl-compiler-options
qmapboxgl
qmaplibregl
)
target_include_directories(
@@ -341,9 +347,7 @@ if(NOT MBGL_QT_LIBRARY_ONLY)
target_link_libraries(
mbgl-test-runner
PRIVATE
Qt${QT_VERSION_MAJOR}::Widgets
Qt${QT_VERSION_MAJOR}::Gui
Qt${QT_VERSION_MAJOR}::OpenGL
mbgl-compiler-options
$<$<NOT:$<BOOL:MSVC>>:pthread>
)

File diff suppressed because it is too large Load Diff

View File

@@ -1,8 +1,9 @@
#pragma once
#include "qmapboxgl.hpp"
#include "qmapboxgl_map_observer.hpp"
#include "qmapboxgl_map_renderer.hpp"
#include <QMapLibreGL/Map>
#include "utils/map_observer.hpp"
#include "utils/map_renderer.hpp"
#include <mbgl/actor/actor.hpp>
#include <mbgl/map/map.hpp>
@@ -16,13 +17,15 @@
#include <atomic>
#include <memory>
class QMapboxGLPrivate : public QObject, public mbgl::RendererFrontend
namespace QMapLibreGL {
class MapPrivate : public QObject, public mbgl::RendererFrontend
{
Q_OBJECT
public:
explicit QMapboxGLPrivate(QMapboxGL *, const QMapboxGLSettings &, const QSize &size, qreal pixelRatio);
virtual ~QMapboxGLPrivate();
explicit MapPrivate(Map *, const Settings &, const QSize &size, qreal pixelRatio);
virtual ~MapPrivate();
// mbgl::RendererFrontend implementation.
void reset() final {}
@@ -39,7 +42,7 @@ public:
bool setProperty(const PropertySetter& setter, const QString& layer, const QString& name, const QVariant& value);
mbgl::EdgeInsets margins;
std::unique_ptr<mbgl::Map> mapObj;
std::unique_ptr<mbgl::Map> mapObj{};
QVector<QPair<QString, QString>> defaultStyles;
public slots:
@@ -49,20 +52,22 @@ signals:
void needsRendering();
private:
Q_DISABLE_COPY(QMapboxGLPrivate)
Q_DISABLE_COPY(MapPrivate)
std::recursive_mutex m_mapRendererMutex;
std::shared_ptr<mbgl::RendererObserver> m_rendererObserver;
std::shared_ptr<mbgl::UpdateParameters> m_updateParameters;
std::shared_ptr<mbgl::RendererObserver> m_rendererObserver{};
std::shared_ptr<mbgl::UpdateParameters> m_updateParameters{};
std::unique_ptr<QMapboxGLMapObserver> m_mapObserver;
std::unique_ptr<QMapboxGLMapRenderer> m_mapRenderer;
std::unique_ptr<mbgl::Actor<mbgl::ResourceTransform::TransformCallback>> m_resourceTransform;
std::unique_ptr<MapObserver> m_mapObserver{};
std::unique_ptr<MapRenderer> m_mapRenderer{};
std::unique_ptr<mbgl::Actor<mbgl::ResourceTransform::TransformCallback>> m_resourceTransform{};
QMapboxGLSettings::GLContextMode m_mode;
Settings::GLContextMode m_mode;
qreal m_pixelRatio;
QString m_localFontFamily;
std::atomic_flag m_renderQueued = ATOMIC_FLAG_INIT;
};
} // namespace QMapLibreGL

View File

@@ -39,7 +39,7 @@ QNetworkRequest HTTPRequest::networkRequest() const
QNetworkRequest req = QNetworkRequest(requestUrl());
req.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache);
static const QByteArray agent = QString("MapboxGL/%1 (Qt %2)").arg(version::revision).arg(QT_VERSION_STR).toLatin1();
static const QByteArray agent = QString("MapLibreGL/%1 (Qt %2)").arg(version::revision).arg(QT_VERSION_STR).toLatin1();
req.setRawHeader("User-Agent", agent);
if (m_resource.priorEtag) {

View File

@@ -1,231 +0,0 @@
#include "qmapbox.hpp"
#include <mbgl/storage/network_status.hpp>
#include <mbgl/util/geometry.hpp>
#include <mbgl/util/traits.hpp>
#include <mbgl/util/projection.hpp>
#include <QOpenGLContext>
// 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 QVector<QMapbox::Coordinate>.
A list of QMapbox::Coordinate objects.
*/
/*!
\typedef QMapbox::CoordinatesCollection
Alias for QVector<QMapbox::Coordinates>.
A list of QMapbox::Coordinates objects.
*/
/*!
\typedef QMapbox::CoordinatesCollections
Alias for QVector<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 QVector<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));
}
/*!
Returns the amount of meters per pixel from a given \a latitude and \a zoom.
*/
double metersPerPixelAtLatitude(double latitude, double zoom)
{
return mbgl::Projection::getMetersPerPixelAtLatitude(latitude, zoom);
}
/*!
Return the projected meters for a given \a coordinate object.
*/
ProjectedMeters projectedMetersForCoordinate(const Coordinate &coordinate)
{
auto projectedMeters = mbgl::Projection::projectedMetersForLatLng(mbgl::LatLng { coordinate.first, coordinate.second });
return QMapbox::ProjectedMeters(projectedMeters.northing(), projectedMeters.easting());
}
/*!
Returns the coordinate for a given \a projectedMeters object.
*/
Coordinate coordinateForProjectedMeters(const ProjectedMeters &projectedMeters)
{
auto latLng = mbgl::Projection::latLngForProjectedMeters(mbgl::ProjectedMeters { projectedMeters.first, projectedMeters.second });
return QMapbox::Coordinate(latLng.latitude(), latLng.longitude());
}
} // namespace QMapbox

View File

@@ -1,118 +0,0 @@
#include "qmapboxgl_map_observer.hpp"
#include "qmapboxgl_p.hpp"
#include <mbgl/util/exception.hpp>
#include <exception>
QMapboxGLMapObserver::QMapboxGLMapObserver(QMapboxGLPrivate *d)
: d_ptr(d)
{
}
QMapboxGLMapObserver::~QMapboxGLMapObserver()
{
}
void QMapboxGLMapObserver::onCameraWillChange(mbgl::MapObserver::CameraChangeMode mode)
{
if (mode == mbgl::MapObserver::CameraChangeMode::Immediate) {
emit mapChanged(QMapboxGL::MapChangeRegionWillChange);
} else {
emit mapChanged(QMapboxGL::MapChangeRegionWillChangeAnimated);
}
}
void QMapboxGLMapObserver::onCameraIsChanging()
{
emit mapChanged(QMapboxGL::MapChangeRegionIsChanging);
}
void QMapboxGLMapObserver::onCameraDidChange(mbgl::MapObserver::CameraChangeMode mode)
{
if (mode == mbgl::MapObserver::CameraChangeMode::Immediate) {
emit mapChanged(QMapboxGL::MapChangeRegionDidChange);
} else {
emit mapChanged(QMapboxGL::MapChangeRegionDidChangeAnimated);
}
}
void QMapboxGLMapObserver::onWillStartLoadingMap()
{
emit mapChanged(QMapboxGL::MapChangeWillStartLoadingMap);
}
void QMapboxGLMapObserver::onDidFinishLoadingMap()
{
emit mapChanged(QMapboxGL::MapChangeDidFinishLoadingMap);
}
void QMapboxGLMapObserver::onDidFailLoadingMap(mbgl::MapLoadError error, const std::string& what)
{
emit mapChanged(QMapboxGL::MapChangeDidFailLoadingMap);
QMapboxGL::MapLoadingFailure type;
QString description(what.c_str());
switch (error) {
case mbgl::MapLoadError::StyleParseError:
type = QMapboxGL::MapLoadingFailure::StyleParseFailure;
break;
case mbgl::MapLoadError::StyleLoadError:
type = QMapboxGL::MapLoadingFailure::StyleLoadFailure;
break;
case mbgl::MapLoadError::NotFoundError:
type = QMapboxGL::MapLoadingFailure::NotFoundFailure;
break;
default:
type = QMapboxGL::MapLoadingFailure::UnknownFailure;
}
emit mapLoadingFailed(type, description);
}
void QMapboxGLMapObserver::onWillStartRenderingFrame()
{
emit mapChanged(QMapboxGL::MapChangeWillStartRenderingFrame);
}
void QMapboxGLMapObserver::onDidFinishRenderingFrame(mbgl::MapObserver::RenderFrameStatus status)
{
if (status.mode == mbgl::MapObserver::RenderMode::Partial) {
emit mapChanged(QMapboxGL::MapChangeDidFinishRenderingFrame);
} else {
emit mapChanged(QMapboxGL::MapChangeDidFinishRenderingFrameFullyRendered);
}
}
void QMapboxGLMapObserver::onWillStartRenderingMap()
{
emit mapChanged(QMapboxGL::MapChangeWillStartRenderingMap);
}
void QMapboxGLMapObserver::onDidFinishRenderingMap(mbgl::MapObserver::RenderMode mode)
{
if (mode == mbgl::MapObserver::RenderMode::Partial) {
emit mapChanged(QMapboxGL::MapChangeDidFinishRenderingMap);
} else {
emit mapChanged(QMapboxGL::MapChangeDidFinishRenderingMapFullyRendered);
}
}
void QMapboxGLMapObserver::onDidFinishLoadingStyle()
{
emit mapChanged(QMapboxGL::MapChangeDidFinishLoadingStyle);
}
void QMapboxGLMapObserver::onSourceChanged(mbgl::style::Source&)
{
std::string attribution;
for (const auto& source : d_ptr->mapObj->getStyle().getSources()) {
// Avoid duplicates by using the most complete attribution HTML snippet.
if (source->getAttribution() && (attribution.size() < source->getAttribution()->size()))
attribution = *source->getAttribution();
}
emit copyrightsChanged(QString::fromStdString(attribution));
emit mapChanged(QMapboxGL::MapChangeSourceDidChange);
}

View File

@@ -1,52 +0,0 @@
#include "qmapboxgl_renderer_backend.hpp"
#include <mbgl/gfx/backend_scope.hpp>
#include <mbgl/gl/renderable_resource.hpp>
#include <QOpenGLContext>
#include <QtGlobal>
class QMapboxGLRenderableResource final : public mbgl::gl::RenderableResource {
public:
QMapboxGLRenderableResource(QMapboxGLRendererBackend& backend_) : backend(backend_) {
}
void bind() override {
assert(mbgl::gfx::BackendScope::exists());
backend.restoreFramebufferBinding();
backend.setViewport(0, 0, backend.getSize());
}
private:
QMapboxGLRendererBackend& backend;
};
QMapboxGLRendererBackend::QMapboxGLRendererBackend(const mbgl::gfx::ContextMode contextMode_)
: mbgl::gl::RendererBackend(contextMode_),
mbgl::gfx::Renderable({ 0, 0 }, std::make_unique<QMapboxGLRenderableResource>(*this)) {
}
QMapboxGLRendererBackend::~QMapboxGLRendererBackend() = default;
void QMapboxGLRendererBackend::updateAssumedState() {
assumeFramebufferBinding(ImplicitFramebufferBinding);
assumeViewport(0, 0, size);
}
void QMapboxGLRendererBackend::restoreFramebufferBinding() {
setFramebufferBinding(m_fbo);
}
void QMapboxGLRendererBackend::updateFramebuffer(quint32 fbo, const mbgl::Size& newSize) {
m_fbo = fbo;
size = newSize;
}
/*!
Initializes an OpenGL extension function such as Vertex Array Objects (VAOs),
required by Mapbox GL Native engine.
*/
mbgl::gl::ProcAddress QMapboxGLRendererBackend::getExtensionFunctionPointer(const char* name) {
QOpenGLContext* thisContext = QOpenGLContext::currentContext();
return thisContext->getProcAddress(name);
}

View File

@@ -1,27 +0,0 @@
#pragma once
#include <mapbox/geojson.hpp>
#include <mbgl/util/geometry.hpp>
#include <mbgl/util/feature.hpp>
#include <QMapbox>
#include <QByteArray>
#include <QDebug>
#include <QVariant>
#include <string>
namespace QMapbox {
mbgl::Point<double> asMapboxGLPoint(const QMapbox::Coordinate &coordinate);
mbgl::MultiPoint<double> asMapboxGLMultiPoint(const QMapbox::Coordinates &multiPoint);
mbgl::LineString<double> asMapboxGLLineString(const QMapbox::Coordinates &lineString);
mbgl::MultiLineString<double> asMapboxGLMultiLineString(const QMapbox::CoordinatesCollection &multiLineString);
mbgl::Polygon<double> asMapboxGLPolygon(const QMapbox::CoordinatesCollection &polygon);
mbgl::MultiPolygon<double> asMapboxGLMultiPolygon(const QMapbox::CoordinatesCollections &multiPolygon);
mbgl::Value asMapboxGLPropertyValue(const QVariant &value);
mbgl::FeatureIdentifier asMapboxGLFeatureIdentifier(const QVariant &id);
mbgl::GeoJSONFeature asMapboxGLFeature(const QMapbox::Feature &feature);
} // namespace QMapbox

View File

@@ -0,0 +1,411 @@
#include <QMapLibreGL/Settings>
#include <mbgl/gfx/renderer_backend.hpp>
#include <mbgl/map/mode.hpp>
#include <mbgl/util/constants.hpp>
#include <mbgl/util/tile_server_options.hpp>
#include <mbgl/util/traits.hpp>
#include <QCoreApplication>
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable: 4805)
#endif
// mbgl::GLContextMode
static_assert(mbgl::underlying_type(QMapLibreGL::Settings::UniqueGLContext) == mbgl::underlying_type(mbgl::gfx::ContextMode::Unique), "error");
static_assert(mbgl::underlying_type(QMapLibreGL::Settings::SharedGLContext) == mbgl::underlying_type(mbgl::gfx::ContextMode::Shared), "error");
// mbgl::MapMode
static_assert(mbgl::underlying_type(QMapLibreGL::Settings::Continuous) == mbgl::underlying_type(mbgl::MapMode::Continuous), "error");
static_assert(mbgl::underlying_type(QMapLibreGL::Settings::Static) == mbgl::underlying_type(mbgl::MapMode::Static), "error");
// mbgl::ConstrainMode
static_assert(mbgl::underlying_type(QMapLibreGL::Settings::NoConstrain) == mbgl::underlying_type(mbgl::ConstrainMode::None), "error");
static_assert(mbgl::underlying_type(QMapLibreGL::Settings::ConstrainHeightOnly) == mbgl::underlying_type(mbgl::ConstrainMode::HeightOnly), "error");
static_assert(mbgl::underlying_type(QMapLibreGL::Settings::ConstrainWidthAndHeight) == mbgl::underlying_type(mbgl::ConstrainMode::WidthAndHeight), "error");
// mbgl::ViewportMode
static_assert(mbgl::underlying_type(QMapLibreGL::Settings::DefaultViewport) == mbgl::underlying_type(mbgl::ViewportMode::Default), "error");
static_assert(mbgl::underlying_type(QMapLibreGL::Settings::FlippedYViewport) == mbgl::underlying_type(mbgl::ViewportMode::FlippedY), "error");
#ifdef _MSC_VER
#pragma warning(pop)
#endif
namespace QMapLibreGL {
/*!
\class QMapLibreGL::Settings
\brief The Settings class stores the initial configuration for QMapLibreGL::Map.
\inmodule MapLibre Maps SDK for Qt
Settings is used to configure QMapLibreGL::Map at the moment of its creation.
Once created, the Settings of a QMapLibreGL::Map can no longer be changed.
Cache-related settings are shared between all QMapLibreGL::Map instances using the same cache path.
The first map to configure cache properties such as size will force the configuration
to all newly instantiated QMapLibreGL::Map objects using the same cache in the same process.
*/
/*!
\enum QMapLibreGL::Settings::GLContextMode
This enum sets the expectations for the OpenGL state.
\value UniqueGLContext The OpenGL context is only used by QMapLibreGL::Map, so it is not
reset before each rendering. Use this mode if the intention is to only draw a
fullscreen map.
\value SharedGLContext The OpenGL context is shared and the state will be
marked dirty - which invalidates any previously assumed GL state. The
embedder is responsible for clearing up the viewport prior to calling
QMapLibreGL::Map::render. The embedder is also responsible for resetting its own
GL state after QMapLibreGL::Map::render has finished, if needed.
\sa contextMode()
*/
/*!
\enum QMapLibreGL::Settings::MapMode
This enum sets the map rendering mode
\value Continuous The map will render as data arrives from the network and
react immediately to state changes.
This is the default mode and the preferred when the map is intended to be
interactive.
\value Static The map will no longer react to state changes and will only
be rendered when QMapLibreGL::Map::startStaticRender is called. After all the
resources are loaded, the QMapLibreGL::Map::staticRenderFinished signal is emitted.
This mode is useful for taking a snapshot of the finished rendering result
of the map into a QImage.
\sa mapMode()
*/
/*!
\enum QMapLibreGL::Settings::ConstrainMode
This enum determines if the map wraps.
\value NoConstrain The map will wrap on the horizontal axis. Since it doesn't
make sense to wrap on the vertical axis in a Web Mercator projection, the map will scroll
and show some empty space.
\value ConstrainHeightOnly The map will wrap around the horizontal axis, like a spinning
globe. This is the recommended constrain mode.
\value ConstrainWidthAndHeight The map won't wrap and panning is restricted to the boundaries
of the map.
\sa constrainMode()
*/
/*!
\enum QMapLibreGL::Settings::ViewportMode
This enum flips the map vertically.
\value DefaultViewport Native orientation.
\value FlippedYViewport Mirrored vertically.
\sa viewportMode()
*/
/*!
Constructs a Settings object with the default values. The default
configuration is valid for initializing a QMapLibreGL::Map.
*/
Settings::Settings()
: m_contextMode(Settings::SharedGLContext)
, m_mapMode(Settings::Continuous)
, m_constrainMode(Settings::ConstrainHeightOnly)
, m_viewportMode(Settings::DefaultViewport)
, m_cacheMaximumSize(mbgl::util::DEFAULT_MAX_CACHE_SIZE)
, m_cacheDatabasePath(":memory:")
, m_assetPath(QCoreApplication::applicationDirPath())
, m_apiKey(qgetenv("MGL_API_KEY"))
, m_tileServerOptionsInternal(new mbgl::TileServerOptions(mbgl::TileServerOptions::DefaultConfiguration()))
{
}
/*!
Returns the OpenGL context mode. This is specially important when mixing
with other OpenGL draw calls.
By default, it is set to Settings::SharedGLContext.
*/
Settings::GLContextMode Settings::contextMode() const
{
return m_contextMode;
}
/*!
Sets the OpenGL context \a mode.
*/
void Settings::setContextMode(GLContextMode mode)
{
m_contextMode = mode;
}
/*!
Returns the map mode. Static mode will emit a signal for
rendering a map only when the map is fully loaded.
Animations like style transitions and labels fading won't
be seen.
The Continuous mode will emit the signal for every new
change on the map and it is usually what you expect for
a interactive map.
By default, it is set to QMapLibreGL::Settings::Continuous.
*/
Settings::MapMode Settings::mapMode() const
{
return m_mapMode;
}
/*!
Sets the map \a mode.
*/
void Settings::setMapMode(MapMode mode)
{
m_mapMode = mode;
}
/*!
Returns the constrain mode. This is used to limit the map to wrap
around the globe horizontally.
By default, it is set to QMapLibreGL::Settings::ConstrainHeightOnly.
*/
Settings::ConstrainMode Settings::constrainMode() const
{
return m_constrainMode;
}
/*!
Sets the map constrain \a mode.
*/
void Settings::setConstrainMode(ConstrainMode mode)
{
m_constrainMode = mode;
}
/*!
Returns the viewport mode. This is used to flip the vertical
orientation of the map as some devices may use inverted orientation.
By default, it is set to QMapLibreGL::Settings::DefaultViewport.
*/
Settings::ViewportMode Settings::viewportMode() const
{
return m_viewportMode;
}
/*!
Sets the viewport \a mode.
*/
void Settings::setViewportMode(ViewportMode mode)
{
m_viewportMode = mode;
}
/*!
Returns the cache database maximum hard size in bytes. The database
will grow until the limit is reached. Setting a maximum size smaller
than the current size of an existing database results in undefined
behavior
By default, it is set to 50 MB.
*/
unsigned Settings::cacheDatabaseMaximumSize() const
{
return m_cacheMaximumSize;
}
/*!
Returns the maximum allowed cache database \a size in bytes.
*/
void Settings::setCacheDatabaseMaximumSize(unsigned size)
{
m_cacheMaximumSize = size;
}
/*!
Returns the cache database path. The cache is used for storing
recently used resources like tiles and also an offline tile database
pre-populated by the
\l {https://github.com/mapbox/mapbox-gl-native/blob/master/bin/offline.sh}
{Offline Tool}.
By default, it is set to \c :memory: meaning it will create an in-memory
cache instead of a file on disk.
*/
QString Settings::cacheDatabasePath() const
{
return m_cacheDatabasePath;
}
/*!
Sets the cache database \a path.
Setting the \a path to \c :memory: will create an in-memory cache.
*/
void Settings::setCacheDatabasePath(const QString &path)
{
m_cacheDatabasePath = path;
}
/*!
Returns the asset path, which is the root directory from where
the \c asset:// scheme gets resolved in a style. \c asset:// can be used
for loading a resource from the disk in a style rather than fetching
it from the network.
By default, it is set to the value returned by QCoreApplication::applicationDirPath().
*/
QString Settings::assetPath() const
{
return m_assetPath;
}
/*!
Sets the asset \a path.
*/
void Settings::setAssetPath(const QString &path)
{
m_assetPath = path;
}
/*!
Returns the API key.
By default, it is taken from the environment variable \c MGL_API_KEY
or empty if the variable is not set.
*/
QString Settings::apiKey() const {
return m_apiKey;
}
/*!
Sets the API key.
MapTiler-hosted and Mapbox-hosted vector tiles and styles require an API
key or access token.
*/
void Settings::setApiKey(const QString &key)
{
m_apiKey = key;
}
/*!
Returns the API base URL.
*/
QString Settings::apiBaseUrl() const
{
return QString::fromStdString(m_tileServerOptionsInternal->baseURL());
}
/*!
Sets the API base \a url.
The API base URL is the URL that the \b "mapbox://" protocol will
be resolved to. It defaults to "https://api.mapbox.com" but can be
changed, for instance, to a tile cache server address.
*/
void Settings::setApiBaseUrl(const QString& url)
{
m_tileServerOptionsInternal = &m_tileServerOptionsInternal->withBaseURL(url.toStdString());
}
/*!
Returns the local font family. Returns an empty string if no local font family is set.
*/
QString Settings::localFontFamily() const
{
return m_localFontFamily;
}
/*!
Sets the local font family.
Rendering Chinese/Japanese/Korean (CJK) ideographs and precomposed Hangul Syllables requires
downloading large amounts of font data, which can significantly slow map load times. Use the
localIdeographFontFamily setting to speed up map load times by using locally available fonts
instead of font data fetched from the server.
*/
void Settings::setLocalFontFamily(const QString &family)
{
m_localFontFamily = family;
}
/*!
Returns resource transformation callback used to transform requested URLs.
*/
std::function<std::string(const std::string &)> Settings::resourceTransform() const {
return m_resourceTransform;
}
/*!
Sets the resource \a transform callback.
When given, resource transformation callback will be used to transform the
requested resource URLs before they are requested from internet. This can be
used add or remove custom parameters, or reroute certain requests to other
servers or endpoints.
*/
void Settings::setResourceTransform(const std::function<std::string(const std::string &)> &transform) {
m_resourceTransform = transform;
}
/*!
Reset all settings based on the given template.
MapLibre can support servers with different resource path structure.
Some of the most common servers like Maptiler and Mapbox are defined
in the library. This function will re-initialise all settings based
on the default values of specific service provider defaults.
*/
void Settings::resetToTemplate(SettingsTemplate settings_template)
{
if(m_tileServerOptionsInternal) delete m_tileServerOptionsInternal;
if(settings_template == MapLibreSettings){
m_tileServerOptionsInternal = new mbgl::TileServerOptions(mbgl::TileServerOptions::MapLibreConfiguration());
}else if(settings_template == MapTilerSettings){
m_tileServerOptionsInternal = new mbgl::TileServerOptions(mbgl::TileServerOptions::MapTilerConfiguration());
}else if(settings_template == MapboxSettings){
m_tileServerOptionsInternal = new mbgl::TileServerOptions(mbgl::TileServerOptions::MapboxConfiguration());
}else{
m_tileServerOptionsInternal = new mbgl::TileServerOptions(mbgl::TileServerOptions::DefaultConfiguration());
}
}
/*!
All predefined styles.
Return all styles that are defined in default settings.
*/
QVector<QPair<QString, QString> > Settings::defaultStyles() const {
QVector<QPair<QString, QString>> styles;
for (const auto &style : tileServerOptionsInternal()->defaultStyles()) {
styles.append(QPair<QString, QString>(
QString::fromStdString(style.getUrl()), QString::fromStdString(style.getName())));
}
return styles;
}
mbgl::TileServerOptions *Settings::tileServerOptionsInternal() const {
return m_tileServerOptionsInternal;
}
} // namespace QMapLibreGL

172
platform/qt/src/types.cpp Normal file
View File

@@ -0,0 +1,172 @@
#include <QMapLibreGL/Types>
#include "mbgl/util/geometry.hpp"
#include "mbgl/util/traits.hpp"
// mbgl::FeatureType
static_assert(mbgl::underlying_type(QMapLibreGL::Feature::PointType) == mbgl::underlying_type(mbgl::FeatureType::Point), "error");
static_assert(mbgl::underlying_type(QMapLibreGL::Feature::LineStringType) == mbgl::underlying_type(mbgl::FeatureType::LineString), "error");
static_assert(mbgl::underlying_type(QMapLibreGL::Feature::PolygonType) == mbgl::underlying_type(mbgl::FeatureType::Polygon), "error");
namespace QMapLibreGL {
/*!
\namespace QMapLibreGL
\inmodule MapLibre Maps SDK for Qt
Contains miscellaneous MapLibre types and utilities used throughout QMapLibreGLGL.
*/
/*!
\typedef QMapLibreGL::Coordinate
Alias for QPair<double, double>.
Representation for geographical coordinates - latitude and longitude, respectively.
*/
/*!
\typedef QMapLibreGL::CoordinateZoom
Alias for QPair<Coordinate, double>.
Used as return value in QMapLibreGLGL::coordinateZoomForBounds.
*/
/*!
\typedef QMapLibreGL::ProjectedMeters
Alias for QPair<double, double>.
Representation for projected meters - northing and easting, respectively.
*/
/*!
\typedef QMapLibreGL::Coordinates
Alias for QVector<QMapLibreGL::Coordinate>.
A list of QMapLibreGL::Coordinate objects.
*/
/*!
\typedef QMapLibreGL::CoordinatesCollection
Alias for QVector<QMapLibreGL::Coordinates>.
A list of QMapLibreGL::Coordinates objects.
*/
/*!
\typedef QMapLibreGL::CoordinatesCollections
Alias for QVector<QMapLibreGL::CoordinatesCollection>.
A list of QMapLibreGL::CoordinatesCollection objects.
*/
/*!
\class QMapLibreGL::Feature
\inmodule MapLibre 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 QMapLibreGL::Feature::Type
This enum is used as basis for geometry disambiguation in QMapLibreGL::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 QMapLibreGL::ShapeAnnotationGeometry
\inmodule MapLibre Maps SDK for Qt
Represents a shape annotation geometry.
*/
/*!
\enum QMapLibreGL::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 QMapLibreGL::SymbolAnnotation
\inmodule MapLibre Maps SDK for Qt
A symbol annotation comprises of its geometry and an icon identifier.
*/
/*!
\class QMapLibreGL::LineAnnotation
\inmodule MapLibre 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 QMapLibreGL::FillAnnotation
\inmodule MapLibre 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 QMapLibreGL::Annotation
Alias for QVariant.
Container that encapsulates either a symbol, a line, a fill or a style sourced annotation.
*/
/*!
\typedef QMapLibreGL::AnnotationID
Alias for quint32 representing an annotation identifier.
*/
/*!
\typedef QMapLibreGL::AnnotationIDs
Alias for QVector<quint32> representing a container of annotation identifiers.
*/
/*!
\class QMapLibreGL::CameraOptions
\inmodule MapLibre Maps SDK for Qt
QMapLibreGL::CameraOptions provides camera options to the renderer.
*/
/*!
\class QMapLibreGL::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.
*/
/*!
\class QMapLibreGL::CustomLayerRenderParameters
\inmodule MapLibre Maps SDK for Qt
QMapLibreGL::CustomLayerRenderParameters provides the data passed on each render
pass for a custom layer.
*/
} // namespace QMapLibreGL

74
platform/qt/src/utils.cpp Normal file
View File

@@ -0,0 +1,74 @@
#include <QMapLibreGL/Utils>
#include <mbgl/storage/network_status.hpp>
#include <mbgl/util/geometry.hpp>
#include <mbgl/util/traits.hpp>
#include <mbgl/util/projection.hpp>
#include <QOpenGLContext>
// mbgl::NetworkStatus::Status
static_assert(mbgl::underlying_type(QMapLibreGL::Online) == mbgl::underlying_type(mbgl::NetworkStatus::Status::Online), "error");
static_assert(mbgl::underlying_type(QMapLibreGL::Offline) == mbgl::underlying_type(mbgl::NetworkStatus::Status::Offline), "error");
namespace QMapLibreGL {
/*!
\enum QMapLibreGL::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.
*/
/*!
\fn QMapLibreGL::NetworkMode QMapLibreGL::networkMode()
Returns the current QMapLibreGL::NetworkMode.
*/
NetworkMode networkMode()
{
return static_cast<NetworkMode>(mbgl::NetworkStatus::Get());
}
/*!
\fn void QMapLibreGL::setNetworkMode(QMapLibreGL::NetworkMode mode)
Forwards the network status \a mode to MapLibre 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));
}
/*!
Returns the amount of meters per pixel from a given \a latitude and \a zoom.
*/
double metersPerPixelAtLatitude(double latitude, double zoom)
{
return mbgl::Projection::getMetersPerPixelAtLatitude(latitude, zoom);
}
/*!
Return the projected meters for a given \a coordinate object.
*/
ProjectedMeters projectedMetersForCoordinate(const Coordinate &coordinate)
{
auto projectedMeters = mbgl::Projection::projectedMetersForLatLng(mbgl::LatLng { coordinate.first, coordinate.second });
return ProjectedMeters(projectedMeters.northing(), projectedMeters.easting());
}
/*!
Returns the coordinate for a given \a projectedMeters object.
*/
Coordinate coordinateForProjectedMeters(const ProjectedMeters &projectedMeters)
{
auto latLng = mbgl::Projection::latLngForProjectedMeters(mbgl::ProjectedMeters { projectedMeters.first, projectedMeters.second });
return Coordinate(latLng.latitude(), latLng.longitude());
}
} // namespace QMapLibreGL

View File

@@ -1,13 +1,15 @@
#pragma once
#include <QMapLibreGL/Types>
#include "geojson.hpp"
#include <mbgl/style/conversion/geojson.hpp>
#include <mbgl/style/conversion_impl.hpp>
#include <mbgl/util/optional.hpp>
#include <QVariant>
#include <QColor>
#include <QMapbox>
#include "qt_geojson.hpp"
#include <QVariant>
namespace mbgl {
namespace style {
@@ -46,9 +48,9 @@ public:
return value.canConvert(QVariant::Map)
|| value.type() == QVariant::ByteArray
#endif
|| QString(value.typeName()) == QStringLiteral("QMapbox::Feature")
|| value.userType() == qMetaTypeId<QVector<QMapbox::Feature>>()
|| value.userType() == qMetaTypeId<QList<QMapbox::Feature>>();
|| QString(value.typeName()) == QStringLiteral("QMapLibreGL::Feature")
|| value.userType() == qMetaTypeId<QVector<QMapLibreGL::Feature>>()
|| value.userType() == qMetaTypeId<QList<QMapLibreGL::Feature>>();
}
static optional<QVariant> objectMember(const QVariant& value, const char* key) {
@@ -168,12 +170,12 @@ public:
}
static optional<GeoJSON> toGeoJSON(const QVariant& value, Error& error) {
if (value.typeName() == QStringLiteral("QMapbox::Feature")) {
return GeoJSON { asMapboxGLFeature(value.value<QMapbox::Feature>()) };
} else if (value.userType() == qMetaTypeId<QVector<QMapbox::Feature>>()) {
return featureCollectionToGeoJSON(value.value<QVector<QMapbox::Feature>>());
} else if (value.userType() == qMetaTypeId<QList<QMapbox::Feature>>()) {
return featureCollectionToGeoJSON(value.value<QList<QMapbox::Feature>>());
if (value.typeName() == QStringLiteral("QMapLibreGL::Feature")) {
return GeoJSON { QMapLibreGL::GeoJSON::asFeature(value.value<QMapLibreGL::Feature>()) };
} else if (value.userType() == qMetaTypeId<QVector<QMapLibreGL::Feature>>()) {
return featureCollectionToGeoJSON(value.value<QVector<QMapLibreGL::Feature>>());
} else if (value.userType() == qMetaTypeId<QList<QMapLibreGL::Feature>>()) {
return featureCollectionToGeoJSON(value.value<QList<QMapLibreGL::Feature>>());
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
} else if (value.typeId() != QMetaType::QByteArray) {
#else
@@ -193,7 +195,7 @@ private:
mapbox::feature::feature_collection<double> collection;
collection.reserve(static_cast<std::size_t>(features.size()));
for (const auto &feature : features) {
collection.push_back(asMapboxGLFeature(feature));
collection.push_back(QMapLibreGL::GeoJSON::asFeature(feature));
}
return GeoJSON { std::move(collection) };
}

View File

@@ -1,69 +1,69 @@
#include "qt_geojson.hpp"
#include "geojson.hpp"
#pragma clang diagnostic ignored "-Wenum-compare-switch"
#include <QDebug>
namespace QMapbox {
namespace QMapLibreGL::GeoJSON {
mbgl::Point<double> asMapboxGLPoint(const QMapbox::Coordinate &coordinate) {
mbgl::Point<double> asPoint(const Coordinate &coordinate) {
return mbgl::Point<double> { coordinate.second, coordinate.first };
}
mbgl::MultiPoint<double> asMapboxGLMultiPoint(const QMapbox::Coordinates &multiPoint) {
mbgl::MultiPoint<double> asMultiPoint(const Coordinates &multiPoint) {
mbgl::MultiPoint<double> mbglMultiPoint;
mbglMultiPoint.reserve(multiPoint.size());
for (const auto &point: multiPoint) {
mbglMultiPoint.emplace_back(asMapboxGLPoint(point));
mbglMultiPoint.emplace_back(asPoint(point));
}
return mbglMultiPoint;
};
mbgl::LineString<double> asMapboxGLLineString(const QMapbox::Coordinates &lineString) {
mbgl::LineString<double> asLineString(const Coordinates &lineString) {
mbgl::LineString<double> mbglLineString;
mbglLineString.reserve(lineString.size());
for (const auto &coordinate : lineString) {
mbglLineString.emplace_back(asMapboxGLPoint(coordinate));
mbglLineString.emplace_back(asPoint(coordinate));
}
return mbglLineString;
};
mbgl::MultiLineString<double> asMapboxGLMultiLineString(const QMapbox::CoordinatesCollection &multiLineString) {
mbgl::MultiLineString<double> asMultiLineString(const CoordinatesCollection &multiLineString) {
mbgl::MultiLineString<double> mbglMultiLineString;
mbglMultiLineString.reserve(multiLineString.size());
for (const auto &lineString : multiLineString) {
mbglMultiLineString.emplace_back(std::forward<mbgl::LineString<double>>(asMapboxGLLineString(lineString)));
mbglMultiLineString.emplace_back(std::forward<mbgl::LineString<double>>(asLineString(lineString)));
}
return mbglMultiLineString;
};
mbgl::Polygon<double> asMapboxGLPolygon(const QMapbox::CoordinatesCollection &polygon) {
mbgl::Polygon<double> asPolygon(const CoordinatesCollection &polygon) {
mbgl::Polygon<double> mbglPolygon;
mbglPolygon.reserve(polygon.size());
for (const auto &linearRing : polygon) {
mbgl::LinearRing<double> mbglLinearRing;
mbglLinearRing.reserve(linearRing.size());
for (const auto &coordinate: linearRing) {
mbglLinearRing.emplace_back(asMapboxGLPoint(coordinate));
mbglLinearRing.emplace_back(asPoint(coordinate));
}
mbglPolygon.emplace_back(std::move(mbglLinearRing));
}
return mbglPolygon;
};
mbgl::MultiPolygon<double> asMapboxGLMultiPolygon(const QMapbox::CoordinatesCollections &multiPolygon) {
mbgl::MultiPolygon<double> asMultiPolygon(const CoordinatesCollections &multiPolygon) {
mbgl::MultiPolygon<double> mbglMultiPolygon;
mbglMultiPolygon.reserve(multiPolygon.size());
for (const auto &polygon : multiPolygon) {
mbglMultiPolygon.emplace_back(std::forward<mbgl::Polygon<double>>(asMapboxGLPolygon(polygon)));
mbglMultiPolygon.emplace_back(std::forward<mbgl::Polygon<double>>(asPolygon(polygon)));
}
return mbglMultiPolygon;
};
mbgl::Value asMapboxGLPropertyValue(const QVariant &value) {
mbgl::Value asPropertyValue(const QVariant &value) {
auto valueList = [](const QVariantList &list) {
std::vector<mbgl::Value> mbglList;
mbglList.reserve(list.size());
for (const auto& listValue : list) {
mbglList.emplace_back(asMapboxGLPropertyValue(listValue));
mbglList.emplace_back(asPropertyValue(listValue));
}
return mbglList;
};
@@ -72,7 +72,7 @@ mbgl::Value asMapboxGLPropertyValue(const QVariant &value) {
std::unordered_map<std::string, mbgl::Value> mbglMap;
mbglMap.reserve(map.size());
for (auto it = map.constBegin(); it != map.constEnd(); ++it) {
mbglMap.emplace(std::make_pair(it.key().toStdString(), asMapboxGLPropertyValue(it.value())));
mbglMap.emplace(std::make_pair(it.key().toStdString(), asPropertyValue(it.value())));
}
return mbglMap;
};
@@ -80,7 +80,7 @@ mbgl::Value asMapboxGLPropertyValue(const QVariant &value) {
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
switch (value.typeId()) {
#else
switch (value.type()) {
switch (static_cast<QMetaType::Type>(value.type())) {
#endif
case QMetaType::UnknownType:
return mbgl::NullValue {};
@@ -104,11 +104,11 @@ mbgl::Value asMapboxGLPropertyValue(const QVariant &value) {
}
}
mbgl::FeatureIdentifier asMapboxGLFeatureIdentifier(const QVariant &id) {
mbgl::FeatureIdentifier asFeatureIdentifier(const QVariant &id) {
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
switch (id.typeId()) {
#else
switch (id.type()) {
switch (static_cast<QMetaType::Type>(id.type())) {
#endif
case QMetaType::UnknownType:
return {};
@@ -126,37 +126,37 @@ mbgl::FeatureIdentifier asMapboxGLFeatureIdentifier(const QVariant &id) {
}
}
mbgl::GeoJSONFeature asMapboxGLFeature(const QMapbox::Feature &feature) {
mbgl::GeoJSONFeature asFeature(const Feature &feature) {
mbgl::PropertyMap properties;
properties.reserve(feature.properties.size());
for (auto it = feature.properties.constBegin(); it != feature.properties.constEnd(); ++it) {
properties.emplace(std::make_pair(it.key().toStdString(), asMapboxGLPropertyValue(it.value())));
properties.emplace(std::make_pair(it.key().toStdString(), asPropertyValue(it.value())));
}
mbgl::FeatureIdentifier id = asMapboxGLFeatureIdentifier(feature.id);
mbgl::FeatureIdentifier id = asFeatureIdentifier(feature.id);
if (feature.type == QMapbox::Feature::PointType) {
const QMapbox::Coordinates &points = feature.geometry.first().first();
if (feature.type == Feature::PointType) {
const Coordinates &points = feature.geometry.first().first();
if (points.size() == 1) {
return { asMapboxGLPoint(points.first()), std::move(properties), std::move(id) };
return { asPoint(points.first()), std::move(properties), std::move(id) };
} else {
return { asMapboxGLMultiPoint(points), std::move(properties), std::move(id) };
return { asMultiPoint(points), std::move(properties), std::move(id) };
}
} else if (feature.type == QMapbox::Feature::LineStringType) {
const QMapbox::CoordinatesCollection &lineStrings = feature.geometry.first();
} else if (feature.type == Feature::LineStringType) {
const CoordinatesCollection &lineStrings = feature.geometry.first();
if (lineStrings.size() == 1) {
return { asMapboxGLLineString(lineStrings.first()), std::move(properties), std::move(id) };
return { asLineString(lineStrings.first()), std::move(properties), std::move(id) };
} else {
return { asMapboxGLMultiLineString(lineStrings), std::move(properties), std::move(id) };
return { asMultiLineString(lineStrings), std::move(properties), std::move(id) };
}
} else { // PolygonType
const QMapbox::CoordinatesCollections &polygons = feature.geometry;
const CoordinatesCollections &polygons = feature.geometry;
if (polygons.size() == 1) {
return { asMapboxGLPolygon(polygons.first()), std::move(properties), std::move(id) };
return { asPolygon(polygons.first()), std::move(properties), std::move(id) };
} else {
return { asMapboxGLMultiPolygon(polygons), std::move(properties), std::move(id) };
return { asMultiPolygon(polygons), std::move(properties), std::move(id) };
}
}
};
} // namespace QMapbox
} // namespace QMapLibreGL::GeoJSON

View File

@@ -0,0 +1,25 @@
#pragma once
#include <QMapLibreGL/Types>
#include <mapbox/geojson.hpp>
#include <mbgl/util/geometry.hpp>
#include <mbgl/util/feature.hpp>
#include <QVariant>
#include <string>
namespace QMapLibreGL::GeoJSON {
mbgl::Point<double> asPoint(const Coordinate &coordinate);
mbgl::MultiPoint<double> asMultiPoint(const Coordinates &multiPoint);
mbgl::LineString<double> asLineString(const Coordinates &lineString);
mbgl::MultiLineString<double> asMultiLineString(const CoordinatesCollection &multiLineString);
mbgl::Polygon<double> asPolygon(const CoordinatesCollection &polygon);
mbgl::MultiPolygon<double> asMultiPolygon(const CoordinatesCollections &multiPolygon);
mbgl::Value asPropertyValue(const QVariant &value);
mbgl::FeatureIdentifier asFeatureIdentifier(const QVariant &id);
mbgl::GeoJSONFeature asFeature(const Feature &feature);
} // namespace QMapLibreGL::GeoJSON

View File

@@ -0,0 +1,122 @@
#include "map_observer.hpp"
#include "../map_p.hpp"
#include <mbgl/util/exception.hpp>
#include <exception>
namespace QMapLibreGL {
MapObserver::MapObserver(MapPrivate *d)
: d_ptr(d)
{
}
MapObserver::~MapObserver()
{
}
void MapObserver::onCameraWillChange(mbgl::MapObserver::CameraChangeMode mode)
{
if (mode == mbgl::MapObserver::CameraChangeMode::Immediate) {
emit mapChanged(Map::MapChangeRegionWillChange);
} else {
emit mapChanged(Map::MapChangeRegionWillChangeAnimated);
}
}
void MapObserver::onCameraIsChanging()
{
emit mapChanged(Map::MapChangeRegionIsChanging);
}
void MapObserver::onCameraDidChange(mbgl::MapObserver::CameraChangeMode mode)
{
if (mode == mbgl::MapObserver::CameraChangeMode::Immediate) {
emit mapChanged(Map::MapChangeRegionDidChange);
} else {
emit mapChanged(Map::MapChangeRegionDidChangeAnimated);
}
}
void MapObserver::onWillStartLoadingMap()
{
emit mapChanged(Map::MapChangeWillStartLoadingMap);
}
void MapObserver::onDidFinishLoadingMap()
{
emit mapChanged(Map::MapChangeDidFinishLoadingMap);
}
void MapObserver::onDidFailLoadingMap(mbgl::MapLoadError error, const std::string& what)
{
emit mapChanged(Map::MapChangeDidFailLoadingMap);
Map::MapLoadingFailure type;
QString description(what.c_str());
switch (error) {
case mbgl::MapLoadError::StyleParseError:
type = Map::MapLoadingFailure::StyleParseFailure;
break;
case mbgl::MapLoadError::StyleLoadError:
type = Map::MapLoadingFailure::StyleLoadFailure;
break;
case mbgl::MapLoadError::NotFoundError:
type = Map::MapLoadingFailure::NotFoundFailure;
break;
default:
type = Map::MapLoadingFailure::UnknownFailure;
}
emit mapLoadingFailed(type, description);
}
void MapObserver::onWillStartRenderingFrame()
{
emit mapChanged(Map::MapChangeWillStartRenderingFrame);
}
void MapObserver::onDidFinishRenderingFrame(mbgl::MapObserver::RenderFrameStatus status)
{
if (status.mode == mbgl::MapObserver::RenderMode::Partial) {
emit mapChanged(Map::MapChangeDidFinishRenderingFrame);
} else {
emit mapChanged(Map::MapChangeDidFinishRenderingFrameFullyRendered);
}
}
void MapObserver::onWillStartRenderingMap()
{
emit mapChanged(Map::MapChangeWillStartRenderingMap);
}
void MapObserver::onDidFinishRenderingMap(mbgl::MapObserver::RenderMode mode)
{
if (mode == mbgl::MapObserver::RenderMode::Partial) {
emit mapChanged(Map::MapChangeDidFinishRenderingMap);
} else {
emit mapChanged(Map::MapChangeDidFinishRenderingMapFullyRendered);
}
}
void MapObserver::onDidFinishLoadingStyle()
{
emit mapChanged(Map::MapChangeDidFinishLoadingStyle);
}
void MapObserver::onSourceChanged(mbgl::style::Source&)
{
std::string attribution;
for (const auto& source : d_ptr->mapObj->getStyle().getSources()) {
// Avoid duplicates by using the most complete attribution HTML snippet.
if (source->getAttribution() && (attribution.size() < source->getAttribution()->size()))
attribution = *source->getAttribution();
}
emit copyrightsChanged(QString::fromStdString(attribution));
emit mapChanged(Map::MapChangeSourceDidChange);
}
} // namespace QMapLibreGL

View File

@@ -1,6 +1,6 @@
#pragma once
#include "qmapboxgl.hpp"
#include <QMapLibreGL/Map>
#include <mbgl/map/map_observer.hpp>
#include <mbgl/style/style.hpp>
@@ -10,15 +10,17 @@
#include <exception>
#include <memory>
class QMapboxGLPrivate;
namespace QMapLibreGL {
class QMapboxGLMapObserver : public QObject, public mbgl::MapObserver
class MapPrivate;
class MapObserver : public QObject, public mbgl::MapObserver
{
Q_OBJECT
public:
explicit QMapboxGLMapObserver(QMapboxGLPrivate *);
virtual ~QMapboxGLMapObserver();
explicit MapObserver(MapPrivate *);
virtual ~MapObserver();
// mbgl::MapObserver implementation.
void onCameraWillChange(mbgl::MapObserver::CameraChangeMode) final;
@@ -35,12 +37,14 @@ public:
void onSourceChanged(mbgl::style::Source&) final;
signals:
void mapChanged(QMapboxGL::MapChange);
void mapLoadingFailed(QMapboxGL::MapLoadingFailure, const QString &reason);
void mapChanged(Map::MapChange);
void mapLoadingFailed(Map::MapLoadingFailure, const QString &reason);
void copyrightsChanged(const QString &copyrightsHtml);
private:
Q_DISABLE_COPY(QMapboxGLMapObserver)
Q_DISABLE_COPY(MapObserver)
QMapboxGLPrivate *d_ptr;
MapPrivate *d_ptr;
};
} // namespace QMapLibreGL

View File

@@ -1,10 +1,11 @@
#include "qmapboxgl_map_renderer.hpp"
#include "qmapboxgl_scheduler.hpp"
#include "map_renderer.hpp"
#include "scheduler.hpp"
#include <mbgl/gfx/backend_scope.hpp>
#include <QThreadStorage>
#include <QtGlobal>
namespace {
static bool needsToForceScheduler() {
static QThreadStorage<bool> force;
@@ -17,16 +18,21 @@ static bool needsToForceScheduler() {
};
static auto *getScheduler() {
static QThreadStorage<std::shared_ptr<QMapboxGLScheduler>> scheduler;
static QThreadStorage<std::shared_ptr<QMapLibreGL::Scheduler>> scheduler;
if (!scheduler.hasLocalData()) {
scheduler.setLocalData(std::make_shared<QMapboxGLScheduler>());
scheduler.setLocalData(std::make_shared<QMapLibreGL::Scheduler>());
}
return scheduler.localData().get();
};
QMapboxGLMapRenderer::QMapboxGLMapRenderer(qreal pixelRatio, QMapboxGLSettings::GLContextMode mode, const QString &localFontFamily)
} // namespace
namespace QMapLibreGL {
MapRenderer::MapRenderer(qreal pixelRatio, Settings::GLContextMode mode, const QString &localFontFamily)
: m_backend(static_cast<mbgl::gfx::ContextMode>(mode)),
m_renderer(std::make_unique<mbgl::Renderer>(m_backend, pixelRatio,
localFontFamily.isEmpty() ? mbgl::nullopt : mbgl::optional<std::string> { localFontFamily.toStdString() }))
@@ -43,29 +49,29 @@ QMapboxGLMapRenderer::QMapboxGLMapRenderer(qreal pixelRatio, QMapboxGLSettings::
mbgl::Scheduler::SetCurrent(scheduler);
}
connect(scheduler, &QMapboxGLScheduler::needsProcessing, this, &QMapboxGLMapRenderer::needsRendering);
connect(scheduler, &Scheduler::needsProcessing, this, &MapRenderer::needsRendering);
}
}
QMapboxGLMapRenderer::~QMapboxGLMapRenderer()
MapRenderer::~MapRenderer()
{
MBGL_VERIFY_THREAD(tid);
}
void QMapboxGLMapRenderer::updateParameters(std::shared_ptr<mbgl::UpdateParameters> newParameters)
void MapRenderer::updateParameters(std::shared_ptr<mbgl::UpdateParameters> newParameters)
{
std::lock_guard<std::mutex> lock(m_updateMutex);
m_updateParameters = std::move(newParameters);
}
void QMapboxGLMapRenderer::updateFramebuffer(quint32 fbo, const mbgl::Size &size)
void MapRenderer::updateFramebuffer(quint32 fbo, const mbgl::Size &size)
{
MBGL_VERIFY_THREAD(tid);
m_backend.updateFramebuffer(fbo, size);
}
void QMapboxGLMapRenderer::render()
void MapRenderer::render()
{
MBGL_VERIFY_THREAD(tid);
@@ -91,7 +97,9 @@ void QMapboxGLMapRenderer::render()
}
}
void QMapboxGLMapRenderer::setObserver(std::shared_ptr<mbgl::RendererObserver> observer)
void MapRenderer::setObserver(std::shared_ptr<mbgl::RendererObserver> observer)
{
m_renderer->setObserver(observer.get());
}
} // namespace QMapLibreGL

View File

@@ -1,13 +1,15 @@
#pragma once
#include "qmapboxgl.hpp"
#include "qmapboxgl_renderer_backend.hpp"
#include <QMapLibreGL/Settings>
#include "renderer_backend.hpp"
#include <mbgl/renderer/renderer.hpp>
#include <mbgl/renderer/renderer_observer.hpp>
#include <mbgl/util/util.hpp>
#include <QtGlobal>
#include <QObject>
#include <memory>
#include <mutex>
@@ -17,15 +19,17 @@ class Renderer;
class UpdateParameters;
} // namespace mbgl
class QMapboxGLRendererBackend;
namespace QMapLibreGL {
class QMapboxGLMapRenderer : public QObject
class RendererBackend;
class MapRenderer : public QObject
{
Q_OBJECT
public:
QMapboxGLMapRenderer(qreal pixelRatio, QMapboxGLSettings::GLContextMode, const QString &localFontFamily);
virtual ~QMapboxGLMapRenderer();
MapRenderer(qreal pixelRatio, Settings::GLContextMode, const QString &localFontFamily);
virtual ~MapRenderer();
void render();
void updateFramebuffer(quint32 fbo, const mbgl::Size &size);
@@ -40,13 +44,15 @@ signals:
private:
MBGL_STORE_THREAD(tid)
Q_DISABLE_COPY(QMapboxGLMapRenderer)
Q_DISABLE_COPY(MapRenderer)
std::mutex m_updateMutex;
std::shared_ptr<mbgl::UpdateParameters> m_updateParameters;
QMapboxGLRendererBackend m_backend;
std::unique_ptr<mbgl::Renderer> m_renderer;
RendererBackend m_backend;
std::unique_ptr<mbgl::Renderer> m_renderer{};
bool m_forceScheduler;
bool m_forceScheduler{};
};
} // namespace QMapLibreGL

View File

@@ -0,0 +1,56 @@
#include "renderer_backend.hpp"
#include <mbgl/gfx/backend_scope.hpp>
#include <mbgl/gl/renderable_resource.hpp>
#include <QtGlobal>
#include <QOpenGLContext>
namespace QMapLibreGL {
class RenderableResource final : public mbgl::gl::RenderableResource {
public:
RenderableResource(RendererBackend& backend_) : backend(backend_) {
}
void bind() override {
assert(mbgl::gfx::BackendScope::exists());
backend.restoreFramebufferBinding();
backend.setViewport(0, 0, backend.getSize());
}
private:
RendererBackend& backend;
};
RendererBackend::RendererBackend(const mbgl::gfx::ContextMode contextMode_)
: mbgl::gl::RendererBackend(contextMode_),
mbgl::gfx::Renderable({ 0, 0 }, std::make_unique<RenderableResource>(*this)) {
}
RendererBackend::~RendererBackend() = default;
void RendererBackend::updateAssumedState() {
assumeFramebufferBinding(ImplicitFramebufferBinding);
assumeViewport(0, 0, size);
}
void RendererBackend::restoreFramebufferBinding() {
setFramebufferBinding(m_fbo);
}
void RendererBackend::updateFramebuffer(quint32 fbo, const mbgl::Size& newSize) {
m_fbo = fbo;
size = newSize;
}
/*!
Initializes an OpenGL extension function such as Vertex Array Objects (VAOs),
required by MapLibre GL Native engine.
*/
mbgl::gl::ProcAddress RendererBackend::getExtensionFunctionPointer(const char* name) {
QOpenGLContext* thisContext = QOpenGLContext::currentContext();
return thisContext->getProcAddress(name);
}
} // namespace QMapLibreGL

View File

@@ -1,15 +1,17 @@
#pragma once
#include "qmapboxgl.hpp"
#include <mbgl/gfx/renderable.hpp>
#include <mbgl/gl/renderer_backend.hpp>
class QMapboxGLRendererBackend final : public mbgl::gl::RendererBackend,
#include <QtGlobal>
namespace QMapLibreGL {
class RendererBackend final : public mbgl::gl::RendererBackend,
public mbgl::gfx::Renderable {
public:
QMapboxGLRendererBackend(mbgl::gfx::ContextMode);
~QMapboxGLRendererBackend() override;
RendererBackend(mbgl::gfx::ContextMode);
~RendererBackend() override;
void updateFramebuffer(quint32 fbo, const mbgl::Size&);
void restoreFramebufferBinding();
@@ -31,7 +33,9 @@ protected:
void updateAssumedState() override;
private:
quint32 m_fbo = 0;
quint32 m_fbo{};
Q_DISABLE_COPY(QMapboxGLRendererBackend)
Q_DISABLE_COPY(RendererBackend)
};
} // namespace QMapLibreGL

View File

@@ -8,16 +8,18 @@
#include <memory>
namespace QMapLibreGL {
// Forwards RendererObserver signals to the given
// Delegate RendererObserver on the given RunLoop
class QMapboxGLRendererObserver : public mbgl::RendererObserver {
class RendererObserver : public mbgl::RendererObserver {
public:
QMapboxGLRendererObserver(mbgl::util::RunLoop& mapRunLoop, mbgl::RendererObserver& delegate_)
RendererObserver(mbgl::util::RunLoop& mapRunLoop, mbgl::RendererObserver& delegate_)
: mailbox(std::make_shared<mbgl::Mailbox>(mapRunLoop))
, delegate(delegate_, mailbox) {
}
~QMapboxGLRendererObserver() {
~RendererObserver() {
mailbox->close();
}
@@ -46,6 +48,8 @@ public:
}
private:
std::shared_ptr<mbgl::Mailbox> mailbox;
std::shared_ptr<mbgl::Mailbox> mailbox{};
mbgl::ActorRef<mbgl::RendererObserver> delegate;
};
} // namespace QMapLibreGL

View File

@@ -1,19 +1,21 @@
#include "qmapboxgl_scheduler.hpp"
#include "scheduler.hpp"
#include <mbgl/util/util.hpp>
#include <cassert>
QMapboxGLScheduler::QMapboxGLScheduler()
namespace QMapLibreGL {
Scheduler::Scheduler()
{
}
QMapboxGLScheduler::~QMapboxGLScheduler()
Scheduler::~Scheduler()
{
MBGL_VERIFY_THREAD(tid);
}
void QMapboxGLScheduler::schedule(std::function<void()> function) {
void Scheduler::schedule(std::function<void()> function) {
std::lock_guard<std::mutex> lock(m_taskQueueMutex);
m_taskQueue.push(std::move(function));
@@ -22,7 +24,7 @@ void QMapboxGLScheduler::schedule(std::function<void()> function) {
emit needsProcessing();
}
void QMapboxGLScheduler::processEvents()
void Scheduler::processEvents()
{
std::queue<std::function<void()>> taskQueue;
{
@@ -36,3 +38,5 @@ void QMapboxGLScheduler::processEvents()
taskQueue.pop();
}
}
} // namespace QMapLibreGL

View File

@@ -9,17 +9,19 @@
#include <mutex>
#include <queue>
class QMapboxGLScheduler : public QObject, public mbgl::Scheduler
namespace QMapLibreGL {
class Scheduler : public QObject, public mbgl::Scheduler
{
Q_OBJECT
public:
QMapboxGLScheduler();
virtual ~QMapboxGLScheduler();
Scheduler();
virtual ~Scheduler();
// mbgl::Scheduler implementation.
void schedule(std::function<void()> scheduled) final;
mapbox::base::WeakPtr<Scheduler> makeWeakPtr() override { return weakFactory.makeWeakPtr(); }
mapbox::base::WeakPtr<mbgl::Scheduler> makeWeakPtr() override { return weakFactory.makeWeakPtr(); }
void processEvents();
@@ -33,3 +35,5 @@ private:
std::queue<std::function<void()>> m_taskQueue;
mapbox::base::WeakPtrFactory<Scheduler> weakFactory{this};
};
} // namepace QMapLibreGL

View File

@@ -1,4 +1,4 @@
#include <QApplication>
#include <QGuiApplication>
#include <mbgl/test.hpp>
#include <cstring>
@@ -15,7 +15,7 @@
#define str(s) #s
int main(int argc, char *argv[]) {
QApplication app(argc, argv);
QGuiApplication app(argc, argv);
#ifdef WORK_DIRECTORY
#ifdef _MSC_VER

View File

@@ -1,80 +0,0 @@
#include "qmapboxgl.test.hpp"
#include <QMapbox>
#include <QFile>
#include <QGuiApplication>
#include <QOpenGLContext>
#include <QOpenGLFunctions>
#include <QTextStream>
#include <mbgl/test/util.hpp>
QMapboxGLTest::QMapboxGLTest() : size(512, 512), fbo((assert(widget.context()->isValid()), widget.makeCurrent(), size)), map(nullptr, settings, size) {
connect(&map, &QMapboxGL::mapChanged, this, &QMapboxGLTest::onMapChanged);
connect(&map, &QMapboxGL::needsRendering, this, &QMapboxGLTest::onNeedsRendering);
map.resize(fbo.size());
map.setFramebufferObject(fbo.handle(), fbo.size());
map.setCoordinateZoom(QMapbox::Coordinate(60.170448, 24.942046), 14);
}
void QMapboxGLTest::runUntil(QMapboxGL::MapChange status) {
changeCallback = [&](QMapboxGL::MapChange change) {
if (change == status) {
qApp->exit();
changeCallback = nullptr;
}
};
qApp->exec();
}
void QMapboxGLTest::onMapChanged(QMapboxGL::MapChange change) {
if (changeCallback) {
changeCallback(change);
}
}
void QMapboxGLTest::onNeedsRendering() {
widget.makeCurrent();
fbo.bind();
QOpenGLContext::currentContext()->functions()->glViewport(0, 0, fbo.width(), fbo.height());
map.render();
}
TEST_F(QMapboxGLTest, TEST_DISABLED_ON_CI(styleJson)) {
QFile f("test/fixtures/resources/style_vector.json");
ASSERT_TRUE(f.open(QFile::ReadOnly | QFile::Text));
QTextStream in(&f);
QString json = in.readAll();
map.setStyleJson(json);
ASSERT_EQ(map.styleJson(), json);
runUntil(QMapboxGL::MapChangeDidFinishLoadingMap);
map.setStyleJson("invalid json");
runUntil(QMapboxGL::MapChangeDidFailLoadingMap);
map.setStyleJson("\"\"");
runUntil(QMapboxGL::MapChangeDidFailLoadingMap);
map.setStyleJson(QString());
runUntil(QMapboxGL::MapChangeDidFailLoadingMap);
}
TEST_F(QMapboxGLTest, TEST_DISABLED_ON_CI(styleUrl)) {
QString url(QMapbox::defaultStyles()[0].first);
map.setStyleUrl(url);
ASSERT_EQ(map.styleUrl(), url);
runUntil(QMapboxGL::MapChangeDidFinishLoadingMap);
map.setStyleUrl("invalid://url");
runUntil(QMapboxGL::MapChangeDidFailLoadingMap);
map.setStyleUrl(QString());
runUntil(QMapboxGL::MapChangeDidFailLoadingMap);
}

View File

@@ -1,30 +0,0 @@
#include <QMapboxGL>
#include <QGLWidget>
#include <QGLFramebufferObject>
#include <gtest/gtest.h>
class QMapboxGLTest : public QObject, public ::testing::Test {
Q_OBJECT
public:
QMapboxGLTest();
void runUntil(QMapboxGL::MapChange);
private:
QGLWidget widget;
const QSize size;
QGLFramebufferObject fbo;
protected:
QMapboxGLSettings settings;
QMapboxGL map;
std::function<void(QMapboxGL::MapChange)> changeCallback;
private slots:
void onMapChanged(QMapboxGL::MapChange);
void onNeedsRendering();
};

View File

@@ -0,0 +1,80 @@
#include "qmaplibregl.test.hpp"
#include <QMapLibreGL/Map>
#include <QFile>
#include <QGuiApplication>
#include <QOpenGLContext>
#include <QOpenGLFunctions>
#include <QTextStream>
#include <mbgl/test/util.hpp>
QMapLibreGLTest::QMapLibreGLTest() : size(512, 512), fbo((assert(widget.context()->isValid()), widget.makeCurrent(), size)), map(nullptr, settings, size) {
connect(&map, &QMapLibreGL::mapChanged, this, &QMapLibreGLTest::onMapChanged);
connect(&map, &QMapLibreGL::needsRendering, this, &QMapLibreGLTest::onNeedsRendering);
map.resize(fbo.size());
map.setFramebufferObject(fbo.handle(), fbo.size());
map.setCoordinateZoom(QMapLibreGL::Coordinate(60.170448, 24.942046), 14);
}
void QMapLibreGLTest::runUntil(QMapLibreGL::MapChange status) {
changeCallback = [&](QMapLibreGL::MapChange change) {
if (change == status) {
qApp->exit();
changeCallback = nullptr;
}
};
qApp->exec();
}
void QMapLibreGLTest::onMapChanged(QMapLibreGL::MapChange change) {
if (changeCallback) {
changeCallback(change);
}
}
void QMapLibreGLTest::onNeedsRendering() {
widget.makeCurrent();
fbo.bind();
QOpenGLContext::currentContext()->functions()->glViewport(0, 0, fbo.width(), fbo.height());
map.render();
}
TEST_F(QMapLibreGLTest, TEST_DISABLED_ON_CI(styleJson)) {
QFile f("test/fixtures/resources/style_vector.json");
ASSERT_TRUE(f.open(QFile::ReadOnly | QFile::Text));
QTextStream in(&f);
QString json = in.readAll();
map.setStyleJson(json);
ASSERT_EQ(map.styleJson(), json);
runUntil(QMapLibreGL::MapChangeDidFinishLoadingMap);
map.setStyleJson("invalid json");
runUntil(QMapLibreGL::MapChangeDidFailLoadingMap);
map.setStyleJson("\"\"");
runUntil(QMapLibreGL::MapChangeDidFailLoadingMap);
map.setStyleJson(QString());
runUntil(QMapLibreGL::MapChangeDidFailLoadingMap);
}
TEST_F(QMapLibreGLTest, TEST_DISABLED_ON_CI(styleUrl)) {
QString url(QMapLibreGL::defaultStyles()[0].first);
map.setStyleUrl(url);
ASSERT_EQ(map.styleUrl(), url);
runUntil(QMapLibreGL::MapChangeDidFinishLoadingMap);
map.setStyleUrl("invalid://url");
runUntil(QMapLibreGL::MapChangeDidFailLoadingMap);
map.setStyleUrl(QString());
runUntil(QMapLibreGL::MapChangeDidFailLoadingMap);
}

View File

@@ -0,0 +1,30 @@
#include <QMapLibreGL/Map>
#include <QGLWidget>
#include <QGLFramebufferObject>
#include <gtest/gtest.h>
class QMapLibreGLTest : public QObject, public ::testing::Test {
Q_OBJECT
public:
QMapLibreGLTest();
void runUntil(QMapLibreGL::MapChange);
private:
QGLWidget widget;
const QSize size;
QGLFramebufferObject fbo;
protected:
Settings settings;
Map map;
std::function<void(QMapLibreGL::MapChange)> changeCallback;
private slots:
void onMapChanged(QMapLibreGL::MapChange);
void onNeedsRendering();
};