summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruno de Oliveira Abinader <bruno@mapbox.com>2019-02-26 11:01:45 +0200
committerBruno de Oliveira Abinader <bruno@mapbox.com>2019-02-26 21:17:31 +0200
commit13fb375823f1365f87056cea09ab4525e2880fd2 (patch)
tree4301c0e0bf7a7c876855c037e7f28d81bc1f498f
parente5ed9d9ddfaf0fe48d2bb987127b69c42ce49ae0 (diff)
downloadqtlocation-mapboxgl-13fb375823f1365f87056cea09ab4525e2880fd2.tar.gz
[glfw] Add bounds example
-rw-r--r--platform/glfw/glfw_view.cpp40
1 files changed, 40 insertions, 0 deletions
diff --git a/platform/glfw/glfw_view.cpp b/platform/glfw/glfw_view.cpp
index d0c8a7be76..97c4cde657 100644
--- a/platform/glfw/glfw_view.cpp
+++ b/platform/glfw/glfw_view.cpp
@@ -12,6 +12,7 @@
#include <mbgl/util/platform.hpp>
#include <mbgl/util/string.hpp>
#include <mbgl/util/chrono.hpp>
+#include <mbgl/util/geo.hpp>
#include <mbgl/renderer/renderer.hpp>
#include <mbgl/renderer/backend_scope.hpp>
#include <mbgl/map/camera.hpp>
@@ -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,44 @@ 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<mbgl::LatLngBounds> 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 = 0u;
+ static mbgl::AnnotationID boundAnnotationID = std::numeric_limits<mbgl::AnnotationID>::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<mbgl::AnnotationID>::max();
+ break;
+ } else {
+ view->map->setLatLngBounds(bound);
+ }
+
+ mbgl::Polygon<double> rect;
+ rect.push_back({
+ mbgl::Point<double>{ bound.west(), bound.north() },
+ mbgl::Point<double>{ bound.east(), bound.north() },
+ mbgl::Point<double>{ bound.east(), bound.south() },
+ mbgl::Point<double>{ bound.west(), bound.south() },
+ });
+
+ auto boundAnnotation = mbgl::FillAnnotation { rect, 0.5f, { view->makeRandomColor() }, { view->makeRandomColor() } };
+
+ if (boundAnnotationID == std::numeric_limits<mbgl::AnnotationID>::max()) {
+ boundAnnotationID = view->map->addAnnotation(boundAnnotation);
+ } else {
+ view->map->updateAnnotation(boundAnnotationID, boundAnnotation);
+ }
+ } break;
}
}