[Qt] Implement QMapboxGL::jumpTo
This commit is contained in:
committed by
Thiago Marcos P. Santos
parent
459e72d72a
commit
fa6421a56f
@@ -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
|
||||
|
||||
@@ -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 &);
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user