summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruno de Oliveira Abinader <bruno@mapbox.com>2016-03-17 14:08:16 +0200
committerThiago Marcos P. Santos <thiago@mapbox.com>2016-04-20 20:55:51 +0300
commitfa6421a56f74ae623766c2fbb12cf76b94e2a1fd (patch)
treed46ad11b4fcfbbcd89205ea682b9d2d65bd12cd7
parent459e72d72a89adb496757260b9ee90fc1b501bef (diff)
downloadqtlocation-mapboxgl-fa6421a56f74ae623766c2fbb12cf76b94e2a1fd.tar.gz
[Qt] Implement QMapboxGL::jumpTo
-rw-r--r--platform/qt/include/qmapbox.hpp11
-rw-r--r--platform/qt/include/qmapboxgl.hpp2
-rw-r--r--platform/qt/src/qmapboxgl.cpp27
3 files changed, 40 insertions, 0 deletions
diff --git a/platform/qt/include/qmapbox.hpp b/platform/qt/include/qmapbox.hpp
index fe7c749e51..d9a9f37f30 100644
--- a/platform/qt/include/qmapbox.hpp
+++ b/platform/qt/include/qmapbox.hpp
@@ -3,6 +3,7 @@
#include <QList>
#include <QPair>
+#include <QVariant>
#include <QString>
// This header follows the Qt coding style: https://wiki.qt.io/Qt_Coding_Style
@@ -30,9 +31,19 @@ enum NetworkMode {
Offline,
};
+struct Q_DECL_EXPORT CameraOptions {
+ QVariant center; // Coordinate
+ QVariant anchor; // QPointF
+ QVariant zoom; // double
+ QVariant angle; // double
+ QVariant pitch; // double
+};
+
Q_DECL_EXPORT NetworkMode networkMode();
Q_DECL_EXPORT void setNetworkMode(NetworkMode);
}
+Q_DECLARE_METATYPE(QMapbox::Coordinate);
+
#endif // QMAPBOX_H
diff --git a/platform/qt/include/qmapboxgl.hpp b/platform/qt/include/qmapboxgl.hpp
index f3e0af98ea..866aa29cee 100644
--- a/platform/qt/include/qmapboxgl.hpp
+++ b/platform/qt/include/qmapboxgl.hpp
@@ -125,6 +125,8 @@ public:
void setCoordinate(const QMapbox::Coordinate &);
void setCoordinateZoom(const QMapbox::Coordinate &, double zoom);
+ void jumpTo(const QMapbox::CameraOptions&);
+
void setGestureInProgress(bool inProgress);
void addClass(const QString &);
diff --git a/platform/qt/src/qmapboxgl.cpp b/platform/qt/src/qmapboxgl.cpp
index e7752df292..479f348d93 100644
--- a/platform/qt/src/qmapboxgl.cpp
+++ b/platform/qt/src/qmapboxgl.cpp
@@ -7,6 +7,7 @@
#include <mbgl/map/map.hpp>
#include <mbgl/sprite/sprite_image.hpp>
#include <mbgl/storage/network_status.hpp>
+#include <mbgl/util/constants.hpp>
#include <mbgl/util/geo.hpp>
#include <mbgl/util/vec.hpp>
@@ -209,6 +210,32 @@ void QMapboxGL::setCoordinateZoom(const Coordinate &coordinate_, double zoom_)
mbgl::LatLng { coordinate_.first, coordinate_.second }, zoom_, d_ptr->margins);
}
+void QMapboxGL::jumpTo(const CameraOptions& camera)
+{
+ mbgl::CameraOptions mbglCamera;
+ if (camera.center.isValid()) {
+ const Coordinate center = camera.center.value<Coordinate>();
+ mbglCamera.center = mbgl::LatLng { center.first, center.second };
+ }
+ if (camera.anchor.isValid()) {
+ const QPointF anchor = camera.anchor.value<QPointF>();
+ mbglCamera.anchor = mbgl::ScreenCoordinate { anchor.x(), anchor.y() };
+ }
+ if (camera.zoom.isValid()) {
+ mbglCamera.zoom = camera.zoom.value<double>();
+ }
+ if (camera.angle.isValid()) {
+ mbglCamera.angle = -camera.angle.value<double>() * mbgl::util::DEG2RAD;
+ }
+ if (camera.pitch.isValid()) {
+ mbglCamera.pitch = camera.pitch.value<double>() * mbgl::util::DEG2RAD;
+ }
+
+ mbglCamera.padding = d_ptr->margins;
+
+ d_ptr->mapObj->jumpTo(mbglCamera);
+}
+
double QMapboxGL::bearing() const
{
return d_ptr->mapObj->getBearing();