summaryrefslogtreecommitdiff
path: root/src/mbgl/map
diff options
context:
space:
mode:
authorMinh Nguyễn <mxn@1ec5.org>2016-01-15 08:23:10 -0800
committerMinh Nguyễn <mxn@1ec5.org>2016-01-18 16:54:57 -0800
commit143f8a78170065fc46afba1eaf987258e9c9f99b (patch)
tree854e6e55b5d08b4c524afb30c7f4c6ff2d8d3821 /src/mbgl/map
parentcb126eafe0e9b482162414d0fbbc0ae4d4f3cea9 (diff)
downloadqtlocation-mapboxgl-143f8a78170065fc46afba1eaf987258e9c9f99b.tar.gz
[core] Added padding option to CameraOptions
Moved EdgeInsets to geo.hpp so CameraOptions and Transform can refer to it. Added a padding option to CameraOptions that alters the frame of reference for the center option. Added optional padding parameters to LatLng getters and setters. Working towards #2600.
Diffstat (limited to 'src/mbgl/map')
-rw-r--r--src/mbgl/map/map.cpp12
-rw-r--r--src/mbgl/map/transform.cpp42
-rw-r--r--src/mbgl/map/transform.hpp3
3 files changed, 49 insertions, 8 deletions
diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp
index 50201ff949..f03915c953 100644
--- a/src/mbgl/map/map.cpp
+++ b/src/mbgl/map/map.cpp
@@ -172,7 +172,11 @@ void Map::moveBy(const PrecisionPoint& point, const Duration& duration) {
}
void Map::setLatLng(const LatLng& latLng, const Duration& duration) {
- transform->setLatLng(latLng, duration);
+ setLatLng(latLng, EdgeInsets(), duration);
+}
+
+void Map::setLatLng(const LatLng& latLng, const EdgeInsets& padding, const Duration& duration) {
+ transform->setLatLng(latLng, padding, duration);
update(Update::Repaint);
}
@@ -181,8 +185,8 @@ void Map::setLatLng(const LatLng& latLng, const PrecisionPoint& point, const Dur
update(Update::Repaint);
}
-LatLng Map::getLatLng() const {
- return transform->getLatLng();
+LatLng Map::getLatLng(const EdgeInsets& padding) const {
+ return transform->getLatLng(padding);
}
void Map::resetPosition() {
@@ -259,7 +263,7 @@ CameraOptions Map::cameraForLatLngs(const std::vector<LatLng>& latLngs, const Ed
double scaleY = (getHeight() - padding.top - padding.bottom) / height;
double minScale = ::fmin(scaleX, scaleY);
double zoom = ::log2(getScale() * minScale);
- zoom = ::fmax(::fmin(zoom, getMaxZoom()), getMinZoom());
+ zoom = util::clamp(zoom, getMinZoom(), getMaxZoom());
// Calculate the center point of a virtual bounds that is extended in all directions by padding.
PrecisionPoint paddedNEPixel = {
diff --git a/src/mbgl/map/transform.cpp b/src/mbgl/map/transform.cpp
index 98b0804482..7596d5d543 100644
--- a/src/mbgl/map/transform.cpp
+++ b/src/mbgl/map/transform.cpp
@@ -91,7 +91,12 @@ void Transform::easeTo(const CameraOptions& camera, const AnimationOptions& anim
}
// Determine endpoints.
- const LatLng startLatLng = getLatLng();
+ EdgeInsets padding;
+ if (camera.padding) {
+ padding = *camera.padding;
+ }
+ const LatLng startLatLng = getLatLng(padding);
+ padding.flip();
const PrecisionPoint startPoint = {
state.lngX(startLatLng.longitude),
state.latY(startLatLng.latitude),
@@ -141,6 +146,10 @@ void Transform::easeTo(const CameraOptions& camera, const AnimationOptions& anim
if (pitch != startPitch) {
state.pitch = util::interpolate(startPitch, pitch, t);
}
+
+ if (padding) {
+ state.moveLatLng(frameLatLng, padding.getCenter(state.width, state.height));
+ }
return update;
}, duration);
}
@@ -164,7 +173,12 @@ void Transform::flyTo(const CameraOptions &camera, const AnimationOptions &anima
}
// Determine endpoints.
- const LatLng startLatLng = getLatLng();
+ EdgeInsets padding;
+ if (camera.padding) {
+ padding = *camera.padding;
+ }
+ const LatLng startLatLng = getLatLng(padding);
+ padding.flip();
const PrecisionPoint startPoint = {
state.lngX(startLatLng.longitude),
state.latY(startLatLng.latitude),
@@ -189,7 +203,8 @@ void Transform::flyTo(const CameraOptions &camera, const AnimationOptions &anima
/// w₀: Initial visible span, measured in pixels at the initial scale.
/// Known henceforth as a <i>screenful</i>.
- double w0 = std::max(state.width, state.height);
+ double w0 = std::max(state.width - padding.left - padding.right,
+ state.height - padding.top - padding.bottom);
/// w₁: Final visible span, measured in pixels with respect to the initial
/// scale.
double w1 = w0 / state.zoomScale(zoom - startZoom);
@@ -304,6 +319,10 @@ void Transform::flyTo(const CameraOptions &camera, const AnimationOptions &anima
if (pitch != startPitch) {
state.pitch = util::interpolate(startPitch, pitch, k);
}
+
+ if (padding) {
+ state.moveLatLng(frameLatLng, padding.getCenter(state.width, state.height));
+ }
return Update::Zoom;
}, duration);
}
@@ -340,12 +359,19 @@ void Transform::moveBy(const PrecisionPoint& offset, const Duration& duration) {
}
void Transform::setLatLng(const LatLng& latLng, const Duration& duration) {
+ setLatLng(latLng, EdgeInsets(), duration);
+}
+
+void Transform::setLatLng(const LatLng& latLng, const EdgeInsets& padding, const Duration& duration) {
if (!latLng) {
return;
}
CameraOptions camera;
camera.center = latLng;
+ if (padding) {
+ camera.padding = padding;
+ }
easeTo(camera, duration);
}
@@ -381,6 +407,16 @@ void Transform::setLatLngZoom(const LatLng& latLng, double zoom, const Duration&
easeTo(camera, duration);
}
+LatLng Transform::getLatLng(const EdgeInsets& padding) const {
+ if (padding) {
+ EdgeInsets flippedPadding = padding;
+ flippedPadding.flip();
+ return state.pointToLatLng(flippedPadding.getCenter(state.width, state.height));
+ } else {
+ return state.getLatLng();
+ }
+}
+
#pragma mark - Zoom
diff --git a/src/mbgl/map/transform.hpp b/src/mbgl/map/transform.hpp
index 6be0558f98..77c03e939d 100644
--- a/src/mbgl/map/transform.hpp
+++ b/src/mbgl/map/transform.hpp
@@ -43,9 +43,10 @@ public:
top to bottom and from left to right. */
void moveBy(const PrecisionPoint& offset, const Duration& = Duration::zero());
void setLatLng(const LatLng&, const Duration& = Duration::zero());
+ 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());
- LatLng getLatLng() const { return state.getLatLng(); }
+ LatLng getLatLng(const EdgeInsets& = {}) const;
// Zoom