From a360f2bd6d483951a8d42391bc745ec389d69ec4 Mon Sep 17 00:00:00 2001 From: Bruno de Oliveira Abinader Date: Tue, 26 Feb 2019 11:01:45 +0200 Subject: [glfw] Add bounds example --- platform/glfw/glfw_view.cpp | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/platform/glfw/glfw_view.cpp b/platform/glfw/glfw_view.cpp index d0c8a7be76..fc6611941e 100644 --- a/platform/glfw/glfw_view.cpp +++ b/platform/glfw/glfw_view.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -122,6 +123,7 @@ GLFWView::GLFWView(bool fullscreen_, bool benchmark_) 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("- Press `B` to cycle through the color, stencil, and depth buffer\n"); + printf("- Press `D` to cycle through camera bounds: inside, crossing IDL at left, crossing IDL at right, and disabled\n"); printf("\n"); printf("- Press `1` through `6` to add increasing numbers of point annotations for testing\n"); printf("- Press `7` through `0` to add increasing numbers of shape annotations for testing\n"); @@ -279,6 +281,45 @@ void GLFWView::onKey(GLFWwindow *window, int key, int /*scancode*/, int action, case GLFW_KEY_E: view->toggle3DExtrusions(!view->show3DExtrusions); break; + case GLFW_KEY_D: { + static const std::vector bounds = { + mbgl::LatLngBounds::hull(mbgl::LatLng { -45.0, -170.0 }, mbgl::LatLng { 45.0, 170.0 }), // inside + mbgl::LatLngBounds::hull(mbgl::LatLng { -45.0, -200.0 }, mbgl::LatLng { 45.0, -160.0 }), // left IDL + mbgl::LatLngBounds::hull(mbgl::LatLng { -45.0, 160.0 }, mbgl::LatLng { 45.0, 200.0 }), // right IDL + mbgl::LatLngBounds::world() + }; + static size_t nextBound = 0; + static mbgl::AnnotationID boundAnnotationID = std::numeric_limits::max(); + + mbgl::LatLngBounds bound = bounds[nextBound++]; + nextBound = nextBound % bounds.size(); + + if (bound == mbgl::LatLngBounds::world()) { + view->map->setLatLngBounds({}); + view->map->removeAnnotation(boundAnnotationID); + boundAnnotationID = std::numeric_limits::max(); + break; + } else { + view->map->setLatLngBounds(bound); + } + + mbgl::Polygon rect; + rect.push_back({ + mbgl::Point{ bound.west(), bound.north() }, + mbgl::Point{ bound.east(), bound.north() }, + mbgl::Point{ bound.east(), bound.south() }, + mbgl::Point{ bound.west(), bound.south() }, + }); + + auto boundAnnotation = mbgl::FillAnnotation { rect, 0.5f, { view->makeRandomColor() }, { view->makeRandomColor() } }; + + if (boundAnnotationID == std::numeric_limits::max()) { + boundAnnotationID = view->map->addAnnotation(boundAnnotation); + printf("boundAnnotationID: %ld\n", boundAnnotationID); + } else { + view->map->updateAnnotation(boundAnnotationID, boundAnnotation); + } + } break; } } -- cgit v1.2.1