summaryrefslogtreecommitdiff
path: root/platform/qt
diff options
context:
space:
mode:
authorxylosper <darklin20@gmail.com>2019-02-12 11:18:50 +0900
committerThiago Marcos P. Santos <tmpsantos@gmail.com>2019-02-12 11:08:26 +0200
commit26af7265c3e995fb5d09fc5f7e13dd73ae4660b3 (patch)
tree26927d381583a634a660701cbae5a6397cd14cd6 /platform/qt
parent2deebc0efe58778d42a021b817f31535ca00016d (diff)
downloadqtlocation-mapboxgl-26af7265c3e995fb5d09fc5f7e13dd73ae4660b3.tar.gz
[qt] add global projection functions
There are 3 methods in QMapboxGL which can be static method. QMapboxGL::metersPerPixelAtLatitude QMapboxGL::projectedMetersForCoordinate QMapboxGL::coordinateForProjectedMeters Add these functions into QMapbox namespace as global functions. The methods in QMapboxGL are kept for backward compatibility.
Diffstat (limited to 'platform/qt')
-rw-r--r--platform/qt/include/qmapbox.hpp4
-rw-r--r--platform/qt/src/qmapbox.cpp27
-rw-r--r--platform/qt/src/qmapboxgl.cpp8
3 files changed, 34 insertions, 5 deletions
diff --git a/platform/qt/include/qmapbox.hpp b/platform/qt/include/qmapbox.hpp
index c1fbf52ae8..475c591de0 100644
--- a/platform/qt/include/qmapbox.hpp
+++ b/platform/qt/include/qmapbox.hpp
@@ -127,6 +127,10 @@ public:
virtual void deinitialize() = 0;
};
+double metersPerPixelAtLatitude(double latitude, double zoom);
+ProjectedMeters projectedMetersForCoordinate(const Coordinate &);
+Coordinate coordinateForProjectedMeters(const ProjectedMeters &);
+
} // namespace QMapbox
Q_DECLARE_METATYPE(QMapbox::Coordinate);
diff --git a/platform/qt/src/qmapbox.cpp b/platform/qt/src/qmapbox.cpp
index d0f80818c7..34cb5e86bc 100644
--- a/platform/qt/src/qmapbox.cpp
+++ b/platform/qt/src/qmapbox.cpp
@@ -4,6 +4,7 @@
#include <mbgl/util/default_styles.hpp>
#include <mbgl/util/geometry.hpp>
#include <mbgl/util/traits.hpp>
+#include <mbgl/util/projection.hpp>
#include <QOpenGLContext>
@@ -222,4 +223,30 @@ QVector<QPair<QString, QString> >& defaultStyles()
return styles;
}
+/*!
+ 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
diff --git a/platform/qt/src/qmapboxgl.cpp b/platform/qt/src/qmapboxgl.cpp
index e430912efb..721bba8ff0 100644
--- a/platform/qt/src/qmapboxgl.cpp
+++ b/platform/qt/src/qmapboxgl.cpp
@@ -1169,7 +1169,7 @@ void QMapboxGL::addAnnotationIcon(const QString &name, const QImage &icon)
*/
double QMapboxGL::metersPerPixelAtLatitude(double latitude_, double zoom_) const
{
- return mbgl::Projection::getMetersPerPixelAtLatitude(latitude_, zoom_);
+ return QMapbox::metersPerPixelAtLatitude(latitude_, zoom_);
}
/*!
@@ -1177,8 +1177,7 @@ double QMapboxGL::metersPerPixelAtLatitude(double latitude_, double zoom_) const
*/
QMapbox::ProjectedMeters QMapboxGL::projectedMetersForCoordinate(const QMapbox::Coordinate &coordinate_) const
{
- auto projectedMeters = mbgl::Projection::projectedMetersForLatLng(mbgl::LatLng { coordinate_.first, coordinate_.second });
- return QMapbox::ProjectedMeters(projectedMeters.northing(), projectedMeters.easting());
+ return QMapbox::projectedMetersForCoordinate(coordinate_);
}
/*!
@@ -1186,8 +1185,7 @@ QMapbox::ProjectedMeters QMapboxGL::projectedMetersForCoordinate(const QMapbox::
*/
QMapbox::Coordinate QMapboxGL::coordinateForProjectedMeters(const QMapbox::ProjectedMeters &projectedMeters) const
{
- auto latLng = mbgl::Projection::latLngForProjectedMeters(mbgl::ProjectedMeters { projectedMeters.first, projectedMeters.second });
- return QMapbox::Coordinate(latLng.latitude(), latLng.longitude());
+ return QMapbox::coordinateForProjectedMeters(projectedMeters);
}
/*!