summaryrefslogtreecommitdiff
path: root/src/mbgl/map
diff options
context:
space:
mode:
authorBruno de Oliveira Abinader <bruno@mapbox.com>2018-08-30 17:26:04 +0300
committerBruno de Oliveira Abinader <bruno@mapbox.com>2018-10-19 12:05:16 +0200
commitb94be6e68f666410852aebd638782601162809d6 (patch)
tree91774c156316838c28e49ba8b6a167749c974591 /src/mbgl/map
parent98c36fc06edb99b2db20d474c4c3ec6bf51e219d (diff)
downloadqtlocation-mapboxgl-b94be6e68f666410852aebd638782601162809d6.tar.gz
[core] Add TransformState::getCameraOptions()
Diffstat (limited to 'src/mbgl/map')
-rw-r--r--src/mbgl/map/transform.cpp8
-rw-r--r--src/mbgl/map/transform_state.cpp20
-rw-r--r--src/mbgl/map/transform_state.hpp3
3 files changed, 24 insertions, 7 deletions
diff --git a/src/mbgl/map/transform.cpp b/src/mbgl/map/transform.cpp
index 21f1b70c42..0d633499cf 100644
--- a/src/mbgl/map/transform.cpp
+++ b/src/mbgl/map/transform.cpp
@@ -64,13 +64,7 @@ void Transform::resize(const Size size) {
#pragma mark - Camera
CameraOptions Transform::getCameraOptions(const EdgeInsets& padding) const {
- CameraOptions camera;
- camera.center = getLatLng(padding);
- camera.padding = padding;
- camera.zoom = getZoom();
- camera.angle = getAngle();
- camera.pitch = getPitch();
- return camera;
+ return state.getCameraOptions(padding);
}
/**
diff --git a/src/mbgl/map/transform_state.cpp b/src/mbgl/map/transform_state.cpp
index 5cbd307698..4de795d469 100644
--- a/src/mbgl/map/transform_state.cpp
+++ b/src/mbgl/map/transform_state.cpp
@@ -130,6 +130,26 @@ ViewportMode TransformState::getViewportMode() const {
return viewportMode;
}
+#pragma mark - Camera options
+
+CameraOptions TransformState::getCameraOptions(const EdgeInsets& padding) const {
+ CameraOptions camera;
+
+ if (padding.isFlush()) {
+ camera.center = getLatLng();
+ } else {
+ ScreenCoordinate point = padding.getCenter(size.width, size.height);
+ point.y = size.height - point.y;
+ camera.center = screenCoordinateToLatLng(point).wrapped();
+ }
+ camera.padding = padding;
+ camera.zoom = getZoom();
+ camera.angle = -angle * util::RAD2DEG;
+ camera.pitch = pitch * util::RAD2DEG;
+
+ return camera;
+}
+
#pragma mark - Position
LatLng TransformState::getLatLng(LatLng::WrapMode wrapMode) const {
diff --git a/src/mbgl/map/transform_state.hpp b/src/mbgl/map/transform_state.hpp
index b6f8ae4424..4049965618 100644
--- a/src/mbgl/map/transform_state.hpp
+++ b/src/mbgl/map/transform_state.hpp
@@ -1,6 +1,7 @@
#pragma once
#include <mbgl/map/mode.hpp>
+#include <mbgl/map/camera.hpp>
#include <mbgl/util/geo.hpp>
#include <mbgl/util/geometry.hpp>
#include <mbgl/util/constants.hpp>
@@ -40,6 +41,8 @@ public:
// Viewport mode
ViewportMode getViewportMode() const;
+ CameraOptions getCameraOptions(const EdgeInsets&) const;
+
// Position
LatLng getLatLng(LatLng::WrapMode = LatLng::Unwrapped) const;
double pixel_x() const;