From 11afef7825d622a237fa026e45e6d61b4de94068 Mon Sep 17 00:00:00 2001 From: Sudarsana Babu Nagineni Date: Mon, 25 Mar 2019 23:39:31 +0200 Subject: [core] Add interface to change the orientation through MapOptions --- include/mbgl/map/map.hpp | 5 +---- include/mbgl/map/map_options.hpp | 17 +++++++++++++++++ platform/glfw/glfw_view.cpp | 2 +- platform/qt/src/qmapboxgl.cpp | 2 +- src/mbgl/map/map.cpp | 7 ++----- src/mbgl/map/map_impl.cpp | 1 + src/mbgl/map/map_options.cpp | 10 ++++++++++ 7 files changed, 33 insertions(+), 11 deletions(-) diff --git a/include/mbgl/map/map.hpp b/include/mbgl/map/map.hpp index bd0cfbc0d7..9134272ea7 100644 --- a/include/mbgl/map/map.hpp +++ b/include/mbgl/map/map.hpp @@ -87,11 +87,8 @@ public: /// @} - // North Orientation - void setNorthOrientation(NorthOrientation); - NorthOrientation getNorthOrientation() const; - // Map Options + void setNorthOrientation(NorthOrientation); void setConstrainMode(ConstrainMode); void setViewportMode(ViewportMode); MapOptions getMapOptions() const; diff --git a/include/mbgl/map/map_options.hpp b/include/mbgl/map/map_options.hpp index 617a2d793a..8d5c12b96c 100644 --- a/include/mbgl/map/map_options.hpp +++ b/include/mbgl/map/map_options.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include #include @@ -86,6 +87,22 @@ public: */ bool crossSourceCollisions() const; + /** + * @brief Sets the orientation of the Map. By default, it is set to + * Upwards. + * + * @param orientation Orientation of the Map. + * @return reference to MapOptions for chaining options together. + */ + MapOptions& withNorthOrientation(NorthOrientation orientation); + + /** + * @brief Gets the previously set (or default) orientation. + * + * @return Map orientation. + */ + NorthOrientation northOrientation() const; + private: class Impl; std::unique_ptr impl_; diff --git a/platform/glfw/glfw_view.cpp b/platform/glfw/glfw_view.cpp index e768851a53..601642cfa6 100644 --- a/platform/glfw/glfw_view.cpp +++ b/platform/glfw/glfw_view.cpp @@ -385,7 +385,7 @@ GLFWView::makeImage(const std::string& id, int width, int height, float pixelRat void GLFWView::nextOrientation() { using NO = mbgl::NorthOrientation; - switch (map->getNorthOrientation()) { + switch (map->getMapOptions().northOrientation()) { case NO::Upwards: map->setNorthOrientation(NO::Rightwards); break; case NO::Rightwards: map->setNorthOrientation(NO::Downwards); break; case NO::Downwards: map->setNorthOrientation(NO::Leftwards); break; diff --git a/platform/qt/src/qmapboxgl.cpp b/platform/qt/src/qmapboxgl.cpp index 82b157d57a..313860890c 100644 --- a/platform/qt/src/qmapboxgl.cpp +++ b/platform/qt/src/qmapboxgl.cpp @@ -867,7 +867,7 @@ void QMapboxGL::pitchBy(double pitch_) */ QMapboxGL::NorthOrientation QMapboxGL::northOrientation() const { - return static_cast(d_ptr->mapObj->getNorthOrientation()); + return static_cast(d_ptr->mapObj->getMapOptions().northOrientation()); } /*! diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp index e609e22c97..06c637b232 100644 --- a/src/mbgl/map/map.cpp +++ b/src/mbgl/map/map.cpp @@ -326,10 +326,6 @@ void Map::setNorthOrientation(NorthOrientation orientation) { impl->onUpdate(); } -NorthOrientation Map::getNorthOrientation() const { - return impl->transform.getNorthOrientation(); -} - #pragma mark - Constrain mode void Map::setConstrainMode(mbgl::ConstrainMode mode) { @@ -351,7 +347,8 @@ MapOptions Map::getMapOptions() const { .withMapMode(impl->mode) .withConstrainMode(impl->transform.getConstrainMode()) .withViewportMode(impl->transform.getViewportMode()) - .withCrossSourceCollisions(impl->crossSourceCollisions)); + .withCrossSourceCollisions(impl->crossSourceCollisions) + .withNorthOrientation(impl->transform.getNorthOrientation())); } #pragma mark - Projection mode diff --git a/src/mbgl/map/map_impl.cpp b/src/mbgl/map/map_impl.cpp index 348e26700f..cdc8c231e4 100644 --- a/src/mbgl/map/map_impl.cpp +++ b/src/mbgl/map/map_impl.cpp @@ -24,6 +24,7 @@ Map::Impl::Impl(RendererFrontend& frontend_, fileSource(std::move(fileSource_)), style(std::make_unique(scheduler, *fileSource, pixelRatio)), annotationManager(*style) { + transform.setNorthOrientation(mapOptions.northOrientation()); style->impl->setObserver(this); rendererFrontend.setObserver(*this); transform.resize(size_); diff --git a/src/mbgl/map/map_options.cpp b/src/mbgl/map/map_options.cpp index 7c254476d6..b4ad38ac7f 100644 --- a/src/mbgl/map/map_options.cpp +++ b/src/mbgl/map/map_options.cpp @@ -7,6 +7,7 @@ public: MapMode mapMode = MapMode::Continuous; ConstrainMode constrainMode = ConstrainMode::HeightOnly; ViewportMode viewportMode = ViewportMode::Default; + NorthOrientation orientation = NorthOrientation::Upwards; bool crossSourceCollisions = true; }; @@ -51,4 +52,13 @@ bool MapOptions::crossSourceCollisions() const { return impl_->crossSourceCollisions; } +MapOptions& MapOptions::withNorthOrientation(NorthOrientation orientation) { + impl_->orientation = orientation; + return *this; +} + +NorthOrientation MapOptions::northOrientation() const { + return impl_->orientation; +} + } // namespace mbgl -- cgit v1.2.1