10#include <QtCore/QByteArray>
11#include <QtCore/QCoreApplication>
12#include <QtGui/QOpenGLContext>
13#include <QtOpenGL/QOpenGLFramebufferObject>
14#include <QtLocation/private/qdeclarativecirclemapitem_p.h>
15#include <QtLocation/private/qdeclarativegeomapitembase_p.h>
16#include <QtLocation/private/qdeclarativepolygonmapitem_p.h>
17#include <QtLocation/private/qdeclarativepolylinemapitem_p.h>
18#include <QtLocation/private/qdeclarativerectanglemapitem_p.h>
19#include <QtLocation/private/qgeoprojection_p.h>
20#include <QtQuick/QQuickWindow>
21#include <QtQuick/QSGImageNode>
22#include <QtQuick/private/qsgcontext_p.h>
29#define MBGL_TILE_SIZE 512.0
35static char developmentToken[] =
36 "pk.eyJ1IjoicXRzZGsiLCJhIjoiY2l5azV5MHh5MDAwdTMybzBybjUzZnhxYSJ9.9rfbeqPjX2BusLRDXHCOBA";
38static const double invLog2 = 1.0 / std::log(2.0);
40static double zoomLevelFrom256(
double zoomLevelFor256,
double tileSize)
42 return std::log(std::pow(2.0, zoomLevelFor256) * 256.0 /
tileSize) * invLog2;
65 QMapboxGL *
map =
nullptr;
71 qWarning(
"The MapboxGL plugin works with both Desktop and ES 2.0+ OpenGL versions.");
72 qWarning(
"Verify that your Qt is built with OpenGL, and what kind of OpenGL.");
73 qWarning(
"To force using a specific OpenGL version, check QSurfaceFormat::setRenderableType and QSurfaceFormat::setDefaultFormat");
94 &&
m_settings.accessToken() == developmentToken;
107 map->setMargins(margins);
129 syncStyleChanges(
map);
152 switch (
item->itemType()) {
200 emit q->sgNodeChanged();
207 switch (
item->itemType()) {
230 emit q->sgNodeChanged();
238 emit q->sgNodeChanged();
246 emit q->sgNodeChanged();
254 emit q->sgNodeChanged();
261 if (va == m_visibleArea)
268 emit q->sgNodeChanged();
273 return m_visibleArea;
276void QGeoMapMapboxGLPrivate::syncStyleChanges(QMapboxGL *
map)
295 qWarning() <<
"Threaded rendering is not optimal in the Mapbox GL plugin.";
302 if (!
map->isFullyLoaded()) {
320 d->m_refresh.setInterval(250);
329 return QStringLiteral(
"* { vertical-align: middle; font-weight: normal }");
341 if (
d->m_settings.accessToken().isEmpty()) {
342 if (useChinaEndpoint) {
343 qWarning(
"Mapbox China requires an access token: https://www.mapbox.com/contact/sales");
345 d->m_settings.setAccessToken(developmentToken);
353 d->m_useFBO = useFBO;
359 d->m_mapItemsBefore = before;
373 return d->updateSceneGraph(oldNode,
window);
376void QGeoMapMapboxGL::onMapChanged(QMapboxGL::MapChange change)
380 if (change == QMapboxGL::MapChangeDidFinishLoadingStyle || change == QMapboxGL::MapChangeDidFailLoadingMap) {
381 d->m_styleLoaded =
true;
382 }
else if (change == QMapboxGL::MapChangeWillStartLoadingMap) {
383 d->m_styleLoaded =
false;
384 d->m_styleChanges.clear();
391void QGeoMapMapboxGL::onMapItemPropertyChanged()
402void QGeoMapMapboxGL::onMapItemSubPropertyChanged()
412void QGeoMapMapboxGL::onMapItemUnsupportedPropertyChanged()
415 qWarning() <<
"Unsupported property for managed Map item";
418void QGeoMapMapboxGL::onMapItemGeometryChanged()
432 QString copyrightsHtmlFinal = copyrightsHtml;
434 if (
d->m_developmentMode) {
435 copyrightsHtmlFinal.
prepend(
"<a href='https://www.mapbox.com/pricing'>"
436 +
tr(
"Development access token, do not use in production.") +
"</a> - ");
439 if (
d->m_activeMapType.name().startsWith(
"mapbox://")) {
440 copyrightsHtmlFinal =
"<table><tr><th><img src='qrc:/mapboxgl/logo.png'/></th><th>"
441 + copyrightsHtmlFinal +
"</th></tr></table>";
static QCoreApplication * instance() noexcept
Returns a pointer to the application's QCoreApplication (or QGuiApplication/QApplication) instance.
void colorChanged(const QColor &color)
void radiusChanged(qreal radius)
QDeclarativeMapLineProperties * border
\qmlpropertygroup Location::MapCircle::border \qmlproperty int MapCircle::border.width \qmlproperty c...
void centerChanged(const QGeoCoordinate ¢er)
void mapItemOpacityChanged()
void widthChanged(qreal width)
void colorChanged(const QColor &color)
void colorChanged(const QColor &color)
QDeclarativeMapLineProperties * border
\qmlpropertygroup Location::MapPolygon::border \qmlproperty int MapPolygon::border....
QDeclarativeMapLineProperties * line
\qmlpropertygroup Location::MapPolyline::line \qmlproperty int MapPolyline::line.width \qmlproperty c...
void bottomRightChanged(const QGeoCoordinate &bottomRight)
void topLeftChanged(const QGeoCoordinate &topLeft)
void colorChanged(const QColor &color)
QDeclarativeMapLineProperties * border
\qmlpropertygroup Location::MapRectangle::border \qmlproperty int MapRectangle::border....
QGeoCoordinate center() const
double longitude
This property holds the longitude in decimal degrees.
double latitude
This property holds the latitude in decimal degrees.
QRectF visibleArea() const override
void setVisibleArea(const QRectF &visibleArea) override
QMapboxGLSettings m_settings
void addMapItem(QDeclarativeGeoMapItemBase *item) override
void changeActiveMapType(const QGeoMapType &mapType) override
QList< QSharedPointer< QMapboxGLStyleChange > > m_styleChanges
~QGeoMapMapboxGLPrivate()
QGeoMap::ItemTypes supportedMapItemTypes() const override
void changeCameraData(const QGeoCameraData &oldCameraData) override
void removeMapItem(QDeclarativeGeoMapItemBase *item) override
QGeoMapMapboxGLPrivate(QGeoMappingManagerEngineMapboxGL *engine)
void changeViewportSize(const QSize &size) override
QSGNode * updateSceneGraph(QSGNode *oldNode, QQuickWindow *window)
void setMapboxGLSettings(const QMapboxGLSettings &, bool useChinaEndpoint)
QString copyrightsStyleSheet() const override
Capabilities capabilities() const override
void setMapItemsBefore(const QString &)
void copyrightsChanged(const QString ©rightsHtml)
virtual ~QGeoMapMapboxGL()
QGeoMapMapboxGL(QGeoMappingManagerEngineMapboxGL *engine, QObject *parent)
QSGNode * updateSceneGraph(QSGNode *oldNode, QQuickWindow *window) override
QGeoProjection * m_geoProjection
QGeoMapType m_activeMapType
QRectF clampVisibleArea(const QRectF &visibleArea) const
QGeoCameraData m_cameraData
@ SupportsAnchoringCoordinate
void addMapItem(QDeclarativeGeoMapItemBase *item)
void copyrightsChanged(const QString ©rightsHtml)
virtual void setVisibleArea(const QRectF &visibleArea)=0
static QSharedPointer< QMapboxGLStyleChange > fromMapItem(QDeclarativeGeoMapItemBase *)
static QList< QSharedPointer< QMapboxGLStyleChange > > addMapItem(QDeclarativeGeoMapItemBase *, const QString &before)
static QList< QSharedPointer< QMapboxGLStyleChange > > removeMapItem(QDeclarativeGeoMapItemBase *)
static QList< QSharedPointer< QMapboxGLStyleChange > > fromMapItem(QDeclarativeGeoMapItemBase *)
static QList< QSharedPointer< QMapboxGLStyleChange > > fromMapItem(QDeclarativeGeoMapItemBase *)
QObject * parent() const
Returns a pointer to the parent object.
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
QObject * sender() const
Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; othe...
QThread * thread() const
Returns the thread in which the object lives.
static QOpenGLContext * currentContext()
Returns the last context which called makeCurrent in the current thread, or \nullptr,...
\qmltype Window \instantiates QQuickWindow \inqmlmodule QtQuick
\inmodule QtCore\reentrant
constexpr bool isEmpty() const noexcept
Returns true if the rectangle is empty, otherwise returns false.
constexpr qreal y() const noexcept
Returns the y-coordinate of the rectangle's top edge.
constexpr qreal height() const noexcept
Returns the height of the rectangle.
constexpr qreal width() const noexcept
Returns the width of the rectangle.
constexpr qreal x() const noexcept
Returns the x-coordinate of the rectangle's left edge.
\group qtquick-scenegraph-nodes \title Qt Quick Scene Graph Node classes
constexpr int height() const noexcept
Returns the height.
constexpr int width() const noexcept
Returns the width.
constexpr bool isEmpty() const noexcept
Returns true if either of the width and height is less than or equal to 0; otherwise returns false.
\macro QT_RESTRICTED_CAST_FROM_ASCII
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
QString & prepend(QChar c)
void timeout(QPrivateSignal)
This signal is emitted when the timer times out.
QMap< QString, QString > map
[6]
static QT_BEGIN_NAMESPACE const int tileSize
GLint GLenum GLsizei GLsizei GLsizei GLint border
GLdouble GLdouble GLdouble GLdouble q
#define QStringLiteral(str)
QSettings settings("MySoft", "Star Runner")
[0]
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent