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 | |
parent | 98c36fc06edb99b2db20d474c4c3ec6bf51e219d (diff) | |
download | qtlocation-mapboxgl-b94be6e68f666410852aebd638782601162809d6.tar.gz |
[core] Add TransformState::getCameraOptions()
-rw-r--r-- | platform/default/mbgl/gl/headless_frontend.cpp | 8 | ||||
-rw-r--r-- | platform/default/mbgl/gl/headless_frontend.hpp | 2 | ||||
-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 |
5 files changed, 34 insertions, 7 deletions
diff --git a/platform/default/mbgl/gl/headless_frontend.cpp b/platform/default/mbgl/gl/headless_frontend.cpp index 4263d2b148..c87a2796c9 100644 --- a/platform/default/mbgl/gl/headless_frontend.cpp +++ b/platform/default/mbgl/gl/headless_frontend.cpp @@ -55,6 +55,14 @@ RendererBackend* HeadlessFrontend::getBackend() { return &backend; } +CameraOptions HeadlessFrontend::getCameraOptions() { + if (updateParameters) + return RendererState::getCameraOptions(*updateParameters); + + static CameraOptions nullCamera; + return nullCamera; +} + void HeadlessFrontend::setSize(Size size_) { if (size != size_) { size = size_; diff --git a/platform/default/mbgl/gl/headless_frontend.hpp b/platform/default/mbgl/gl/headless_frontend.hpp index 8ae617d37b..29ab30c93d 100644 --- a/platform/default/mbgl/gl/headless_frontend.hpp +++ b/platform/default/mbgl/gl/headless_frontend.hpp @@ -1,5 +1,6 @@ #pragma once +#include <mbgl/map/camera.hpp> #include <mbgl/renderer/mode.hpp> #include <mbgl/renderer/renderer_frontend.hpp> #include <mbgl/gl/headless_backend.hpp> @@ -32,6 +33,7 @@ public: Renderer* getRenderer(); RendererBackend* getBackend(); + CameraOptions getCameraOptions(); PremultipliedImage readStillImage(); PremultipliedImage render(Map&); 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; |