[Qt] Add function for get coordinates and zoom based on a bounding box
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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 = {
|
||||
|
||||
Reference in New Issue
Block a user