[Qt] Add support for margins
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
#include <QPointF>
|
||||
|
||||
class QImage;
|
||||
class QMargins;
|
||||
class QSize;
|
||||
class QString;
|
||||
class QStringList;
|
||||
@@ -170,6 +171,9 @@ public:
|
||||
QPointF pixelForCoordinate(const Coordinate &) const;
|
||||
Coordinate coordinateForPixel(const QPointF &) const;
|
||||
|
||||
void setMargins(const QMargins &margins);
|
||||
QMargins margins() const;
|
||||
|
||||
public slots:
|
||||
void render();
|
||||
void connectionEstablished();
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include <QCoreApplication>
|
||||
#include <QImage>
|
||||
#include <QMapboxGL>
|
||||
#include <QMargins>
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
|
||||
@@ -140,22 +141,22 @@ void QMapboxGL::setStyleURL(const QString &url)
|
||||
|
||||
double QMapboxGL::latitude() const
|
||||
{
|
||||
return d_ptr->mapObj->getLatLng().latitude;
|
||||
return d_ptr->mapObj->getLatLng(d_ptr->margins).latitude;
|
||||
}
|
||||
|
||||
void QMapboxGL::setLatitude(double latitude_)
|
||||
{
|
||||
d_ptr->mapObj->setLatLng(mbgl::LatLng { latitude_, longitude() });
|
||||
d_ptr->mapObj->setLatLng(mbgl::LatLng { latitude_, longitude() }, d_ptr->margins);
|
||||
}
|
||||
|
||||
double QMapboxGL::longitude() const
|
||||
{
|
||||
return d_ptr->mapObj->getLatLng().longitude;
|
||||
return d_ptr->mapObj->getLatLng(d_ptr->margins).longitude;
|
||||
}
|
||||
|
||||
void QMapboxGL::setLongitude(double longitude_)
|
||||
{
|
||||
d_ptr->mapObj->setLatLng(mbgl::LatLng { latitude(), longitude_ });
|
||||
d_ptr->mapObj->setLatLng(mbgl::LatLng { latitude(), longitude_ }, d_ptr->margins);
|
||||
}
|
||||
|
||||
double QMapboxGL::scale() const
|
||||
@@ -175,7 +176,7 @@ double QMapboxGL::zoom() const
|
||||
|
||||
void QMapboxGL::setZoom(double zoom_)
|
||||
{
|
||||
d_ptr->mapObj->setZoom(zoom_);
|
||||
d_ptr->mapObj->setZoom(zoom_, d_ptr->margins);
|
||||
}
|
||||
|
||||
double QMapboxGL::minimumZoom() const
|
||||
@@ -190,18 +191,19 @@ double QMapboxGL::maximumZoom() const
|
||||
|
||||
QMapboxGL::Coordinate QMapboxGL::coordinate() const
|
||||
{
|
||||
const mbgl::LatLng& latLng = d_ptr->mapObj->getLatLng();
|
||||
const mbgl::LatLng& latLng = d_ptr->mapObj->getLatLng(d_ptr->margins);
|
||||
return Coordinate(latLng.latitude, latLng.longitude);
|
||||
}
|
||||
|
||||
void QMapboxGL::setCoordinate(const Coordinate &coordinate_)
|
||||
{
|
||||
d_ptr->mapObj->setLatLng(mbgl::LatLng { coordinate_.first, coordinate_.second });
|
||||
d_ptr->mapObj->setLatLng(mbgl::LatLng { coordinate_.first, coordinate_.second }, d_ptr->margins);
|
||||
}
|
||||
|
||||
void QMapboxGL::setCoordinateZoom(const Coordinate &coordinate_, double zoom_)
|
||||
{
|
||||
d_ptr->mapObj->setLatLngZoom(mbgl::LatLng { coordinate_.first, coordinate_.second }, zoom_);
|
||||
d_ptr->mapObj->setLatLngZoom(
|
||||
mbgl::LatLng { coordinate_.first, coordinate_.second }, zoom_, d_ptr->margins);
|
||||
}
|
||||
|
||||
double QMapboxGL::bearing() const
|
||||
@@ -211,7 +213,7 @@ double QMapboxGL::bearing() const
|
||||
|
||||
void QMapboxGL::setBearing(double degrees)
|
||||
{
|
||||
d_ptr->mapObj->setBearing(degrees);
|
||||
d_ptr->mapObj->setBearing(degrees, d_ptr->margins);
|
||||
}
|
||||
|
||||
void QMapboxGL::setBearing(double degrees, const QPointF ¢er)
|
||||
@@ -456,6 +458,26 @@ QMapboxGL::Coordinate QMapboxGL::coordinateForPixel(const QPointF &pixel) const
|
||||
return Coordinate(latLng.latitude, latLng.longitude);
|
||||
}
|
||||
|
||||
void QMapboxGL::setMargins(const QMargins &margins_)
|
||||
{
|
||||
d_ptr->margins = {
|
||||
static_cast<double>(margins_.top()),
|
||||
static_cast<double>(margins_.left()),
|
||||
static_cast<double>(margins_.bottom()),
|
||||
static_cast<double>(margins_.right())
|
||||
};
|
||||
}
|
||||
|
||||
QMargins QMapboxGL::margins() const
|
||||
{
|
||||
return QMargins(
|
||||
d_ptr->margins.left,
|
||||
d_ptr->margins.top,
|
||||
d_ptr->margins.right,
|
||||
d_ptr->margins.bottom
|
||||
);
|
||||
}
|
||||
|
||||
void QMapboxGL::render()
|
||||
{
|
||||
d_ptr->mapObj->render();
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <mbgl/map/map.hpp>
|
||||
#include <mbgl/map/view.hpp>
|
||||
#include <mbgl/storage/default_file_source.hpp>
|
||||
#include <mbgl/util/geo.hpp>
|
||||
#include <mbgl/util/run_loop.hpp>
|
||||
|
||||
#include <QMapboxGL>
|
||||
@@ -33,6 +34,7 @@ public:
|
||||
void invalidate() final;
|
||||
void notifyMapChange(mbgl::MapChange change) final;
|
||||
|
||||
mbgl::EdgeInsets margins;
|
||||
QSize size;
|
||||
|
||||
QMapboxGL *q_ptr = nullptr;
|
||||
|
||||
Reference in New Issue
Block a user