summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBruno de Oliveira Abinader <bruno@mapbox.com>2016-03-08 23:43:24 +0200
committerBruno de Oliveira Abinader <bruno@mapbox.com>2016-03-10 03:36:46 +0200
commite8d1276bb10159423fb6b0b07cd02d5cced96f05 (patch)
treeed68ea70d49a4e8c40bf24fddf6d709d2c0a058d /src
parentd300f341bca4d4fe295a6dd303c0961bff7a0520 (diff)
downloadqtlocation-mapboxgl-e8d1276bb10159423fb6b0b07cd02d5cced96f05.tar.gz
[core] Added Transform::getScreenCoordinate
Diffstat (limited to 'src')
-rw-r--r--src/mbgl/map/transform.cpp31
-rw-r--r--src/mbgl/map/transform.hpp1
2 files changed, 19 insertions, 13 deletions
diff --git a/src/mbgl/map/transform.cpp b/src/mbgl/map/transform.cpp
index 6aa0bd9a41..fe4cbbe673 100644
--- a/src/mbgl/map/transform.cpp
+++ b/src/mbgl/map/transform.cpp
@@ -106,7 +106,7 @@ void Transform::easeTo(const CameraOptions& camera, const AnimationOptions& anim
state.lngX(latLng.longitude),
state.latY(latLng.latitude),
};
- ScreenCoordinate center = padding.getCenter(state.width, state.height);
+ ScreenCoordinate center = getScreenCoordinate(padding);
center.y = state.height - center.y;
// Constrain camera options.
@@ -194,7 +194,7 @@ void Transform::flyTo(const CameraOptions &camera, const AnimationOptions &anima
state.lngX(latLng.longitude),
state.latY(latLng.latitude),
};
- ScreenCoordinate center = padding.getCenter(state.width, state.height);
+ ScreenCoordinate center = getScreenCoordinate(padding);
center.y = state.height - center.y;
// Constrain camera options.
@@ -211,8 +211,9 @@ 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 - padding.left - padding.right,
- state.height - padding.top - padding.bottom);
+ double w0 = padding ? std::max(state.width, state.height)
+ : 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);
@@ -343,7 +344,7 @@ void Transform::moveBy(const ScreenCoordinate& offset, const Duration& duration)
offset.x,
-offset.y,
};
- ScreenCoordinate centerPoint = state.latLngToScreenCoordinate(state.getLatLng()) - centerOffset;
+ ScreenCoordinate centerPoint = getScreenCoordinate() - centerOffset;
CameraOptions camera;
camera.center = state.screenCoordinateToLatLng(centerPoint);
@@ -410,6 +411,14 @@ LatLng Transform::getLatLng(const EdgeInsets& padding) const {
}
}
+ScreenCoordinate Transform::getScreenCoordinate(const EdgeInsets& padding) const {
+ if (padding) {
+ return padding.getCenter(state.width, state.height);
+ } else {
+ return { state.width / 2., state.height / 2. };
+ }
+}
+
#pragma mark - Zoom
@@ -451,8 +460,7 @@ void Transform::setScale(double scale, const ScreenCoordinate& anchor, const Dur
}
void Transform::setScale(double scale, const EdgeInsets& padding, const Duration& duration) {
- const ScreenCoordinate center = padding.getCenter(state.width, state.height);
- setScale(scale, center, duration);
+ setScale(scale, getScreenCoordinate(padding), duration);
}
void Transform::setMinZoom(const double minZoom) {
@@ -470,9 +478,7 @@ void Transform::rotateBy(const ScreenCoordinate& first, const ScreenCoordinate&
return;
}
- ScreenCoordinate center(state.width, state.height);
- center /= 2;
-
+ ScreenCoordinate center = getScreenCoordinate();
const ScreenCoordinate offset = first - center;
const double distance = std::sqrt(std::pow(2, offset.x) + std::pow(2, offset.y));
@@ -505,13 +511,12 @@ void Transform::setAngle(double angle, const ScreenCoordinate& anchor, const Dur
CameraOptions camera;
camera.angle = angle;
- camera.anchor = anchor;
+ if (anchor) camera.anchor = anchor;
easeTo(camera, duration);
}
void Transform::setAngle(double angle, const EdgeInsets& padding, const Duration& duration) {
- const ScreenCoordinate center = padding.getCenter(state.width, state.height);
- setAngle(angle, center, duration);
+ setAngle(angle, getScreenCoordinate(padding), duration);
}
double Transform::getAngle() const {
diff --git a/src/mbgl/map/transform.hpp b/src/mbgl/map/transform.hpp
index 638eead5f1..6bbfd9c6f7 100644
--- a/src/mbgl/map/transform.hpp
+++ b/src/mbgl/map/transform.hpp
@@ -48,6 +48,7 @@ public:
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;
+ ScreenCoordinate getScreenCoordinate(const EdgeInsets& = {}) const;
// Zoom