[-]
[+]
|
Changed |
_service:tar_git:mapbox-gl-qml.spec
|
|
[-]
[+]
|
Changed |
_service
^
|
@@ -2,7 +2,7 @@
<service name="tar_git">
<param name="url">https://github.com/rinigus/mapbox-gl-qml.git</param>
<param name="branch">master</param>
- <param name="revision">1.7.7.1</param>
+ <param name="revision">2.0.1</param>
<param name="debian">N</param>
<param name="dumb">N</param>
</service>
|
[-]
[+]
|
Changed |
_service:tar_git:mapboxgl-qml-2.0.1.tar.gz/CMakeLists.txt
^
|
@@ -11,13 +11,14 @@
set(CMAKE_INCLUDE_CURRENT_DIR ON)
option(USE_CURL_SSL "Use curl SSL" OFF)
+option(USE_FBO "Use map rendering using FBO" ON)
include(FindPkgConfig)
include(FeatureSummary)
include(GNUInstallDirs)
set(QT_MIN_VERSION "5.6.0")
-find_package(Qt5 ${QT_MIN_VERSION} COMPONENTS Gui Quick Positioning Sql REQUIRED)
+find_package(Qt5 ${QT_MIN_VERSION} COMPONENTS Gui Quick Positioning Sql Svg REQUIRED)
find_package(QMapboxGL REQUIRED)
if(USE_CURL_SSL)
|
[-]
[+]
|
Changed |
_service:tar_git:mapboxgl-qml-2.0.1.tar.gz/api.md
^
|
@@ -15,17 +15,17 @@
* [Include statements](#include-statements)
* [General comments](#general-comments)
* [Properties](#properties)
- * [Map settings on initialization](#map-settings-on-initialization)
- * [Map rendering](#map-rendering)
- * [Mangling of URLs](#mangling-of-urls)
- * [Other properties](#other-properties)
+ * [Map settings on initialization](#map-settings-on-initialization)
+ * [Map rendering](#map-rendering)
+ * [Mangling of URLs](#mangling-of-urls)
+ * [Other properties](#other-properties)
* [Queries and Signals](#queries-and-signals)
* [Methods](#methods)
- * [General methods](#general-methods)
- * [Map sources](#map-sources)
- * [Map layers](#map-layers)
- * [Map layout and paint properties](#map-layout-and-paint-properties)
- * [Tracking locations on the map](#tracking-locations-on-the-map)
+ * [General methods](#general-methods)
+ * [Map sources](#map-sources)
+ * [Map layers](#map-layers)
+ * [Map layout and paint properties](#map-layout-and-paint-properties)
+ * [Tracking locations on the map](#tracking-locations-on-the-map)
* [MapboxMapGestureArea](#mapboxmapgesturearea)
* [Signals](#signals)
* [Properties](#properties-1)
@@ -84,9 +84,9 @@
cache-related properties) would be used as they were specified for the
first created map.
-* `string `**`accessToken`** Mapbox-hosted vector tiles and styles require an API
- [access token](https://www.mapbox.com/help/define-access-token/),
- which you can obtain from the
+* `string `**`accessToken`** When hosted vector tiles and styles require an API
+ [access token](https://www.mapbox.com/help/define-access-token/), you can specify
+ them using `accessToken`. For example , for Mapbox you can obtain it from the
[Mapbox account page](https://www.mapbox.com/studio/account/tokens/). Access
tokens associate requests to Mapbox's vector tile and style APIs
with your Mapbox account. They also deter other developers from
@@ -142,6 +142,27 @@
[QSettings](http://doc.qt.io/qt-5/qsettings.html). At present,
this concerns only cache maximal size.
+* `qreal`**`devicePixelRatio`** Device pixel ratio that is used during
+ construction of the map widget. This should correspond to the true
+ physical to logical pixel ratio as given in Qt via
+ devicePixelRatio method of QScreen. This property allows sharp
+ rendering of the widget in HiDPI cases if the rendering through
+ framebuffer is used (see `useFBO`). For direct rendering case
+ (`useFBO=false`), `devicePixelRatio` is not used.
+
+ If `devicePixelRatio` is not specified, it is determined on the
+ basis of the parent QQuickItem, or if absent, on the basis of the
+ primary screen.
+
+ See also `pixelRatio` that can be changed after the widget is
+ constructed.
+
+* `bool `**`useFBO`** When set to `true` (default), Mapbox GL will use
+ a framebuffer object to render a map. When set to `false`, the map
+ is rendered issuing OpenGL commands directly, through a
+ QSGRenderNode. This is supported only for platforms starting with
+ Qt version 5.8.
+
### Map rendering
@@ -159,6 +180,12 @@
construct (see http://doc.qt.io/qt-5/qml-coordinate.html and
http://doc.qt.io/qt-5/qgeocoordinate.html for details).
+* `real `**`mapToQtPixelRatio`** Ratio between logical map and Qt
+ pixel sizes. When wishing to add elements on a map which should
+ have a fixed size in relation to other Qt UI elements, use this
+ property to when specifying sizes in map styles. For example, when
+ adding icons to the map.
+
* `rect `**`margins`** Relative margins that determine position of the
center on the map. Margins specify the relative active area of the
widget and the position of the active area. When given by a
@@ -184,20 +211,20 @@
resulting in a two-dimensional map. It is constrained at 60
degrees.
-* `real `**`pixelRatio`** Relative pixel density of the screen when compared
- to 96dpi. All the map elements will be scaled by this ratio when
- drawn. This allows to use the same style on the screens with the
- different pixel densities.
-
- Care should be taken when having `pixelRatio` different from one
- and using `metersPerPixel` to draw something on the map (such as
- uncertainty of position, for example). Since `metersPerPixel`
- gives the scale on the actual screen and all objects are scaled up
- by `pixelRatio`, you may have to reduce the drawn objects by
- `pixelRatio` when adding them on the map. For example, when
- drawing uncertainty of position as a circle around position, you
- would have to divide the radius of the circle by `pixelRatio` when
- modifying the circle radius by `setPaintProperty` method.
+* `real `**`pixelRatio`** Relative pixel density of the screen when
+ compared to 96dpi. All the map elements will be scaled by this
+ ratio when drawn. This allows to use the same style on the screens
+ with the different pixel densities and adjust the scale on
+ fly. Note that the minimal `pixelRatio` is set to
+ `devicePixelRatio` used at the map widget construction.
+
+ It is recommended to use this property for adjusting map overall
+ zoom for HiDPI cases. However, do not assume relationships between
+ Qt and map logical pixel sizes as it will depend on selected
+ implementation of the rendering and may change in future. Instead,
+ for adding custom elements through map styles, use the properties
+ made for such conversion: `mapToQtPixelRatio`, `metersPerPixel`,
+ `metersPerMapPixel`.
* `string `**`styleJson`** The map style in JSON given as a
string. Sets a new style from a JSON that must conform to the
@@ -248,8 +275,14 @@
`errorChanged` to trigger error processing and don't rely on
clearance of errorString property.
-* `real `**`metersPerPixel`** Meters per pixel at the center of the map
- given for the pixel density as specified by `pixelRatio`.
+* `real `**`metersPerPixel`** Meters per Qt logical pixel at the
+ center of the map.
+
+* `real `**`metersPerMapPixel`** Meters per map logical pixel at the
+ center of the map. Use this property when drawing objects on the map
+ that are specified in pixels, such as map style, and can be then
+ converted to meters. For example, when drawing location precision
+ with a circle by giving its radius in map pixels.
* `real `**`metersPerPixelTolerance`** Tolerance with which
`metersPerPixel` is updated.
@@ -296,16 +329,16 @@
specific method if it was deemed to be nearby:
```javascript
- // 15 pixels at 96dpi would correspond to 4 mm
- var nearby_lat = map.pixelRatio * 15 * degLatPerPixel;
- var nearby_lon = map.pixelRatio * 15 * degLonPerPixel;
-
- // check if its current position
- if ( Math.abs(coordinate.longitude - map.position.coordinate.longitude) < nearby_lon &&
- Math.abs(coordinate.latitude - map.position.coordinate.latitude) < nearby_lat ) {
- positionMarker.mouseClick();
- return;
- }
+ // 15 pixels at 96dpi would correspond to 4 mm
+ var nearby_lat = 15 * degLatPerPixel;
+ var nearby_lon = 15 * degLonPerPixel;
+
+ // check if its current position
+ if ( Math.abs(coordinate.longitude - map.position.coordinate.longitude) < nearby_lon &&
+ Math.abs(coordinate.latitude - map.position.coordinate.latitude) < nearby_lat ) {
+ positionMarker.mouseClick();
+ return;
+ }
```
@@ -334,7 +367,7 @@
in QML). For example, to fit Helsinki and Tallinn on a map, use
```javascript
map.fitView([QtPositioning.coordinate(60.170448, 24.942046),
- QtPositioning.coordinate(59.436962, 24.753574)])
+ QtPositioning.coordinate(59.436962, 24.753574)])
```
Optionally, it can fit the given list if `preserve` is set to `true`. This
@@ -398,68 +431,68 @@
The following QML snippet adds a point on the map
```javascript
- map.addSource("location",
- {"type": "geojson",
- "data": {
- "type": "Feature",
- "properties": { "name": "location" },
- "geometry": {
- "type": "Point",
- "coordinates": [
- (24.94),
- (60.16)
- ]
- }
- }
- })
+ map.addSource("location",
+ {"type": "geojson",
+ "data": {
+ "type": "Feature",
+ "properties": { "name": "location" },
+ "geometry": {
+ "type": "Point",
+ "coordinates": [
+ (24.94),
+ (60.16)
+ ]
+ }
+ }
|
[-]
[+]
|
Changed |
_service:tar_git:mapboxgl-qml-2.0.1.tar.gz/app/mapbox-qml.pro
^
|
@@ -7,16 +7,14 @@
RESOURCES += qml.qrc
-include(../mapbox-gl-qml.pri)
-
CONFIG += link_pkgconfig
PKGCONFIG += icu-uc icu-io
-#use_curl_ssl {
+use_curl_ssl {
CONFIG += link_pkgconfig
DEFINES += USE_CURL_SSL
PKGCONFIG += libcurl openssl
-#}
+}
LIBS += -lqmapboxgl -lz -lcrypto -ldl
|
[-]
[+]
|
Changed |
_service:tar_git:mapboxgl-qml-2.0.1.tar.gz/app/qml/main.qml
^
|
@@ -3,8 +3,7 @@
import QtQuick.Layouts 1.0
import QtPositioning 5.3
-import QQuickItemMapboxGL 1.0
-//import MapboxMap 1.0
+import MapboxMap 1.0
import "."
@@ -27,6 +26,7 @@
minimumZoomLevel: 0
maximumZoomLevel: 20
pixelRatio: 1.0
+ useFBO: true
bearing: bearingSlider.value
pitch: pitchSlider.value
@@ -87,8 +87,8 @@
property string styleUrlOrig: "http://localhost:8553/v1/mbgl/style?style=osmbright"
property int styleIndex: 0
- styleUrl: "mapbox://styles/mapbox/outdoors-v10" //"mapbox://styles/mapbox/streets-v10"
- //styleUrl: styleUrlOrig
+ //styleUrl: "mapbox://styles/mapbox/outdoors-v10" //"mapbox://styles/mapbox/streets-v10"
+ styleUrl: styleUrlOrig
urlDebug: true
|
[-]
[+]
|
Changed |
_service:tar_git:mapboxgl-qml-2.0.1.tar.gz/app/src/main.cpp
^
|
@@ -1,5 +1,3 @@
-#include "qquickitemmapboxgl.h"
-
#include <QGuiApplication>
#include <QQmlApplicationEngine>
@@ -7,8 +5,6 @@
{
QGuiApplication app(argc, argv);
- qmlRegisterType<QQuickItemMapboxGL>("QQuickItemMapboxGL", 1, 0, "MapboxMap");
-
QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:/qml/main.qml")));
|
[-]
[+]
|
Changed |
_service:tar_git:mapboxgl-qml-2.0.1.tar.gz/src/CMakeLists.txt
^
|
@@ -35,7 +35,8 @@
Qt5::Quick
Qt5::Positioning
Qt5::Sql
- qmapboxgl)
+ Qt5::Svg
+ QMapboxGL)
if(USE_CURL_SSL)
add_definitions(-DUSE_CURL_SSL=1)
@@ -44,7 +45,14 @@
PkgConfig::OPENSSL)
endif()
-FindQtInstallQml()
+if(USE_FBO)
+ add_definitions(-DUSE_FBO=1)
+endif()
+
+if(NOT DEFINED QT_INSTALL_QML)
+ FindQtInstallQml()
+ message(STATUS "Found QT_INSTALL_QML path: ${QT_INSTALL_QML}")
+endif()
install(FILES
plugin/MapboxMapGestureArea.qml
|
[-]
[+]
|
Changed |
_service:tar_git:mapboxgl-qml-2.0.1.tar.gz/src/include/qquickitemmapboxgl.h
^
|
@@ -83,14 +83,18 @@
Q_PROPERTY(qreal zoomLevel READ zoomLevel WRITE setZoomLevel NOTIFY zoomLevelChanged)
Q_PROPERTY(QRectF margins READ margins WRITE setMargins NOTIFY marginsChanged) /// see comments below on interpretation of RectF
+ Q_PROPERTY(qreal devicePixelRatio READ devicePixelRatio WRITE setDevicePixelRatio NOTIFY devicePixelRatioChanged)
Q_PROPERTY(qreal pixelRatio READ pixelRatio WRITE setPixelRatio NOTIFY pixelRatioChanged)
+ Q_PROPERTY(qreal mapToQtPixelRatio READ mapToQtPixelRatio NOTIFY mapToQtPixelRatioChanged)
Q_PROPERTY(QString styleJson READ styleJson WRITE setStyleJson NOTIFY styleJsonChanged)
Q_PROPERTY(QString styleUrl READ styleUrl WRITE setStyleUrl)
Q_PROPERTY(QString urlSuffix READ urlSuffix WRITE setUrlSuffix NOTIFY urlSuffixChanged)
Q_PROPERTY(bool urlDebug READ urlDebug WRITE setUrlDebug NOTIFY urlDebugChanged)
+ Q_PROPERTY(bool useFBO READ useFBO WRITE setUseFBO NOTIFY useFBOChanged)
/// tracks meters per pixel for the map center
Q_PROPERTY(qreal metersPerPixel READ metersPerPixel NOTIFY metersPerPixelChanged)
+ Q_PROPERTY(qreal metersPerMapPixel READ metersPerMapPixel NOTIFY metersPerPixelChanged)
Q_PROPERTY(qreal metersPerPixelTolerance READ metersPerPixelTolerance WRITE setMetersPerPixelTolerance NOTIFY metersPerPixelToleranceChanged)
// error
@@ -133,6 +137,7 @@
QGeoCoordinate center() const;
qreal metersPerPixel() const;
+ qreal metersPerMapPixel() const;
void setMetersPerPixelTolerance(qreal tol);
qreal metersPerPixelTolerance() const;
@@ -144,9 +149,14 @@
QString styleUrl() const;
void setStyleUrl(const QString &url);
+ void setDevicePixelRatio(qreal devicePixelRatio);
+ qreal devicePixelRatio() const;
+
void setPixelRatio(qreal pixelRatio);
qreal pixelRatio() const;
+ qreal mapToQtPixelRatio() const;
+
/// Settings related
QString accessToken() const;
void setAccessToken(const QString &token);
@@ -175,6 +185,9 @@
bool urlDebug() const;
void setUrlDebug(bool debug);
+ bool useFBO() const;
+ void setUseFBO(bool fbo);
+
bool gestureInProgress() const;
void setGestureInProgress(bool progress);
@@ -247,7 +260,7 @@
Q_INVOKABLE void removeLayer(const QString &id);
Q_INVOKABLE void addImage(const QString &name, const QImage &sprite);
- Q_INVOKABLE bool addImagePath(const QString &name, const QString &path); ///< Add image using image file path or url starting with file://
+ Q_INVOKABLE bool addImagePath(const QString &name, const QString &path, const int svgX=0, const int svgY=0); ///< Add image using image file path or url starting with file://
Q_INVOKABLE void removeImage(const QString &name);
Q_INVOKABLE void setLayoutProperty(const QString &layer, const QString &property, const QVariant &value);
@@ -278,11 +291,13 @@
void centerChanged(const QGeoCoordinate &coordinate);
void marginsChanged(const QMarginsF &margins);
+ void devicePixelRatioChanged(qreal devicePixelRatio);
void pixelRatioChanged(qreal pixelRatio);
void styleJsonChanged(QString json);
void styleUrlChanged(QString url);
void urlSuffixChanged(QString urlSuffix);
void urlDebugChanged(bool urlDebug);
+ void useFBOChanged(bool useFBO);
void errorChanged(QString error);
@@ -325,6 +340,7 @@
/// Tracking the state of the map
void metersPerPixelChanged(qreal metersPerPixel);
void metersPerPixelToleranceChanged(qreal metersPerPixelTolerance);
+ void mapToQtPixelRatioChanged(qreal mapToQtPixelRatio);
public slots:
void setCenter(const QGeoCoordinate ¢er);
@@ -341,8 +357,6 @@
void setError(QString error); ///< Set error string, used internally
-
-
private:
/// \brief Private class to track locations
@@ -366,6 +380,10 @@
private:
QMapboxGLSettings m_settings;
+ /// Signals that the first full init is done and setup-related
+ /// properties cannot be changed
+ bool m_first_init_done{false};
+
bool m_cache_default_path{false};
bool m_cache_store_settings{false};
@@ -381,6 +399,7 @@
QGeoCoordinate m_center;
double m_metersPerPixel = -1;
+ double m_metersPerMapPixel = -1;
double m_metersPerPixelTolerance = 1e-6;
qreal m_bearing = 0;
@@ -396,10 +415,13 @@
QString m_errorString;
- qreal m_pixelRatio;
+ qreal m_devicePixelRatio = 1;
+ qreal m_pixelRatio = 1;
+ qreal m_mapToQtPixelRatio = 1;
QString m_styleUrl;
QString m_styleJson;
bool m_useUrlForStyle = true;
+ bool m_useFBO = true;
QMutex m_resourceTransformMutex;
std::string m_urlSuffix;
|
[-]
[+]
|
Changed |
_service:tar_git:mapboxgl-qml-2.0.1.tar.gz/src/include/qsgmapboxglnode.h
^
|
@@ -43,6 +43,8 @@
#ifndef QSGMAPBOXGLNODE_H
#define QSGMAPBOXGLNODE_H
+#define HAS_SGRENDERNODE (QT_VERSION >= QT_VERSION_CHECK(5,8,0))
+
#include <QtQuick/QQuickWindow>
#include <QtQuick/QSGSimpleTextureNode>
#include <QtGui/QOpenGLFramebufferObject>
@@ -51,33 +53,74 @@
#include <QMapboxGL>
-class QSGMapboxGLTextureNode : public QObject, public QSGSimpleTextureNode
+class QSGMapboxGLAbstractNode : public QObject
{
Q_OBJECT
public:
- QSGMapboxGLTextureNode(const QMapboxGLSettings &, const QSize &, qreal pixelRatio, QQuickItem *item);
- ~QSGMapboxGLTextureNode();
+ QSGMapboxGLAbstractNode(const QMapboxGLSettings &, const QSize &, qreal devicePixelRatio, qreal pixelRatio, QQuickItem *item);
- QMapboxGL* map() const { return m_map.data(); }
+ QMapboxGL* map() const { return m_map.data(); }
+ float height() const { return m_map_size.height(); }
+ float width() const { return m_map_size.width(); }
+ float mapToQtPixelRatio() const;
- void resize(const QSize &size, qreal pixelRatio);
- bool render(QQuickWindow *);
+ virtual void resize(const QSize &size, qreal pixelRatio);
+ virtual void render(QQuickWindow *) {}
public slots:
- void querySourceExists(const QString &id);
- void queryLayerExists(const QString &id);
- void queryCoordinateForPixel(QPointF p, const QVariant &tag);
+ void querySourceExists(const QString &id);
+ void queryLayerExists(const QString &id);
+ void queryCoordinateForPixel(QPointF p, const QVariant &tag);
signals:
- void replySourceExists(const QString id, bool exists);
- void replyLayerExists(const QString id, bool exists);
- void replyCoordinateForPixel(const QPointF p, QGeoCoordinate geo, qreal degLatPerPixel, qreal degLonPerPixel, const QVariant &tag);
+ void replySourceExists(const QString id, bool exists);
+ void replyLayerExists(const QString id, bool exists);
+ void replyCoordinateForPixel(const QPointF p, QGeoCoordinate geo, qreal degLatPerPixel, qreal degLonPerPixel, const QVariant &tag);
+
+protected:
+ QScopedPointer<QMapboxGL> m_map;
+ QSize m_map_size; ///<- size as set for map
+ QSize m_item_size; ///<- size of Qt item in Qt logical pixels units
+ qreal m_pixel_ratio;
+ qreal m_device_pixel_ratio{1};
+};
+
+class QSGMapboxGLTextureNode : public QSGMapboxGLAbstractNode, public QSGSimpleTextureNode
+{
+ Q_OBJECT
+
+public:
+ QSGMapboxGLTextureNode(const QMapboxGLSettings &, const QSize &, qreal devicePixelRatio, qreal pixelRatio, QQuickItem *item);
+ ~QSGMapboxGLTextureNode();
+
+ QMapboxGL* map() const { return m_map.data(); }
+
+ void resize(const QSize &size, qreal pixelRatio) override;
+ void render(QQuickWindow *) override;
private:
- QScopedPointer<QMapboxGL> m_map;
- QScopedPointer<QOpenGLFramebufferObject> m_fbo;
- qreal m_pixel_ratio;
+ QScopedPointer<QOpenGLFramebufferObject> m_fbo;
+};
+
+#if HAS_SGRENDERNODE
+#include <QSGRenderNode>
+
+class QSGMapboxGLRenderNode : public QSGMapboxGLAbstractNode, public QSGRenderNode
+{
+ Q_OBJECT
+
+public:
+ QSGMapboxGLRenderNode(const QMapboxGLSettings &, const QSize &, qreal devicePixelRatio, qreal pixelRatio, QQuickItem *item);
+
+ QMapboxGL* map() const;
+
+ void resize(const QSize &size, qreal pixelRatio);
+
+ // QSGRenderNode
+ void render(const RenderState *state) override;
+ StateFlags changedStates() const override;
};
+#endif
#endif // QSGMAPBOXGLNODE_H
|
[-]
[+]
|
Changed |
_service:tar_git:mapboxgl-qml-2.0.1.tar.gz/src/qquickitemmapboxgl.cpp
^
|
@@ -46,16 +46,20 @@
#include <mbgl/util/constants.hpp>
-#include <QCoreApplication>
+#include <QGuiApplication>
#include <QDir>
#include <QFileInfo>
+#include <QFont>
#include <QJsonDocument>
#include <QMutexLocker>
+#include <QScreen>
#include <QSettings>
#include <QStandardPaths>
#include <QSqlDatabase>
#include <QSqlError>
#include <QSqlQuery>
+#include <QSvgRenderer>
+#include <QPainter>
#include <QVariantMap>
#include <math.h>
@@ -122,17 +126,38 @@
QQuickItem(parent),
m_margins(0, 0, 0, 0)
{
+#if HAS_SGRENDERNODE
+#ifndef USE_FBO
+ m_useFBO = false;
+#else
+ m_useFBO = true;
+#endif
+#endif
+
setFlag(ItemHasContents);
- m_styleUrl = QMapbox::defaultStyles()[0].first;
+ m_styleUrl = QStringLiteral("mapbox://styles/mapbox/streets-v10");
m_styleJson = QString(); // empty
m_settings.setViewportMode(QMapboxGLSettings::DefaultViewport);
+ QFont font;
+ font.setStyleHint(QFont::SansSerif);
+ m_settings.setLocalFontFamily(font.defaultFamily());
+
+ m_settings.resetToTemplate(QMapboxGLSettings::MapboxSettings);
+
m_settings.setResourceTransform(std::bind(&QQuickItemMapboxGL::resourceTransform,
this, std::placeholders::_1));
- m_pixelRatio = 1;
+ QScreen *screen = (parent && parent->window() && parent->window()->screen()) ?
+ parent->window()->screen() : QGuiApplication::primaryScreen();
+ if (screen)
+ m_devicePixelRatio = screen->devicePixelRatio();
+ else
+ m_devicePixelRatio = -1;
+
+ m_pixelRatio = m_devicePixelRatio;
m_timer.setInterval(250);
connect(&m_timer, &QTimer::timeout, this, &QQuickItemMapboxGL::update);
@@ -164,7 +189,7 @@
QVariantList QQuickItemMapboxGL::defaultStyles() const
{
QVariantList array;
- auto styles = QMapbox::defaultStyles();
+ auto styles = m_settings.defaultStyles();
for (const auto &i: styles)
{
QVariantMap o;
@@ -179,12 +204,12 @@
/// Properties that have to be set during construction of the map
QString QQuickItemMapboxGL::accessToken() const
{
- return m_settings.accessToken();
+ return m_settings.apiKey();
}
void QQuickItemMapboxGL::setAccessToken(const QString &token)
{
- m_settings.setAccessToken(token);
+ m_settings.setApiKey(token);
emit accessTokenChanged(accessToken());
}
@@ -290,6 +315,25 @@
if (old != s) emit cacheDatabaseStoreSettingsChanged(s);
}
+bool QQuickItemMapboxGL::useFBO() const
+{
+ return m_useFBO;
+}
+
+void QQuickItemMapboxGL::setUseFBO(bool fbo)
+{
+ if (m_first_init_done)
+ {
+ qWarning() << "Use FBO cannot be changed after the initialization of the map. Set it at creation of the widget";
+ return;
+ }
+
+#if HAS_SGRENDERNODE
+ m_useFBO = fbo;
+#endif
+ emit useFBOChanged(fbo);
+}
+
/// Error feedback
QString QQuickItemMapboxGL::errorString() const
{
@@ -446,6 +490,11 @@
return m_metersPerPixel;
}
+qreal QQuickItemMapboxGL::metersPerMapPixel() const
+{
+ return m_metersPerMapPixel;
+}
+
void QQuickItemMapboxGL::setMetersPerPixelTolerance(qreal tol)
{
m_metersPerPixelTolerance = tol;
@@ -487,6 +536,9 @@
void QQuickItemMapboxGL::setMargins(qreal left, qreal top, qreal right, qreal bottom)
{
+ if (!finite(left) || !finite(top) || !finite(right) || !finite(bottom))
+ return;
+
m_margins.setLeft(left);
m_margins.setTop(top);
m_margins.setRight(right);
@@ -523,6 +575,9 @@
void QQuickItemMapboxGL::setMargins(const QRectF &margins_box)
{
+ if (!finite(margins_box.bottom()) || !finite(margins_box.left()) ||
+ !finite(margins_box.width()) || !finite(margins_box.height()))
+ return;
QMarginsF margins = qrect2qmargins(margins_box);
m_margins = margins;
m_syncState |= MarginsNeedSync;
@@ -531,6 +586,26 @@
}
/// Rendering details
+qreal QQuickItemMapboxGL::devicePixelRatio() const
+{
+ return m_devicePixelRatio > 0 ? m_devicePixelRatio : 1;
+}
+
+void QQuickItemMapboxGL::setDevicePixelRatio(qreal devicePixelRatio)
+{
+ if (m_first_init_done)
+ {
+ qWarning() << "DevicePixelRatio cannot be changed after the initialization of the map. Set it at creation of the widget";
+ return;
+ }
+
+ m_devicePixelRatio = qMax((qreal)1.0, devicePixelRatio);
+ m_syncState |= PixelRatioNeedsSync;
+ if (m_pixelRatio < m_devicePixelRatio) setPixelRatio(m_devicePixelRatio);
+ update();
+ emit devicePixelRatioChanged(m_devicePixelRatio);
+}
+
qreal QQuickItemMapboxGL::pixelRatio() const
{
return m_pixelRatio;
@@ -538,12 +613,17 @@
void QQuickItemMapboxGL::setPixelRatio(qreal pixelRatio)
{
- m_pixelRatio = qMax((qreal)1.0, pixelRatio);
+ m_pixelRatio = qMax(m_devicePixelRatio, pixelRatio);
m_syncState |= PixelRatioNeedsSync;
update();
emit pixelRatioChanged(m_pixelRatio);
}
+qreal QQuickItemMapboxGL::mapToQtPixelRatio() const
+{
+ return m_mapToQtPixelRatio;
+}
+
QString QQuickItemMapboxGL::styleJson() const
{
return m_styleJson;
@@ -750,7 +830,8 @@
m_images.add(name, sprite); DATA_UPDATE;
}
-bool QQuickItemMapboxGL::addImagePath(const QString &name, const QString &path)
+bool QQuickItemMapboxGL::addImagePath(const QString &name, const QString &path,
+ const int svgX, const int svgY)
{
QString p;
|
[-]
[+]
|
Changed |
_service:tar_git:mapboxgl-qml-2.0.1.tar.gz/src/qsgmapboxglnode.cpp
^
|
@@ -2,6 +2,7 @@
**
** Based on the implementation of Mapbox GL Native QtLocation plugin at
** https://github.com/qt/qtlocation/tree/5.9/src/plugins/geoservices/mapboxgl
+** and later versions. Developed further for integration with the plugin
**
** The original code license is below
**
@@ -50,19 +51,85 @@
#include <QDebug>
-static const QSize minTextureSize = QSize(64, 64);
+static const QSize minTextureSize = QSize(16, 16);
+////////////////////////////////////////////
+/// QSGMapboxGLAbstractNode
-QSGMapboxGLTextureNode::QSGMapboxGLTextureNode(const QMapboxGLSettings &settings, const QSize &size, qreal pixelRatio, QQuickItem *item)
- : QObject(), QSGSimpleTextureNode(), m_pixel_ratio(pixelRatio)
+QSGMapboxGLAbstractNode::QSGMapboxGLAbstractNode(const QMapboxGLSettings &settings, const QSize &size,
+ qreal devicePixelRatio, qreal pixelRatio, QQuickItem *item):
+ QObject(), m_map_size(size), m_item_size(size),
+ m_device_pixel_ratio(devicePixelRatio), m_pixel_ratio(pixelRatio)
{
- setTextureCoordinatesTransform(QSGSimpleTextureNode::MirrorVertically);
- setFiltering(QSGTexture::Linear);
-
m_map.reset(new QMapboxGL(nullptr, settings, size.expandedTo(minTextureSize), pixelRatio));
QObject::connect(m_map.data(), &QMapboxGL::needsRendering, item, &QQuickItem::update);
QObject::connect(m_map.data(), &QMapboxGL::copyrightsChanged, item, &QQuickItem::update);
+}
+
+void QSGMapboxGLAbstractNode::resize(const QSize &size, qreal pixelRatio)
+{
+ m_item_size = size;
+ m_pixel_ratio = pixelRatio;
+}
+
+float QSGMapboxGLAbstractNode::mapToQtPixelRatio() const
+{
+ return 0.5 * (width()/m_item_size.width() +
+ height()/m_item_size.height());
+}
+
+///////////////////////////////////
+/// queries
+
+void QSGMapboxGLAbstractNode::querySourceExists(const QString &sourceID)
+{
+ emit replySourceExists(sourceID, m_map->sourceExists(sourceID));
+}
+
+void QSGMapboxGLAbstractNode::queryLayerExists(const QString &sourceID)
+{
+ emit replyLayerExists(sourceID, m_map->layerExists(sourceID));
+}
+
+void QSGMapboxGLAbstractNode::queryCoordinateForPixel(QPointF p, const QVariant &tag)
+{
+ float rx = ((float)m_map_size.width()) / ((float)m_item_size.width());
+ float ry = ((float)m_map_size.height()) / ((float)m_item_size.height());
+
+ p.setX(p.x() * rx);
+ p.setY(p.y() * ry);
+ QMapbox::Coordinate mbc = m_map->coordinateForPixel(p);
+ QGeoCoordinate coor(mbc.first, mbc.second);
+
+ // get sensitivity of coordinates to the changes in pixel coordinates
+ double bearing = m_map->bearing() / 180. * M_PI;
+ double sinB = sin(bearing);
+ double cosB = cos(bearing);
+ p += QPointF(cosB + sinB, -sinB + cosB);
+ QMapbox::Coordinate mbc_shift = m_map->coordinateForPixel(p);
+
+ qreal degLatPerPixel = fabs(mbc_shift.first - mbc.first) * rx;
+ qreal degLonPerPixel = fabs(mbc_shift.second - mbc.second) * ry;
+
+ emit replyCoordinateForPixel(p, coor, degLatPerPixel, degLonPerPixel, tag);
+}
+
+
+////////////////////////////////////////////
+/// QSGMapboxGLTextureNode
+
+QSGMapboxGLTextureNode::QSGMapboxGLTextureNode(const QMapboxGLSettings &settings, const QSize &size,
+ qreal devicePixelRatio,
+ qreal pixelRatio, QQuickItem *item)
+ : QSGMapboxGLAbstractNode(settings, size, devicePixelRatio, pixelRatio, item),
+ QSGSimpleTextureNode()
+{
+ qInfo() << "Using QSGMapboxGLTextureNode for map rendering."
+ << "devicePixelRatio:" << devicePixelRatio;
+
+ setTextureCoordinatesTransform(QSGSimpleTextureNode::MirrorVertically);
+ setFiltering(QSGTexture::Linear);
resize(size, pixelRatio); // to fill and attach fbo
}
@@ -73,14 +140,16 @@
void QSGMapboxGLTextureNode::resize(const QSize &size, qreal pixelRatio)
{
- const QSize& minSize = size.expandedTo(minTextureSize);
- const QSize fbSize = minSize;
+ const QSize minSize = size.expandedTo(minTextureSize);
+ QSGMapboxGLAbstractNode::resize(minSize, pixelRatio);
- m_pixel_ratio = pixelRatio;
- m_map->resize(minSize / pixelRatio);
+ const QSize fbSize = minSize * m_device_pixel_ratio; // physical pixels
+ m_map_size = minSize * m_device_pixel_ratio / m_pixel_ratio; // ensure zoom
+
+ m_map->resize(m_map_size);
m_fbo.reset(new QOpenGLFramebufferObject(fbSize, QOpenGLFramebufferObject::CombinedDepthStencil));
- m_map->setFramebufferObject(m_fbo->handle(), minSize);
+ m_map->setFramebufferObject(m_fbo->handle(), fbSize); //minSize);
QSGTexturePlain *fboTexture = static_cast<QSGTexturePlain *>(texture());
if (!fboTexture)
@@ -95,12 +164,10 @@
}
setRect(QRectF(QPointF(), minSize));
- markDirty(QSGNode::DirtyGeometry);
}
-bool QSGMapboxGLTextureNode::render(QQuickWindow *window)
+void QSGMapboxGLTextureNode::render(QQuickWindow *window)
{
- bool loaded = m_map->isFullyLoaded();
QOpenGLFunctions *f = window->openglContext()->functions();
f->glViewport(0, 0, m_fbo->width(), m_fbo->height());
@@ -117,39 +184,55 @@
f->glDepthRangef(0, 1);
window->resetOpenGLState();
- markDirty(QSGNode::DirtyMaterial);
-
- return loaded;
}
-///////////////////////////////////
-/// queries
+#if HAS_SGRENDERNODE
+////////////////////////////////////////////
+/// QSGMapboxGLRenderNode
-void QSGMapboxGLTextureNode::querySourceExists(const QString &sourceID)
+QSGMapboxGLRenderNode::QSGMapboxGLRenderNode(const QMapboxGLSettings &settings, const QSize &size,
+ qreal devicePixelRatio, qreal pixelRatio, QQuickItem *item)
+ : QSGMapboxGLAbstractNode(settings, size, devicePixelRatio, pixelRatio, item)
{
- emit replySourceExists(sourceID, m_map->sourceExists(sourceID));
+ qInfo() << "Using QSGMapboxGLRenderNode for map rendering. "
+ << "devicePixelRatio:" << devicePixelRatio;
}
-void QSGMapboxGLTextureNode::queryLayerExists(const QString &sourceID)
+void QSGMapboxGLRenderNode::resize(const QSize &size, qreal pixelRatio)
{
- emit replyLayerExists(sourceID, m_map->layerExists(sourceID));
+ const QSize minSize = size.expandedTo(minTextureSize);
+ QSGMapboxGLAbstractNode::resize(size, pixelRatio);
+ m_map_size = minSize / pixelRatio;
+ m_map->resize(m_map_size);
}
-void QSGMapboxGLTextureNode::queryCoordinateForPixel(QPointF p, const QVariant &tag)
+void QSGMapboxGLRenderNode::render(const RenderState *state)
{
- p /= m_pixel_ratio;
- QMapbox::Coordinate mbc = m_map->coordinateForPixel(p);
- QGeoCoordinate coor(mbc.first, mbc.second);
+ // QMapboxGL assumes we've prepared the viewport prior to render().
+ QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions();
+ f->glViewport(state->scissorRect().x(), state->scissorRect().y(), state->scissorRect().width(), state->scissorRect().height());
+ f->glScissor(state->scissorRect().x(), state->scissorRect().y(), state->scissorRect().width(), state->scissorRect().height());
+ f->glEnable(GL_SCISSOR_TEST);
- // get sensitivity of coordinates to the changes in pixel coordinates
- double bearing = m_map->bearing() / 180. * M_PI;
- double sinB = sin(bearing);
- double cosB = cos(bearing);
- p += QPointF(cosB + sinB, -sinB + cosB);
- QMapbox::Coordinate mbc_shift = m_map->coordinateForPixel(p);
+ GLint alignment;
+ f->glGetIntegerv(GL_UNPACK_ALIGNMENT, &alignment);
- qreal degLatPerPixel = fabs(mbc_shift.first - mbc.first) / m_pixel_ratio;
- qreal degLonPerPixel = fabs(mbc_shift.second - mbc.second) / m_pixel_ratio;
+ m_map->render();
- emit replyCoordinateForPixel(p, coor, degLatPerPixel, degLonPerPixel, tag);
+ // QTBUG-62861
+ f->glPixelStorei(GL_UNPACK_ALIGNMENT, alignment);
+ f->glDepthRangef(0, 1);
|