Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[glfw] Add bounds example
Browse files Browse the repository at this point in the history
  • Loading branch information
brunoabinader committed Feb 26, 2019
1 parent e5ed9d9 commit 13fb375
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions platform/glfw/glfw_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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;
}
}

Expand Down

0 comments on commit 13fb375

Please sign in to comment.