summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMinh Nguyễn <mxn@1ec5.org>2016-01-15 12:01:37 -0800
committerMinh Nguyễn <mxn@1ec5.org>2016-01-18 16:54:58 -0800
commitbf87eaa7b8aa049358559a96f290603e13ac736b (patch)
treec28e725d66d6cee549b72f5f3bb13fbd1f61c6ad /src
parentc86646519a4887d47003d11061a6a82e7ff4241c (diff)
downloadqtlocation-mapboxgl-bf87eaa7b8aa049358559a96f290603e13ac736b.tar.gz
[core, osx] Added optional padding to convenience methods
Methods that offer a convenient way to jump or ease now accept an optional padding parameter. MGLMapView specifies the padding to ensure that keyboard-based zooming and rotation respects the toolbar.
Diffstat (limited to 'src')
-rw-r--r--src/mbgl/map/map.cpp37
-rw-r--r--src/mbgl/map/transform.cpp26
-rw-r--r--src/mbgl/map/transform.hpp28
3 files changed, 73 insertions, 18 deletions
diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp
index f03915c953..b0cc49968c 100644
--- a/src/mbgl/map/map.cpp
+++ b/src/mbgl/map/map.cpp
@@ -189,12 +189,15 @@ LatLng Map::getLatLng(const EdgeInsets& padding) const {
return transform->getLatLng(padding);
}
-void Map::resetPosition() {
- CameraOptions options;
- options.angle = 0;
- options.center = LatLng(0, 0);
- options.zoom = 0;
- transform->jumpTo(options);
+void Map::resetPosition(const EdgeInsets& padding) {
+ CameraOptions camera;
+ camera.angle = 0;
+ camera.center = LatLng(0, 0);
+ if (padding) {
+ camera.padding = padding;
+ }
+ camera.zoom = 0;
+ transform->jumpTo(camera);
update(Update::Zoom);
}
@@ -216,7 +219,11 @@ double Map::getScale() const {
}
void Map::setZoom(double zoom, const Duration& duration) {
- transform->setZoom(zoom, duration);
+ setZoom(zoom, {}, duration);
+}
+
+void Map::setZoom(double zoom, const EdgeInsets& padding, const Duration& duration) {
+ transform->setZoom(zoom, padding, duration);
update(Update::Zoom);
}
@@ -225,7 +232,11 @@ double Map::getZoom() const {
}
void Map::setLatLngZoom(const LatLng& latLng, double zoom, const Duration& duration) {
- transform->setLatLngZoom(latLng, zoom, duration);
+ setLatLngZoom(latLng, zoom, {}, duration);
+}
+
+void Map::setLatLngZoom(const LatLng& latLng, double zoom, const EdgeInsets& padding, const Duration& duration) {
+ transform->setLatLngZoom(latLng, zoom, padding, duration);
update(Update::Zoom);
}
@@ -316,12 +327,16 @@ void Map::rotateBy(const PrecisionPoint& first, const PrecisionPoint& second, co
}
void Map::setBearing(double degrees, const Duration& duration) {
- transform->setAngle(-degrees * M_PI / 180, duration);
+ setBearing(degrees, EdgeInsets(), duration);
+}
+
+void Map::setBearing(double degrees, const PrecisionPoint& center, const Duration& duration) {
+ transform->setAngle(-degrees * M_PI / 180, center, duration);
update(Update::Repaint);
}
-void Map::setBearing(double degrees, const PrecisionPoint& center) {
- transform->setAngle(-degrees * M_PI / 180, center);
+void Map::setBearing(double degrees, const EdgeInsets& padding, const Duration& duration) {
+ transform->setAngle(-degrees * M_PI / 180, padding, duration);
update(Update::Repaint);
}
diff --git a/src/mbgl/map/transform.cpp b/src/mbgl/map/transform.cpp
index 7596d5d543..69af657ecd 100644
--- a/src/mbgl/map/transform.cpp
+++ b/src/mbgl/map/transform.cpp
@@ -397,12 +397,19 @@ void Transform::setLatLng(const LatLng& latLng, const PrecisionPoint& point, con
}
void Transform::setLatLngZoom(const LatLng& latLng, double zoom, const Duration& duration) {
+ setLatLngZoom(latLng, zoom, {}, duration);
+}
+
+void Transform::setLatLngZoom(const LatLng& latLng, double zoom, const EdgeInsets& padding, const Duration& duration) {
if (!latLng || std::isnan(zoom)) {
return;
}
CameraOptions camera;
camera.center = latLng;
+ if (padding) {
+ camera.padding = padding;
+ }
camera.zoom = zoom;
easeTo(camera, duration);
}
@@ -429,8 +436,13 @@ void Transform::scaleBy(double ds, const PrecisionPoint& center, const Duration&
setScale(scale, center, duration);
}
-void Transform::setZoom(double zoom, const Duration& duration) {
- setScale(state.zoomScale(zoom), {NAN, NAN}, duration);
+void Transform::setZoom(double zoom, const PrecisionPoint& anchor, const Duration& duration) {
+ setScale(state.zoomScale(zoom), anchor, duration);
+}
+
+void Transform::setZoom(double zoom, const EdgeInsets& padding, const Duration& duration) {
+ const PrecisionPoint center = padding.getCenter(state.width, state.height);
+ setZoom(zoom, center, duration);
}
double Transform::getZoom() const {
@@ -452,6 +464,11 @@ void Transform::setScale(double scale, const PrecisionPoint& anchor, const Durat
easeTo(camera, duration);
}
+void Transform::setScale(double scale, const EdgeInsets& padding, const Duration& duration) {
+ const PrecisionPoint center = padding.getCenter(state.width, state.height);
+ setScale(scale, center, duration);
+}
+
#pragma mark - Angle
void Transform::rotateBy(const PrecisionPoint& first, const PrecisionPoint& second, const Duration& duration) {
@@ -498,6 +515,11 @@ void Transform::setAngle(double angle, const PrecisionPoint& anchor, const Durat
easeTo(camera, duration);
}
+void Transform::setAngle(double angle, const EdgeInsets& padding, const Duration& duration) {
+ const PrecisionPoint center = padding.getCenter(state.width, state.height);
+ setAngle(angle, center, duration);
+}
+
double Transform::getAngle() const {
return state.angle;
}
diff --git a/src/mbgl/map/transform.hpp b/src/mbgl/map/transform.hpp
index 77c03e939d..cb3378a532 100644
--- a/src/mbgl/map/transform.hpp
+++ b/src/mbgl/map/transform.hpp
@@ -46,21 +46,34 @@ public:
void setLatLng(const LatLng&, const EdgeInsets&, const Duration& = Duration::zero());
void setLatLng(const LatLng&, const PrecisionPoint&, const Duration& = Duration::zero());
void setLatLngZoom(const LatLng&, double zoom, const Duration& = Duration::zero());
+ void setLatLngZoom(const LatLng&, double zoom, const EdgeInsets&, const Duration& = Duration::zero());
LatLng getLatLng(const EdgeInsets& = {}) const;
// Zoom
/** Scales the map, keeping the given point fixed within the view.
@param ds The difference in scale factors to scale the map by.
- @param anchor A point relative to the top-left corner of the view. */
+ @param anchor A point relative to the top-left corner of the view.
+ If unspecified, the center point is fixed within the view. */
void scaleBy(double ds, const PrecisionPoint& anchor = {NAN, NAN}, const Duration& = Duration::zero());
/** Sets the scale factor, keeping the given point fixed within the view.
@param scale The new scale factor.
- @param anchor A point relative to the top-left corner of the view. */
+ @param anchor A point relative to the top-left corner of the view.
+ If unspecified, the center point is fixed within the view. */
void setScale(double scale, const PrecisionPoint& anchor = {NAN, NAN}, const Duration& = Duration::zero());
- /** Sets the zoom level.
- @param zoom The new zoom level. */
- void setZoom(double zoom, const Duration& = Duration::zero());
+ /** Sets the scale factor, keeping the center point fixed within the inset view.
+ @param scale The new scale factor.
+ @param padding The viewport padding that affects the fixed center point. */
+ void setScale(double scale, const EdgeInsets& padding, const Duration& = Duration::zero());
+ /** Sets the zoom level, keeping the given point fixed within the view.
+ @param zoom The new zoom level.
+ @param anchor A point relative to the top-left corner of the view.
+ If unspecified, the center point is fixed within the view. */
+ void setZoom(double zoom, const PrecisionPoint& anchor = {NAN, NAN}, const Duration& = Duration::zero());
+ /** Sets the zoom level, keeping the center point fixed within the inset view.
+ @param zoom The new zoom level.
+ @param padding The viewport padding that affects the fixed center point. */
+ void setZoom(double zoom, const EdgeInsets& padding, const Duration& = Duration::zero());
/** Returns the zoom level. */
double getZoom() const;
/** Returns the scale factor. */
@@ -78,6 +91,11 @@ public:
counterclockwise from true north.
@param anchor A point relative to the top-left corner of the view. */
void setAngle(double angle, const PrecisionPoint& anchor, const Duration& = Duration::zero());
+ /** Sets the angle of rotation, keeping the center point fixed within the inset view.
+ @param angle The new angle of rotation, measured in radians
+ counterclockwise from true north.
+ @param padding The viewport padding that affects the fixed center point. */
+ void setAngle(double angle, const EdgeInsets& padding, const Duration& = Duration::zero());
/** Returns the angle of rotation.
@return The angle of rotation, measured in radians counterclockwise from
true north. */