diff options
author | Bruno de Oliveira Abinader <bruno@mapbox.com> | 2018-08-30 17:26:04 +0300 |
---|---|---|
committer | Bruno de Oliveira Abinader <bruno@mapbox.com> | 2018-10-19 12:05:16 +0200 |
commit | b94be6e68f666410852aebd638782601162809d6 (patch) | |
tree | 91774c156316838c28e49ba8b6a167749c974591 /src/mbgl/map | |
parent | 98c36fc06edb99b2db20d474c4c3ec6bf51e219d (diff) | |
download | qtlocation-mapboxgl-b94be6e68f666410852aebd638782601162809d6.tar.gz |
[core] Add TransformState::getCameraOptions()
Diffstat (limited to 'src/mbgl/map')
-rw-r--r-- | src/mbgl/map/transform.cpp | 8 | ||||
-rw-r--r-- | src/mbgl/map/transform_state.cpp | 20 | ||||
-rw-r--r-- | src/mbgl/map/transform_state.hpp | 3 |
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; |