[core] Add interface to change the orientation through MapOptions

This commit is contained in:
Sudarsana Babu Nagineni
2019-03-25 23:39:31 +02:00
parent e639087c91
commit 11afef7825
7 changed files with 33 additions and 11 deletions

View File

@@ -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;

View File

@@ -1,6 +1,7 @@
#pragma once
#include <mbgl/map/mode.hpp>
#include <mbgl/util/geo.hpp>
#include <memory>
@@ -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> impl_;

View File

@@ -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;

View File

@@ -867,7 +867,7 @@ void QMapboxGL::pitchBy(double pitch_)
*/
QMapboxGL::NorthOrientation QMapboxGL::northOrientation() const
{
return static_cast<QMapboxGL::NorthOrientation>(d_ptr->mapObj->getNorthOrientation());
return static_cast<QMapboxGL::NorthOrientation>(d_ptr->mapObj->getMapOptions().northOrientation());
}
/*!

View File

@@ -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

View File

@@ -24,6 +24,7 @@ Map::Impl::Impl(RendererFrontend& frontend_,
fileSource(std::move(fileSource_)),
style(std::make_unique<style::Style>(scheduler, *fileSource, pixelRatio)),
annotationManager(*style) {
transform.setNorthOrientation(mapOptions.northOrientation());
style->impl->setObserver(this);
rendererFrontend.setObserver(*this);
transform.resize(size_);

View File

@@ -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