summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/mbgl/map/map.hpp9
-rw-r--r--include/mbgl/map/mode.hpp7
-rw-r--r--platform/default/glfw_view.cpp1
-rw-r--r--platform/ios/src/MGLMapView.mm2
-rw-r--r--platform/osx/src/MGLMapView.mm2
-rw-r--r--src/mbgl/map/map.cpp21
-rw-r--r--src/mbgl/map/transform.cpp14
-rw-r--r--src/mbgl/map/transform.hpp8
-rw-r--r--src/mbgl/map/transform_state.cpp12
-rw-r--r--src/mbgl/map/transform_state.hpp8
-rw-r--r--src/mbgl/renderer/painter_symbol.cpp6
-rw-r--r--test/map/transform.cpp24
-rw-r--r--test/style/source.cpp2
-rw-r--r--test/util/tile_cover.cpp2
14 files changed, 85 insertions, 33 deletions
diff --git a/include/mbgl/map/map.hpp b/include/mbgl/map/map.hpp
index 3200484ec1..1042d97574 100644
--- a/include/mbgl/map/map.hpp
+++ b/include/mbgl/map/map.hpp
@@ -34,7 +34,8 @@ public:
explicit Map(View&, FileSource&,
MapMode mapMode = MapMode::Continuous,
GLContextMode contextMode = GLContextMode::Unique,
- ConstrainMode constrainMode = ConstrainMode::HeightOnly);
+ ConstrainMode constrainMode = ConstrainMode::HeightOnly,
+ ViewportMode viewportMode = ViewportMode::Default);
~Map();
// Register a callback that will get called (on the render thread) when all resources have
@@ -117,11 +118,15 @@ public:
// North Orientation
void setNorthOrientation(NorthOrientation);
NorthOrientation getNorthOrientation() const;
-
+
// Constrain mode
void setConstrainMode(ConstrainMode);
ConstrainMode getConstrainMode() const;
+ // Viewport mode
+ void setViewportMode(ViewportMode);
+ ViewportMode getViewportMode() const;
+
// Size
uint16_t getWidth() const;
uint16_t getHeight() const;
diff --git a/include/mbgl/map/mode.hpp b/include/mbgl/map/mode.hpp
index 7fd1a7f522..9302e36056 100644
--- a/include/mbgl/map/mode.hpp
+++ b/include/mbgl/map/mode.hpp
@@ -29,6 +29,13 @@ enum class ConstrainMode : EnumType {
WidthAndHeight,
};
+// Satisfies embedding platforms that requires the viewport coordinate systems
+// to be set according to its standards.
+enum class ViewportMode : EnumType {
+ Default,
+ FlippedY,
+};
+
enum class MapDebugOptions : EnumType {
NoDebug = 0,
TileBorders = 1 << 1,
diff --git a/platform/default/glfw_view.cpp b/platform/default/glfw_view.cpp
index 7fb47ff7c9..e3a38114bd 100644
--- a/platform/default/glfw_view.cpp
+++ b/platform/default/glfw_view.cpp
@@ -96,6 +96,7 @@ GLFWView::GLFWView(bool fullscreen_, bool benchmark_)
printf("- Press `N` to reset north\n");
printf("- Press `R` to toggle any available `night` style class\n");
printf("- Press `Z` to cycle through north orientations\n");
+ printf("- Prezz `X` to cycle through the viewport modes\n");
printf("- Press `A` to cycle through Mapbox offices in the world + dateline monument\n");
printf("\n");
printf("- Press `1` through `6` to add increasing numbers of point annotations for testing\n");
diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm
index 11484a097a..a0c24eebe5 100644
--- a/platform/ios/src/MGLMapView.mm
+++ b/platform/ios/src/MGLMapView.mm
@@ -380,7 +380,7 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
// setup mbgl map
mbgl::DefaultFileSource *mbglFileSource = [MGLOfflineStorage sharedOfflineStorage].mbglFileSource;
- _mbglMap = new mbgl::Map(*_mbglView, *mbglFileSource, mbgl::MapMode::Continuous, mbgl::GLContextMode::Unique, mbgl::ConstrainMode::None);
+ _mbglMap = new mbgl::Map(*_mbglView, *mbglFileSource, mbgl::MapMode::Continuous, mbgl::GLContextMode::Unique, mbgl::ConstrainMode::None, mbgl::ViewportMode::Default);
[self validateTileCacheSize];
// start paused if in IB
diff --git a/platform/osx/src/MGLMapView.mm b/platform/osx/src/MGLMapView.mm
index 382d9f8bad..7a17aa9250 100644
--- a/platform/osx/src/MGLMapView.mm
+++ b/platform/osx/src/MGLMapView.mm
@@ -261,7 +261,7 @@ public:
[[NSFileManager defaultManager] removeItemAtURL:legacyCacheURL error:NULL];
mbgl::DefaultFileSource *mbglFileSource = [MGLOfflineStorage sharedOfflineStorage].mbglFileSource;
- _mbglMap = new mbgl::Map(*_mbglView, *mbglFileSource, mbgl::MapMode::Continuous, mbgl::GLContextMode::Unique, mbgl::ConstrainMode::None);
+ _mbglMap = new mbgl::Map(*_mbglView, *mbglFileSource, mbgl::MapMode::Continuous, mbgl::GLContextMode::Unique, mbgl::ConstrainMode::None, mbgl::ViewportMode::Default);
[self validateTileCacheSize];
// Install the OpenGL layer. Interface Builder’s synchronous drawing means
diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp
index 0747606fc6..a4f9422184 100644
--- a/src/mbgl/map/map.cpp
+++ b/src/mbgl/map/map.cpp
@@ -34,7 +34,7 @@ enum class RenderState {
class Map::Impl : public Style::Observer {
public:
- Impl(View&, FileSource&, MapMode, GLContextMode, ConstrainMode);
+ Impl(View&, FileSource&, MapMode, GLContextMode, ConstrainMode, ViewportMode);
void onResourceLoaded() override;
void onResourceError(std::exception_ptr) override;
@@ -76,16 +76,16 @@ public:
bool loading = false;
};
-Map::Map(View& view, FileSource& fileSource, MapMode mapMode, GLContextMode contextMode, ConstrainMode constrainMode)
- : impl(std::make_unique<Impl>(view, fileSource, mapMode, contextMode, constrainMode)) {
+Map::Map(View& view, FileSource& fileSource, MapMode mapMode, GLContextMode contextMode, ConstrainMode constrainMode, ViewportMode viewportMode)
+ : impl(std::make_unique<Impl>(view, fileSource, mapMode, contextMode, constrainMode, viewportMode)) {
view.initialize(this);
update(Update::Dimensions);
}
-Map::Impl::Impl(View& view_, FileSource& fileSource_, MapMode mode_, GLContextMode contextMode_, ConstrainMode constrainMode_)
+Map::Impl::Impl(View& view_, FileSource& fileSource_, MapMode mode_, GLContextMode contextMode_, ConstrainMode constrainMode_, ViewportMode viewportMode_)
: view(view_),
fileSource(fileSource_),
- transform(view, constrainMode_),
+ transform(view, constrainMode_, viewportMode_),
mode(mode_),
contextMode(contextMode_),
pixelRatio(view.getPixelRatio()),
@@ -638,6 +638,17 @@ ConstrainMode Map::getConstrainMode() const {
return impl->transform.getConstrainMode();
}
+#pragma mark - Viewport mode
+
+void Map::setViewportMode(mbgl::ViewportMode mode) {
+ impl->transform.setViewportMode(mode);
+ update(Update::Repaint);
+}
+
+ViewportMode Map::getViewportMode() const {
+ return impl->transform.getViewportMode();
+}
+
#pragma mark - Projection
double Map::getMetersPerPixelAtLatitude(double lat, double zoom) const {
diff --git a/src/mbgl/map/transform.cpp b/src/mbgl/map/transform.cpp
index 69a644c7d9..958f9d9b63 100644
--- a/src/mbgl/map/transform.cpp
+++ b/src/mbgl/map/transform.cpp
@@ -36,9 +36,9 @@ static double _normalizeAngle(double angle, double anchorAngle)
return angle;
}
-Transform::Transform(View &view_, ConstrainMode constrainMode)
+Transform::Transform(View &view_, ConstrainMode constrainMode, ViewportMode viewportMode)
: view(view_)
- , state(constrainMode)
+ , state(constrainMode, viewportMode)
{
}
@@ -555,6 +555,16 @@ ConstrainMode Transform::getConstrainMode() const {
return state.getConstrainMode();
}
+#pragma mark - Viewport mode
+
+void Transform::setViewportMode(mbgl::ViewportMode mode) {
+ state.viewportMode = mode;
+}
+
+ViewportMode Transform::getViewportMode() const {
+ return state.getViewportMode();
+}
+
#pragma mark - Transition
void Transform::startTransition(const CameraOptions& camera,
diff --git a/src/mbgl/map/transform.hpp b/src/mbgl/map/transform.hpp
index 7d3bdceb99..cd2d7a33f3 100644
--- a/src/mbgl/map/transform.hpp
+++ b/src/mbgl/map/transform.hpp
@@ -20,7 +20,7 @@ class View;
class Transform : private util::noncopyable {
public:
- Transform(View&, ConstrainMode);
+ Transform(View&, ConstrainMode, ViewportMode);
// Map view
bool resize(std::array<uint16_t, 2> size);
@@ -132,11 +132,15 @@ public:
// North Orientation
void setNorthOrientation(NorthOrientation);
NorthOrientation getNorthOrientation() const;
-
+
// Constrain mode
void setConstrainMode(ConstrainMode);
ConstrainMode getConstrainMode() const;
+ // Viewport mode
+ void setViewportMode(ViewportMode);
+ ViewportMode getViewportMode() const;
+
// Transitions
bool inTransition() const;
Update updateTransitions(const TimePoint& now);
diff --git a/src/mbgl/map/transform_state.cpp b/src/mbgl/map/transform_state.cpp
index 2813d6334e..0b8d831e54 100644
--- a/src/mbgl/map/transform_state.cpp
+++ b/src/mbgl/map/transform_state.cpp
@@ -7,8 +7,9 @@
namespace mbgl {
-TransformState::TransformState(ConstrainMode constrainMode_)
+TransformState::TransformState(ConstrainMode constrainMode_, ViewportMode viewportMode_)
: constrainMode(constrainMode_)
+ , viewportMode(viewportMode_)
{
}
@@ -39,7 +40,8 @@ void TransformState::getProjMatrix(mat4& projMatrix) const {
// After the rotateX, z values are in pixel units. Convert them to
// altitude unites. 1 altitude unit = the screen height.
- matrix::scale(projMatrix, projMatrix, 1, -1, 1.0f / (rotatedNorth() ? getWidth() : getHeight()));
+ const bool flippedY = viewportMode == ViewportMode::FlippedY;
+ matrix::scale(projMatrix, projMatrix, 1, flippedY ? 1 : -1, 1.0f / (rotatedNorth() ? getWidth() : getHeight()));
using NO = NorthOrientation;
switch (getNorthOrientation()) {
@@ -89,6 +91,12 @@ ConstrainMode TransformState::getConstrainMode() const {
return constrainMode;
}
+#pragma mark - ViewportMode
+
+ViewportMode TransformState::getViewportMode() const {
+ return viewportMode;
+}
+
#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 b9acad66f1..970dda2613 100644
--- a/src/mbgl/map/transform_state.hpp
+++ b/src/mbgl/map/transform_state.hpp
@@ -18,7 +18,7 @@ class TransformState {
friend class Transform;
public:
- TransformState(ConstrainMode = ConstrainMode::HeightOnly);
+ TransformState(ConstrainMode = ConstrainMode::HeightOnly, ViewportMode = ViewportMode::Default);
// Matrix
void matrixFor(mat4&, const UnwrappedTileID&) const;
@@ -31,10 +31,13 @@ public:
// North Orientation
NorthOrientation getNorthOrientation() const;
double getNorthOrientationAngle() const;
-
+
// Constrain mode
ConstrainMode getConstrainMode() const;
+ // Viewport mode
+ ViewportMode getViewportMode() const;
+
// Position
LatLng getLatLng(LatLng::WrapMode = LatLng::Unwrapped) const;
double pixel_x() const;
@@ -99,6 +102,7 @@ private:
private:
ConstrainMode constrainMode;
+ ViewportMode viewportMode;
// animation state
bool rotating = false;
diff --git a/src/mbgl/renderer/painter_symbol.cpp b/src/mbgl/renderer/painter_symbol.cpp
index a48c70866c..42355493a5 100644
--- a/src/mbgl/renderer/painter_symbol.cpp
+++ b/src/mbgl/renderer/painter_symbol.cpp
@@ -51,7 +51,8 @@ void Painter::renderSDF(SymbolBucket &bucket,
gammaScale = 1.0f;
matrix::rotate_z(exMatrix, exMatrix, state.getNorthOrientationAngle());
}
- matrix::scale(exMatrix, exMatrix, s, s, 1);
+ const bool flippedY = !skewed && state.getViewportMode() == ViewportMode::FlippedY;
+ matrix::scale(exMatrix, exMatrix, s, flippedY ? -s : s, 1);
// If layerStyle.size > bucket.info.fontSize then labels may collide
float fontSize = paintSize;
@@ -217,7 +218,8 @@ void Painter::renderSymbol(SymbolBucket& bucket,
matrix::rotate_z(exMatrix, exMatrix, state.getNorthOrientationAngle());
s = state.getAltitude();
}
- matrix::scale(exMatrix, exMatrix, s, s, 1);
+ const bool flippedY = !skewed && state.getViewportMode() == ViewportMode::FlippedY;
+ matrix::scale(exMatrix, exMatrix, s, flippedY ? -s : s, 1);
matrix::scale(exMatrix, exMatrix, fontScale, fontScale, 1.0f);
diff --git a/test/map/transform.cpp b/test/map/transform.cpp
index a3a62e7ad8..b9a905274a 100644
--- a/test/map/transform.cpp
+++ b/test/map/transform.cpp
@@ -8,7 +8,7 @@ using namespace mbgl;
TEST(Transform, InvalidScale) {
MockView view;
- Transform transform(view, ConstrainMode::HeightOnly);
+ Transform transform(view, ConstrainMode::HeightOnly, ViewportMode::Default);
ASSERT_DOUBLE_EQ(0, transform.getLatLng().latitude);
ASSERT_DOUBLE_EQ(0, transform.getLatLng().longitude);
@@ -48,7 +48,7 @@ TEST(Transform, InvalidScale) {
TEST(Transform, InvalidLatLng) {
MockView view;
- Transform transform(view, ConstrainMode::HeightOnly);
+ Transform transform(view, ConstrainMode::HeightOnly, ViewportMode::Default);
ASSERT_DOUBLE_EQ(0, transform.getLatLng().latitude);
ASSERT_DOUBLE_EQ(0, transform.getLatLng().longitude);
@@ -84,7 +84,7 @@ TEST(Transform, InvalidLatLng) {
TEST(Transform, InvalidBearing) {
MockView view;
- Transform transform(view, ConstrainMode::HeightOnly);
+ Transform transform(view, ConstrainMode::HeightOnly, ViewportMode::Default);
ASSERT_DOUBLE_EQ(0, transform.getLatLng().latitude);
ASSERT_DOUBLE_EQ(0, transform.getLatLng().longitude);
@@ -111,7 +111,7 @@ TEST(Transform, PerspectiveProjection) {
MockView view;
LatLng loc;
- Transform transform(view, ConstrainMode::HeightOnly);
+ Transform transform(view, ConstrainMode::HeightOnly, ViewportMode::Default);
transform.resize({{ 1000, 1000 }});
transform.setScale(2 << 9);
transform.setPitch(0.9);
@@ -142,7 +142,7 @@ TEST(Transform, PerspectiveProjection) {
TEST(Transform, UnwrappedLatLng) {
MockView view;
- Transform transform(view, ConstrainMode::HeightOnly);
+ Transform transform(view, ConstrainMode::HeightOnly, ViewportMode::Default);
transform.resize({{ 1000, 1000 }});
transform.setScale(2 << 9);
transform.setPitch(0.9);
@@ -175,7 +175,7 @@ TEST(Transform, ConstrainHeightOnly) {
MockView view;
LatLng loc;
- Transform transform(view, ConstrainMode::HeightOnly);
+ Transform transform(view, ConstrainMode::HeightOnly, ViewportMode::Default);
transform.resize({{ 1000, 1000 }});
transform.setScale(std::pow(2, util::MAX_ZOOM));
@@ -194,7 +194,7 @@ TEST(Transform, ConstrainWidthAndHeight) {
MockView view;
LatLng loc;
- Transform transform(view, ConstrainMode::WidthAndHeight);
+ Transform transform(view, ConstrainMode::WidthAndHeight, ViewportMode::Default);
transform.resize({{ 1000, 1000 }});
transform.setScale(std::pow(2, util::MAX_ZOOM));
@@ -211,7 +211,7 @@ TEST(Transform, ConstrainWidthAndHeight) {
TEST(Transform, Anchor) {
MockView view;
- Transform transform(view, ConstrainMode::HeightOnly);
+ Transform transform(view, ConstrainMode::HeightOnly, ViewportMode::Default);
transform.resize({{ 1000, 1000 }});
const LatLng latLng { 10, -100 };
@@ -312,7 +312,7 @@ TEST(Transform, Anchor) {
TEST(Transform, Padding) {
MockView view;
- Transform transform(view, ConstrainMode::HeightOnly);
+ Transform transform(view, ConstrainMode::HeightOnly, ViewportMode::Default);
transform.resize({{ 1000, 1000 }});
ASSERT_DOUBLE_EQ(0, transform.getLatLng().latitude);
@@ -350,7 +350,7 @@ TEST(Transform, Padding) {
TEST(Transform, MoveBy) {
MockView view;
- Transform transform(view, ConstrainMode::HeightOnly);
+ Transform transform(view, ConstrainMode::HeightOnly, ViewportMode::Default);
transform.resize({{ 1000, 1000 }});
transform.setLatLngZoom({ 0, 0 }, 10);
@@ -378,7 +378,7 @@ TEST(Transform, MoveBy) {
TEST(Transform, Antimeridian) {
MockView view;
- Transform transform(view, ConstrainMode::HeightOnly);
+ Transform transform(view, ConstrainMode::HeightOnly, ViewportMode::Default);
transform.resize({{ 1000, 1000 }});
transform.setLatLngZoom({ 0, 0 }, 1);
@@ -422,7 +422,7 @@ TEST(Transform, Antimeridian) {
TEST(Transform, Camera) {
MockView view;
- Transform transform(view, ConstrainMode::HeightOnly);
+ Transform transform(view, ConstrainMode::HeightOnly, ViewportMode::Default);
transform.resize({{ 1000, 1000 }});
const LatLng latLng1 { 45, 135 };
diff --git a/test/style/source.cpp b/test/style/source.cpp
index b520fcb6fd..156aff71ad 100644
--- a/test/style/source.cpp
+++ b/test/style/source.cpp
@@ -25,7 +25,7 @@ public:
StubFileSource fileSource;
StubStyleObserver observer;
MockView view;
- Transform transform { view, ConstrainMode::HeightOnly };
+ Transform transform { view, ConstrainMode::HeightOnly, ViewportMode::Default };
TransformState transformState;
Worker worker { 1 };
gl::TexturePool texturePool;
diff --git a/test/util/tile_cover.cpp b/test/util/tile_cover.cpp
index 2fde6da54b..a0cc8eb3eb 100644
--- a/test/util/tile_cover.cpp
+++ b/test/util/tile_cover.cpp
@@ -30,7 +30,7 @@ TEST(TileCover, WorldZ0) {
TEST(TileCover, Pitch) {
MockView view;
- Transform transform(view, ConstrainMode::HeightOnly);
+ Transform transform(view, ConstrainMode::HeightOnly, ViewportMode::Default);
transform.resize({ { 512, 512 } });
transform.setZoom(2);
transform.setPitch(40.0 * M_PI / 180.0);