summaryrefslogtreecommitdiff
path: root/platform
diff options
context:
space:
mode:
authorThiago Marcos P. Santos <thiago@mapbox.com>2016-02-03 17:20:26 +0200
committerThiago Marcos P. Santos <thiago@mapbox.com>2016-04-20 20:55:51 +0300
commite974dd282d3337856fd1a83e76878e1ff6ce1bf1 (patch)
tree1cc0b12c4339956a850bfb1774d0871639c78cb5 /platform
parent19e11293676db729909e10659f3e0710a251a03b (diff)
downloadqtlocation-mapboxgl-e974dd282d3337856fd1a83e76878e1ff6ce1bf1.tar.gz
[Qt] Add function for get coordinates and zoom based on a bounding box
Diffstat (limited to 'platform')
-rw-r--r--platform/qt/include/qmapbox.hpp2
-rw-r--r--platform/qt/include/qmapboxgl.hpp3
-rw-r--r--platform/qt/src/qmapboxgl.cpp30
3 files changed, 35 insertions, 0 deletions
diff --git a/platform/qt/include/qmapbox.hpp b/platform/qt/include/qmapbox.hpp
index 8877d730bb..fc52218bb2 100644
--- a/platform/qt/include/qmapbox.hpp
+++ b/platform/qt/include/qmapbox.hpp
@@ -13,6 +13,8 @@ typedef QPair<double, double> Coordinate;
typedef QList<Coordinate> Coordinates;
typedef QList<Coordinates> CoordinateSegments;
+typedef QPair<Coordinate, double> CoordinateZoom;
+
typedef quint32 AnnotationID;
typedef QList<AnnotationID> AnnotationIDs;
diff --git a/platform/qt/include/qmapboxgl.hpp b/platform/qt/include/qmapboxgl.hpp
index 01538268d7..f3e0af98ea 100644
--- a/platform/qt/include/qmapboxgl.hpp
+++ b/platform/qt/include/qmapboxgl.hpp
@@ -158,6 +158,9 @@ public:
QPointF pixelForCoordinate(const QMapbox::Coordinate &) const;
QMapbox::Coordinate coordinateForPixel(const QPointF &) const;
+ QMapbox::CoordinateZoom coordinateZoomForBounds(const QMapbox::Coordinate &sw, QMapbox::Coordinate &ne) const;
+ QMapbox::CoordinateZoom coordinateZoomForBounds(const QMapbox::Coordinate &sw, QMapbox::Coordinate &ne, double bearing, double pitch);
+
void setMargins(const QMargins &margins);
QMargins margins() const;
diff --git a/platform/qt/src/qmapboxgl.cpp b/platform/qt/src/qmapboxgl.cpp
index ed6f8566a1..e7752df292 100644
--- a/platform/qt/src/qmapboxgl.cpp
+++ b/platform/qt/src/qmapboxgl.cpp
@@ -3,6 +3,7 @@
#include <mbgl/annotation/point_annotation.hpp>
#include <mbgl/annotation/shape_annotation.hpp>
#include <mbgl/gl/gl.hpp>
+#include <mbgl/map/camera.hpp>
#include <mbgl/map/map.hpp>
#include <mbgl/sprite/sprite_image.hpp>
#include <mbgl/storage/network_status.hpp>
@@ -460,6 +461,35 @@ Coordinate QMapboxGL::coordinateForPixel(const QPointF &pixel) const
return Coordinate(latLng.latitude, latLng.longitude);
}
+CoordinateZoom QMapboxGL::coordinateZoomForBounds(const Coordinate &sw, Coordinate &ne) const
+{
+ auto bounds = mbgl::LatLngBounds::hull(mbgl::LatLng { sw.first, sw.second }, mbgl::LatLng { ne.first, ne.second });
+ mbgl::CameraOptions camera = d_ptr->mapObj->cameraForLatLngBounds(bounds, d_ptr->margins);
+
+ return {{ (*camera.center).latitude, (*camera.center).longitude }, *camera.zoom };
+}
+
+CoordinateZoom QMapboxGL::coordinateZoomForBounds(const Coordinate &sw, Coordinate &ne,
+ double newBearing, double newPitch)
+{
+ // FIXME: mbgl::Map::cameraForLatLngBounds should
+ // take bearing and pitch as input too, so this
+ // hack won't be needed.
+ double currentBearing = bearing();
+ double currentPitch = pitch();
+
+ setBearing(newBearing);
+ setPitch(newPitch);
+
+ auto bounds = mbgl::LatLngBounds::hull(mbgl::LatLng { sw.first, sw.second }, mbgl::LatLng { ne.first, ne.second });
+ mbgl::CameraOptions camera = d_ptr->mapObj->cameraForLatLngBounds(bounds, d_ptr->margins);
+
+ setBearing(currentBearing);
+ setPitch(currentPitch);
+
+ return {{ (*camera.center).latitude, (*camera.center).longitude }, *camera.zoom };
+}
+
void QMapboxGL::setMargins(const QMargins &margins_)
{
d_ptr->margins = {