@@ -121,10 +121,12 @@ void addFillExtrusionLayer(mbgl::style::Style &style, bool visible) {
|
||||
|
||||
void glfwError(int error, const char *description) {
|
||||
mbgl::Log::Error(mbgl::Event::OpenGL, std::string("GLFW error (") + std::to_string(error) + "): " + description);
|
||||
|
||||
}
|
||||
|
||||
GLFWView::GLFWView(bool fullscreen_, bool benchmark_, const mbgl::ResourceOptions &resourceOptions, const mbgl::ClientOptions &clientOptions)
|
||||
GLFWView::GLFWView(bool fullscreen_,
|
||||
bool benchmark_,
|
||||
const mbgl::ResourceOptions &resourceOptions,
|
||||
const mbgl::ClientOptions &clientOptions)
|
||||
: fullscreen(fullscreen_),
|
||||
benchmark(benchmark_),
|
||||
snapshotterObserver(std::make_unique<SnapshotObserver>()),
|
||||
@@ -199,7 +201,9 @@ GLFWView::GLFWView(bool fullscreen_, bool benchmark_, const mbgl::ResourceOption
|
||||
glfwMakeContextCurrent(nullptr);
|
||||
|
||||
printf("\n");
|
||||
printf("================================================================================\n");
|
||||
printf(
|
||||
"======================================================================"
|
||||
"==========\n");
|
||||
printf("\n");
|
||||
printf("- Press `S` to cycle through bundled styles\n");
|
||||
printf("- Press `X` to reset the transform\n");
|
||||
@@ -210,18 +214,29 @@ GLFWView::GLFWView(bool fullscreen_, bool benchmark_, const mbgl::ResourceOption
|
||||
printf("- Press `Z` to cycle through north orientations\n");
|
||||
printf("- Press `X` to cycle through the viewport modes\n");
|
||||
printf("- Press `I` to delete existing database and re-initialize\n");
|
||||
printf("- Press `A` to cycle through Mapbox offices in the world + dateline monument\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(
|
||||
"- Press `D` to cycle through camera bounds: inside, crossing IDL at "
|
||||
"left, crossing IDL at right, and "
|
||||
"disabled\n");
|
||||
printf("- Press `T` to add custom geometry source\n");
|
||||
printf("- Press `F` to enable feature-state demo\n");
|
||||
printf("- Press `U` to toggle pitch bounds\n");
|
||||
printf("- Press `H` to take a snapshot of a current map.\n");
|
||||
printf("- Press `J` to take a snapshot of a current map with an extrusions overlay.\n");
|
||||
printf(
|
||||
"- Press `J` to take a snapshot of a current map with an extrusions "
|
||||
"overlay.\n");
|
||||
printf("- Press `Y` to start a camera fly-by demo\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");
|
||||
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");
|
||||
printf("\n");
|
||||
printf("- Press `Q` to query annotations\n");
|
||||
printf("- Press `C` to remove annotations\n");
|
||||
@@ -238,7 +253,9 @@ GLFWView::GLFWView(bool fullscreen_, bool benchmark_, const mbgl::ResourceOption
|
||||
printf("- Press `Tab` to cycle through the map debug options\n");
|
||||
printf("- Press `Esc` to quit\n");
|
||||
printf("\n");
|
||||
printf("================================================================================\n");
|
||||
printf(
|
||||
"======================================================================"
|
||||
"==========\n");
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
@@ -252,7 +269,7 @@ void GLFWView::setMap(mbgl::Map *map_) {
|
||||
map->addAnnotationImage(makeImage("default_marker", 22, 22, 1));
|
||||
}
|
||||
|
||||
void GLFWView::setRenderFrontend(GLFWRendererFrontend* rendererFrontend_) {
|
||||
void GLFWView::setRenderFrontend(GLFWRendererFrontend *rendererFrontend_) {
|
||||
rendererFrontend = rendererFrontend_;
|
||||
}
|
||||
|
||||
@@ -284,231 +301,262 @@ void GLFWView::onKey(GLFWwindow *window, int key, int /*scancode*/, int action,
|
||||
case GLFW_KEY_S:
|
||||
if (view->changeStyleCallback) view->changeStyleCallback();
|
||||
break;
|
||||
case GLFW_KEY_N:
|
||||
if (!mods)
|
||||
view->map->easeTo(mbgl::CameraOptions().withBearing(0.0), mbgl::AnimationOptions {{mbgl::Milliseconds(500)}});
|
||||
break;
|
||||
case GLFW_KEY_Z:
|
||||
view->nextOrientation();
|
||||
break;
|
||||
case GLFW_KEY_Q: {
|
||||
auto result = view->rendererFrontend->getRenderer()->queryPointAnnotations({ {}, { static_cast<double>(view->getSize().width), static_cast<double>(view->getSize().height) } });
|
||||
printf("visible point annotations: %zu\n", result.size());
|
||||
auto features = view->rendererFrontend->getRenderer()->queryRenderedFeatures(
|
||||
mbgl::ScreenBox{{view->getSize().width * 0.5, view->getSize().height * 0.5},
|
||||
{view->getSize().width * 0.5 + 1.0, view->getSize().height * 0.5 + 1}},
|
||||
{});
|
||||
printf("Rendered features at the center of the screen: %zu\n", features.size());
|
||||
} break;
|
||||
case GLFW_KEY_P:
|
||||
view->pauseResumeCallback();
|
||||
break;
|
||||
case GLFW_KEY_C:
|
||||
view->clearAnnotations();
|
||||
break;
|
||||
case GLFW_KEY_I:
|
||||
view->resetDatabaseCallback();
|
||||
break;
|
||||
case GLFW_KEY_K:
|
||||
view->addRandomCustomPointAnnotations(1);
|
||||
break;
|
||||
case GLFW_KEY_L:
|
||||
view->addRandomLineAnnotations(1);
|
||||
break;
|
||||
case GLFW_KEY_A: {
|
||||
// XXX Fix precision loss in flyTo:
|
||||
// https://github.com/mapbox/mapbox-gl-native/issues/4298
|
||||
static const std::vector<mbgl::LatLng> places = {
|
||||
mbgl::LatLng { -16.796665, -179.999983 }, // Dateline monument
|
||||
mbgl::LatLng { 12.9810542, 77.6345551 }, // Mapbox Bengaluru, India
|
||||
mbgl::LatLng { -13.15607,-74.21773 }, // Mapbox Peru
|
||||
mbgl::LatLng { 37.77572, -122.4158818 }, // Mapbox SF, USA
|
||||
mbgl::LatLng { 38.91318,-77.03255 }, // Mapbox DC, USA
|
||||
};
|
||||
static size_t nextPlace = 0;
|
||||
mbgl::CameraOptions cameraOptions;
|
||||
cameraOptions.center = places[nextPlace++];
|
||||
cameraOptions.zoom = 20;
|
||||
cameraOptions.pitch = 30;
|
||||
|
||||
mbgl::AnimationOptions animationOptions(mbgl::Seconds(10));
|
||||
view->map->flyTo(cameraOptions, animationOptions);
|
||||
nextPlace = nextPlace % places.size();
|
||||
} break;
|
||||
case GLFW_KEY_R: {
|
||||
view->show3DExtrusions = true;
|
||||
view->toggle3DExtrusions(view->show3DExtrusions);
|
||||
if (view->animateRouteCallback) break;
|
||||
view->animateRouteCallback = [](mbgl::Map* routeMap) {
|
||||
static mapbox::cheap_ruler::CheapRuler ruler { 40.7 }; // New York
|
||||
static mapbox::geojson::geojson route { mapbox::geojson::parse(mbgl::platform::glfw::route) };
|
||||
const auto& geometry = route.get<mapbox::geometry::geometry<double>>();
|
||||
const auto& lineString = geometry.get<mapbox::geometry::line_string<double>>();
|
||||
|
||||
static double routeDistance = ruler.lineDistance(lineString);
|
||||
static double routeProgress = 0;
|
||||
routeProgress += 0.0005;
|
||||
if (routeProgress > 1.0) {
|
||||
routeProgress = 0.0;
|
||||
}
|
||||
|
||||
auto camera = routeMap->getCameraOptions();
|
||||
|
||||
auto point = ruler.along(lineString, routeProgress * routeDistance);
|
||||
const mbgl::LatLng center { point.y, point.x };
|
||||
auto latLng = *camera.center;
|
||||
double bearing = ruler.bearing({ latLng.longitude(), latLng.latitude() }, point);
|
||||
double easing = bearing - *camera.bearing;
|
||||
easing += easing > 180.0 ? -360.0 : easing < -180 ? 360.0 : 0;
|
||||
bearing = *camera.bearing + (easing / 20);
|
||||
routeMap->jumpTo(mbgl::CameraOptions().withCenter(center).withZoom(18.0).withBearing(bearing).withPitch(60.0));
|
||||
};
|
||||
view->animateRouteCallback(view->map);
|
||||
} break;
|
||||
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()};
|
||||
static size_t nextBound = 0u;
|
||||
static mbgl::AnnotationID boundAnnotationID = std::numeric_limits<mbgl::AnnotationID>::max();
|
||||
|
||||
mbgl::LatLngBounds bound = bounds[nextBound++];
|
||||
nextBound = nextBound % bounds.size();
|
||||
|
||||
view->map->setBounds(mbgl::BoundOptions().withLatLngBounds(bound));
|
||||
|
||||
if (bound == mbgl::LatLngBounds()) {
|
||||
view->map->removeAnnotation(boundAnnotationID);
|
||||
boundAnnotationID = std::numeric_limits<mbgl::AnnotationID>::max();
|
||||
} else {
|
||||
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;
|
||||
case GLFW_KEY_T:
|
||||
view->toggleCustomSource();
|
||||
break;
|
||||
case GLFW_KEY_F: {
|
||||
using namespace mbgl;
|
||||
using namespace mbgl::style;
|
||||
using namespace mbgl::style::expression::dsl;
|
||||
|
||||
auto &style = view->map->getStyle();
|
||||
if (!style.getSource("states")) {
|
||||
std::string url = "https://maplibre.org/maplibre-gl-js-docs/assets/us_states.geojson";
|
||||
auto source = std::make_unique<GeoJSONSource>("states");
|
||||
source->setURL(url);
|
||||
style.addSource(std::move(source));
|
||||
|
||||
case GLFW_KEY_N:
|
||||
if (!mods)
|
||||
view->map->easeTo(mbgl::CameraOptions().withBearing(0.0),
|
||||
mbgl::AnimationOptions{{mbgl::Milliseconds(500)}});
|
||||
break;
|
||||
case GLFW_KEY_Z:
|
||||
view->nextOrientation();
|
||||
break;
|
||||
case GLFW_KEY_Q: {
|
||||
auto result = view->rendererFrontend->getRenderer()->queryPointAnnotations(
|
||||
{{}, {static_cast<double>(view->getSize().width), static_cast<double>(view->getSize().height)}});
|
||||
printf("visible point annotations: %zu\n", result.size());
|
||||
auto features = view->rendererFrontend->getRenderer()->queryRenderedFeatures(
|
||||
mbgl::ScreenBox{{view->getSize().width * 0.5, view->getSize().height * 0.5},
|
||||
{view->getSize().width * 0.5 + 1.0, view->getSize().height * 0.5 + 1}},
|
||||
{});
|
||||
printf("Rendered features at the center of the screen: %zu\n", features.size());
|
||||
} break;
|
||||
case GLFW_KEY_P:
|
||||
view->pauseResumeCallback();
|
||||
break;
|
||||
case GLFW_KEY_C:
|
||||
view->clearAnnotations();
|
||||
break;
|
||||
case GLFW_KEY_I:
|
||||
view->resetDatabaseCallback();
|
||||
break;
|
||||
case GLFW_KEY_K:
|
||||
view->addRandomCustomPointAnnotations(1);
|
||||
break;
|
||||
case GLFW_KEY_L:
|
||||
view->addRandomLineAnnotations(1);
|
||||
break;
|
||||
case GLFW_KEY_A: {
|
||||
// XXX Fix precision loss in flyTo:
|
||||
// https://github.com/mapbox/mapbox-gl-native/issues/4298
|
||||
static const std::vector<mbgl::LatLng> places = {
|
||||
mbgl::LatLng{-16.796665, -179.999983}, // Dateline monument
|
||||
mbgl::LatLng{12.9810542, 77.6345551}, // Mapbox Bengaluru, India
|
||||
mbgl::LatLng{-13.15607, -74.21773}, // Mapbox Peru
|
||||
mbgl::LatLng{37.77572, -122.4158818}, // Mapbox SF, USA
|
||||
mbgl::LatLng{38.91318, -77.03255}, // Mapbox DC, USA
|
||||
};
|
||||
static size_t nextPlace = 0;
|
||||
mbgl::CameraOptions cameraOptions;
|
||||
cameraOptions.center = mbgl::LatLng{42.619626, -103.523181};
|
||||
cameraOptions.zoom = 3;
|
||||
cameraOptions.pitch = 0;
|
||||
cameraOptions.bearing = 0;
|
||||
view->map->jumpTo(cameraOptions);
|
||||
}
|
||||
cameraOptions.center = places[nextPlace++];
|
||||
cameraOptions.zoom = 20;
|
||||
cameraOptions.pitch = 30;
|
||||
|
||||
auto layer = style.getLayer("state-fills");
|
||||
if (!layer) {
|
||||
auto fillLayer = std::make_unique<FillLayer>("state-fills", "states");
|
||||
fillLayer->setFillColor(mbgl::Color{0.0, 0.0, 1.0, 0.5});
|
||||
fillLayer->setFillOpacity(PropertyExpression<float>(
|
||||
createExpression(R"(["case", ["boolean", ["feature-state", "hover"], false], 1, 0.5])")));
|
||||
style.addLayer(std::move(fillLayer));
|
||||
} else {
|
||||
layer->setVisibility(layer->getVisibility() == mbgl::style::VisibilityType::Visible
|
||||
? mbgl::style::VisibilityType::None
|
||||
: mbgl::style::VisibilityType::Visible);
|
||||
}
|
||||
mbgl::AnimationOptions animationOptions(mbgl::Seconds(10));
|
||||
view->map->flyTo(cameraOptions, animationOptions);
|
||||
nextPlace = nextPlace % places.size();
|
||||
} break;
|
||||
case GLFW_KEY_R: {
|
||||
view->show3DExtrusions = true;
|
||||
view->toggle3DExtrusions(view->show3DExtrusions);
|
||||
if (view->animateRouteCallback) break;
|
||||
view->animateRouteCallback = [](mbgl::Map *routeMap) {
|
||||
static mapbox::cheap_ruler::CheapRuler ruler{40.7}; // New York
|
||||
static mapbox::geojson::geojson route{mapbox::geojson::parse(mbgl::platform::glfw::route)};
|
||||
const auto &geometry = route.get<mapbox::geometry::geometry<double>>();
|
||||
const auto &lineString = geometry.get<mapbox::geometry::line_string<double>>();
|
||||
|
||||
layer = style.getLayer("state-borders");
|
||||
if (!layer) {
|
||||
auto borderLayer = std::make_unique<LineLayer>("state-borders", "states");
|
||||
borderLayer->setLineColor(mbgl::Color{0.0, 0.0, 1.0, 1.0});
|
||||
borderLayer->setLineWidth(PropertyExpression<float>(
|
||||
createExpression(R"(["case", ["boolean", ["feature-state", "hover"], false], 2, 1])")));
|
||||
style.addLayer(std::move(borderLayer));
|
||||
} else {
|
||||
layer->setVisibility(layer->getVisibility() == mbgl::style::VisibilityType::Visible
|
||||
? mbgl::style::VisibilityType::None
|
||||
: mbgl::style::VisibilityType::Visible);
|
||||
}
|
||||
} break;
|
||||
case GLFW_KEY_F1: {
|
||||
bool success = TestWriter()
|
||||
.withInitialSize(mbgl::Size(view->width, view->height))
|
||||
.withStyle(view->map->getStyle())
|
||||
.withCameraOptions(view->map->getCameraOptions())
|
||||
.write(view->testDirectory);
|
||||
static double routeDistance = ruler.lineDistance(lineString);
|
||||
static double routeProgress = 0;
|
||||
routeProgress += 0.0005;
|
||||
if (routeProgress > 1.0) {
|
||||
routeProgress = 0.0;
|
||||
}
|
||||
|
||||
if (success) {
|
||||
mbgl::Log::Info(mbgl::Event::General, "Render test created!");
|
||||
} else {
|
||||
mbgl::Log::Error(mbgl::Event::General,
|
||||
"Fail to create render test! Base directory does not exist or permission denied.");
|
||||
}
|
||||
} break;
|
||||
case GLFW_KEY_U: {
|
||||
auto bounds = view->map->getBounds();
|
||||
if (bounds.minPitch == mbgl::util::rad2deg(mbgl::util::PITCH_MIN) &&
|
||||
bounds.maxPitch == mbgl::util::rad2deg(mbgl::util::PITCH_MAX)) {
|
||||
mbgl::Log::Info(mbgl::Event::General, "Limiting pitch bounds to [30, 40] degrees");
|
||||
view->map->setBounds(mbgl::BoundOptions().withMinPitch(30).withMaxPitch(40));
|
||||
} else {
|
||||
mbgl::Log::Info(mbgl::Event::General, "Resetting pitch bounds to [0, 60] degrees");
|
||||
view->map->setBounds(mbgl::BoundOptions().withMinPitch(0).withMaxPitch(60));
|
||||
}
|
||||
} break;
|
||||
case GLFW_KEY_H: {
|
||||
view->makeSnapshot();
|
||||
} break;
|
||||
case GLFW_KEY_J: {
|
||||
// Snapshot with overlay
|
||||
view->makeSnapshot(true);
|
||||
} break;
|
||||
case GLFW_KEY_G: {
|
||||
view->toggleLocationIndicatorLayer();
|
||||
} break;
|
||||
case GLFW_KEY_Y: {
|
||||
view->freeCameraDemoPhase = 0;
|
||||
view->freeCameraDemoStartTime = mbgl::Clock::now();
|
||||
view->invalidate();
|
||||
} break;
|
||||
auto camera = routeMap->getCameraOptions();
|
||||
|
||||
auto point = ruler.along(lineString, routeProgress * routeDistance);
|
||||
const mbgl::LatLng center{point.y, point.x};
|
||||
auto latLng = *camera.center;
|
||||
double bearing = ruler.bearing({latLng.longitude(), latLng.latitude()}, point);
|
||||
double easing = bearing - *camera.bearing;
|
||||
easing += easing > 180.0 ? -360.0 : easing < -180 ? 360.0 : 0;
|
||||
bearing = *camera.bearing + (easing / 20);
|
||||
routeMap->jumpTo(
|
||||
mbgl::CameraOptions().withCenter(center).withZoom(18.0).withBearing(bearing).withPitch(60.0));
|
||||
};
|
||||
view->animateRouteCallback(view->map);
|
||||
} break;
|
||||
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()};
|
||||
static size_t nextBound = 0u;
|
||||
static mbgl::AnnotationID boundAnnotationID = std::numeric_limits<mbgl::AnnotationID>::max();
|
||||
|
||||
mbgl::LatLngBounds bound = bounds[nextBound++];
|
||||
nextBound = nextBound % bounds.size();
|
||||
|
||||
view->map->setBounds(mbgl::BoundOptions().withLatLngBounds(bound));
|
||||
|
||||
if (bound == mbgl::LatLngBounds()) {
|
||||
view->map->removeAnnotation(boundAnnotationID);
|
||||
boundAnnotationID = std::numeric_limits<mbgl::AnnotationID>::max();
|
||||
} else {
|
||||
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;
|
||||
case GLFW_KEY_T:
|
||||
view->toggleCustomSource();
|
||||
break;
|
||||
case GLFW_KEY_F: {
|
||||
using namespace mbgl;
|
||||
using namespace mbgl::style;
|
||||
using namespace mbgl::style::expression::dsl;
|
||||
|
||||
auto &style = view->map->getStyle();
|
||||
if (!style.getSource("states")) {
|
||||
std::string url =
|
||||
"https://maplibre.org/maplibre-gl-js-docs/assets/"
|
||||
"us_states.geojson";
|
||||
auto source = std::make_unique<GeoJSONSource>("states");
|
||||
source->setURL(url);
|
||||
style.addSource(std::move(source));
|
||||
|
||||
mbgl::CameraOptions cameraOptions;
|
||||
cameraOptions.center = mbgl::LatLng{42.619626, -103.523181};
|
||||
cameraOptions.zoom = 3;
|
||||
cameraOptions.pitch = 0;
|
||||
cameraOptions.bearing = 0;
|
||||
view->map->jumpTo(cameraOptions);
|
||||
}
|
||||
|
||||
auto layer = style.getLayer("state-fills");
|
||||
if (!layer) {
|
||||
auto fillLayer = std::make_unique<FillLayer>("state-fills", "states");
|
||||
fillLayer->setFillColor(mbgl::Color{0.0, 0.0, 1.0, 0.5});
|
||||
fillLayer->setFillOpacity(PropertyExpression<float>(
|
||||
createExpression(R"(["case", ["boolean", ["feature-state", "hover"], false], 1, 0.5])")));
|
||||
style.addLayer(std::move(fillLayer));
|
||||
} else {
|
||||
layer->setVisibility(layer->getVisibility() == mbgl::style::VisibilityType::Visible
|
||||
? mbgl::style::VisibilityType::None
|
||||
: mbgl::style::VisibilityType::Visible);
|
||||
}
|
||||
|
||||
layer = style.getLayer("state-borders");
|
||||
if (!layer) {
|
||||
auto borderLayer = std::make_unique<LineLayer>("state-borders", "states");
|
||||
borderLayer->setLineColor(mbgl::Color{0.0, 0.0, 1.0, 1.0});
|
||||
borderLayer->setLineWidth(PropertyExpression<float>(
|
||||
createExpression(R"(["case", ["boolean", ["feature-state", "hover"], false], 2, 1])")));
|
||||
style.addLayer(std::move(borderLayer));
|
||||
} else {
|
||||
layer->setVisibility(layer->getVisibility() == mbgl::style::VisibilityType::Visible
|
||||
? mbgl::style::VisibilityType::None
|
||||
: mbgl::style::VisibilityType::Visible);
|
||||
}
|
||||
} break;
|
||||
case GLFW_KEY_F1: {
|
||||
bool success = TestWriter()
|
||||
.withInitialSize(mbgl::Size(view->width, view->height))
|
||||
.withStyle(view->map->getStyle())
|
||||
.withCameraOptions(view->map->getCameraOptions())
|
||||
.write(view->testDirectory);
|
||||
|
||||
if (success) {
|
||||
mbgl::Log::Info(mbgl::Event::General, "Render test created!");
|
||||
} else {
|
||||
mbgl::Log::Error(mbgl::Event::General,
|
||||
"Fail to create render test! Base directory does not "
|
||||
"exist or permission denied.");
|
||||
}
|
||||
} break;
|
||||
case GLFW_KEY_U: {
|
||||
auto bounds = view->map->getBounds();
|
||||
if (bounds.minPitch == mbgl::util::rad2deg(mbgl::util::PITCH_MIN) &&
|
||||
bounds.maxPitch == mbgl::util::rad2deg(mbgl::util::PITCH_MAX)) {
|
||||
mbgl::Log::Info(mbgl::Event::General, "Limiting pitch bounds to [30, 40] degrees");
|
||||
view->map->setBounds(mbgl::BoundOptions().withMinPitch(30).withMaxPitch(40));
|
||||
} else {
|
||||
mbgl::Log::Info(mbgl::Event::General, "Resetting pitch bounds to [0, 60] degrees");
|
||||
view->map->setBounds(mbgl::BoundOptions().withMinPitch(0).withMaxPitch(60));
|
||||
}
|
||||
} break;
|
||||
case GLFW_KEY_H: {
|
||||
view->makeSnapshot();
|
||||
} break;
|
||||
case GLFW_KEY_J: {
|
||||
// Snapshot with overlay
|
||||
view->makeSnapshot(true);
|
||||
} break;
|
||||
case GLFW_KEY_G: {
|
||||
view->toggleLocationIndicatorLayer();
|
||||
} break;
|
||||
case GLFW_KEY_Y: {
|
||||
view->freeCameraDemoPhase = 0;
|
||||
view->freeCameraDemoStartTime = mbgl::Clock::now();
|
||||
view->invalidate();
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
if (action == GLFW_RELEASE || action == GLFW_REPEAT) {
|
||||
switch (key) {
|
||||
case GLFW_KEY_W: view->popAnnotation(); break;
|
||||
case GLFW_KEY_1: view->addRandomPointAnnotations(1); break;
|
||||
case GLFW_KEY_2: view->addRandomPointAnnotations(10); break;
|
||||
case GLFW_KEY_3: view->addRandomPointAnnotations(100); break;
|
||||
case GLFW_KEY_4: view->addRandomPointAnnotations(1000); break;
|
||||
case GLFW_KEY_5: view->addRandomPointAnnotations(10000); break;
|
||||
case GLFW_KEY_6: view->addRandomPointAnnotations(100000); break;
|
||||
case GLFW_KEY_7: view->addRandomShapeAnnotations(1); break;
|
||||
case GLFW_KEY_8: view->addRandomShapeAnnotations(10); break;
|
||||
case GLFW_KEY_9: view->addRandomShapeAnnotations(100); break;
|
||||
case GLFW_KEY_0: view->addRandomShapeAnnotations(1000); break;
|
||||
case GLFW_KEY_M: view->addAnimatedAnnotation(); break;
|
||||
case GLFW_KEY_W:
|
||||
view->popAnnotation();
|
||||
break;
|
||||
case GLFW_KEY_1:
|
||||
view->addRandomPointAnnotations(1);
|
||||
break;
|
||||
case GLFW_KEY_2:
|
||||
view->addRandomPointAnnotations(10);
|
||||
break;
|
||||
case GLFW_KEY_3:
|
||||
view->addRandomPointAnnotations(100);
|
||||
break;
|
||||
case GLFW_KEY_4:
|
||||
view->addRandomPointAnnotations(1000);
|
||||
break;
|
||||
case GLFW_KEY_5:
|
||||
view->addRandomPointAnnotations(10000);
|
||||
break;
|
||||
case GLFW_KEY_6:
|
||||
view->addRandomPointAnnotations(100000);
|
||||
break;
|
||||
case GLFW_KEY_7:
|
||||
view->addRandomShapeAnnotations(1);
|
||||
break;
|
||||
case GLFW_KEY_8:
|
||||
view->addRandomShapeAnnotations(10);
|
||||
break;
|
||||
case GLFW_KEY_9:
|
||||
view->addRandomShapeAnnotations(100);
|
||||
break;
|
||||
case GLFW_KEY_0:
|
||||
view->addRandomShapeAnnotations(1000);
|
||||
break;
|
||||
case GLFW_KEY_M:
|
||||
view->addAnimatedAnnotation();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -563,18 +611,20 @@ mbgl::Color GLFWView::makeRandomColor() const {
|
||||
const auto r = static_cast<float>(std::rand()) / static_cast<float>(RAND_MAX);
|
||||
const auto g = static_cast<float>(std::rand()) / static_cast<float>(RAND_MAX);
|
||||
const auto b = static_cast<float>(std::rand()) / static_cast<float>(RAND_MAX);
|
||||
return { r, g, b, 1.0f };
|
||||
return {r, g, b, 1.0f};
|
||||
}
|
||||
|
||||
mbgl::Point<double> GLFWView::makeRandomPoint() const {
|
||||
const double x = width * static_cast<double>(std::rand()) / RAND_MAX;
|
||||
const double y = height * static_cast<double>(std::rand()) / RAND_MAX;
|
||||
mbgl::LatLng latLng = map->latLngForPixel({ x, y });
|
||||
return { latLng.longitude(), latLng.latitude() };
|
||||
mbgl::LatLng latLng = map->latLngForPixel({x, y});
|
||||
return {latLng.longitude(), latLng.latitude()};
|
||||
}
|
||||
|
||||
std::unique_ptr<mbgl::style::Image>
|
||||
GLFWView::makeImage(const std::string& id, int width, int height, float pixelRatio) {
|
||||
std::unique_ptr<mbgl::style::Image> GLFWView::makeImage(const std::string &id,
|
||||
int width,
|
||||
int height,
|
||||
float pixelRatio) {
|
||||
const int r = static_cast<int>(255 * (static_cast<double>(std::rand()) / RAND_MAX));
|
||||
const int g = static_cast<int>(255 * (static_cast<double>(std::rand()) / RAND_MAX));
|
||||
const int b = static_cast<int>(255 * (static_cast<double>(std::rand()) / RAND_MAX));
|
||||
@@ -582,8 +632,8 @@ GLFWView::makeImage(const std::string& id, int width, int height, float pixelRat
|
||||
const int w = static_cast<int>(std::ceil(pixelRatio * width));
|
||||
const int h = static_cast<int>(std::ceil(pixelRatio * height));
|
||||
|
||||
mbgl::PremultipliedImage image({ static_cast<uint32_t>(w), static_cast<uint32_t>(h) });
|
||||
auto data = reinterpret_cast<uint32_t*>(image.data.get());
|
||||
mbgl::PremultipliedImage image({static_cast<uint32_t>(w), static_cast<uint32_t>(h)});
|
||||
auto data = reinterpret_cast<uint32_t *>(image.data.get());
|
||||
const int dist = (w / 2) * (w / 2);
|
||||
for (int y = 0; y < h; y++) {
|
||||
for (int x = 0; x < w; x++) {
|
||||
@@ -593,8 +643,7 @@ GLFWView::makeImage(const std::string& id, int width, int height, float pixelRat
|
||||
if (diff > 0) {
|
||||
const int a = std::min(0xFF, diff) * 0xFF / dist;
|
||||
// Premultiply the rgb values with alpha
|
||||
data[w * y + x] =
|
||||
(a << 24) | ((a * r / 0xFF) << 16) | ((a * g / 0xFF) << 8) | (a * b / 0xFF);
|
||||
data[w * y + x] = (a << 24) | ((a * r / 0xFF) << 16) | ((a * g / 0xFF) << 8) | (a * b / 0xFF);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -605,26 +654,34 @@ GLFWView::makeImage(const std::string& id, int width, int height, float pixelRat
|
||||
void GLFWView::nextOrientation() {
|
||||
using NO = mbgl::NorthOrientation;
|
||||
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;
|
||||
default: map->setNorthOrientation(NO::Upwards); break;
|
||||
case NO::Upwards:
|
||||
map->setNorthOrientation(NO::Rightwards);
|
||||
break;
|
||||
case NO::Rightwards:
|
||||
map->setNorthOrientation(NO::Downwards);
|
||||
break;
|
||||
case NO::Downwards:
|
||||
map->setNorthOrientation(NO::Leftwards);
|
||||
break;
|
||||
default:
|
||||
map->setNorthOrientation(NO::Upwards);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void GLFWView::addRandomCustomPointAnnotations(int count) {
|
||||
for (int i = 0; i < count; i++) {
|
||||
static int spriteID = 1;
|
||||
const auto name = std::string{ "marker-" } + mbgl::util::toString(spriteID++);
|
||||
const auto name = std::string{"marker-"} + mbgl::util::toString(spriteID++);
|
||||
map->addAnnotationImage(makeImage(name, 22, 22, 1));
|
||||
spriteIDs.push_back(name);
|
||||
annotationIDs.push_back(map->addAnnotation(mbgl::SymbolAnnotation { makeRandomPoint(), name }));
|
||||
annotationIDs.push_back(map->addAnnotation(mbgl::SymbolAnnotation{makeRandomPoint(), name}));
|
||||
}
|
||||
}
|
||||
|
||||
void GLFWView::addRandomPointAnnotations(int count) {
|
||||
for (int i = 0; i < count; ++i) {
|
||||
annotationIDs.push_back(map->addAnnotation(mbgl::SymbolAnnotation { makeRandomPoint(), "default_marker" }));
|
||||
annotationIDs.push_back(map->addAnnotation(mbgl::SymbolAnnotation{makeRandomPoint(), "default_marker"}));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -634,21 +691,22 @@ void GLFWView::addRandomLineAnnotations(int count) {
|
||||
for (int j = 0; j < 3; ++j) {
|
||||
lineString.push_back(makeRandomPoint());
|
||||
}
|
||||
annotationIDs.push_back(map->addAnnotation(mbgl::LineAnnotation { lineString, 1.0f, 2.0f, { makeRandomColor() } }));
|
||||
annotationIDs.push_back(map->addAnnotation(mbgl::LineAnnotation{lineString, 1.0f, 2.0f, {makeRandomColor()}}));
|
||||
}
|
||||
}
|
||||
|
||||
void GLFWView::addRandomShapeAnnotations(int count) {
|
||||
for (int i = 0; i < count; ++i) {
|
||||
mbgl::Polygon<double> triangle;
|
||||
triangle.push_back({ makeRandomPoint(), makeRandomPoint(), makeRandomPoint() });
|
||||
annotationIDs.push_back(map->addAnnotation(mbgl::FillAnnotation { triangle, 0.5f, { makeRandomColor() }, { makeRandomColor() } }));
|
||||
triangle.push_back({makeRandomPoint(), makeRandomPoint(), makeRandomPoint()});
|
||||
annotationIDs.push_back(
|
||||
map->addAnnotation(mbgl::FillAnnotation{triangle, 0.5f, {makeRandomColor()}, {makeRandomColor()}}));
|
||||
}
|
||||
}
|
||||
|
||||
void GLFWView::addAnimatedAnnotation() {
|
||||
const double started = glfwGetTime();
|
||||
animatedAnnotationIDs.push_back(map->addAnnotation(mbgl::SymbolAnnotation { { 0, 0 } , "default_marker" }));
|
||||
animatedAnnotationIDs.push_back(map->addAnnotation(mbgl::SymbolAnnotation{{0, 0}, "default_marker"}));
|
||||
animatedAnnotationAddedTimes.push_back(started);
|
||||
}
|
||||
|
||||
@@ -659,8 +717,8 @@ void GLFWView::updateAnimatedAnnotations() {
|
||||
|
||||
const double period = 10;
|
||||
const double x = dt / period * 360 - 180;
|
||||
const double y = std::sin(dt/ period * M_PI * 2.0) * 80;
|
||||
map->updateAnnotation(animatedAnnotationIDs[i], mbgl::SymbolAnnotation { {x, y }, "default_marker" });
|
||||
const double y = std::sin(dt / period * M_PI * 2.0) * 80;
|
||||
map->updateAnnotation(animatedAnnotationIDs[i], mbgl::SymbolAnnotation{{x, y}, "default_marker"});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -684,13 +742,13 @@ void GLFWView::cycleDebugOptions() {
|
||||
}
|
||||
|
||||
void GLFWView::clearAnnotations() {
|
||||
for (const auto& id : annotationIDs) {
|
||||
for (const auto &id : annotationIDs) {
|
||||
map->removeAnnotation(id);
|
||||
}
|
||||
|
||||
annotationIDs.clear();
|
||||
|
||||
for (const auto& id : animatedAnnotationIDs) {
|
||||
for (const auto &id : animatedAnnotationIDs) {
|
||||
map->removeAnnotation(id);
|
||||
}
|
||||
|
||||
@@ -708,8 +766,11 @@ void GLFWView::popAnnotation() {
|
||||
|
||||
void GLFWView::makeSnapshot(bool withOverlay) {
|
||||
if (!snapshotter || snapshotter->getStyleURL() != map->getStyle().getURL()) {
|
||||
snapshotter = std::make_unique<mbgl::MapSnapshotter>(
|
||||
map->getMapOptions().size(), map->getMapOptions().pixelRatio(), mapResourceOptions, mapClientOptions, *snapshotterObserver);
|
||||
snapshotter = std::make_unique<mbgl::MapSnapshotter>(map->getMapOptions().size(),
|
||||
map->getMapOptions().pixelRatio(),
|
||||
mapResourceOptions,
|
||||
mapClientOptions,
|
||||
*snapshotterObserver);
|
||||
snapshotter->setStyleURL(map->getStyle().getURL());
|
||||
}
|
||||
|
||||
@@ -722,7 +783,8 @@ void GLFWView::makeSnapshot(bool withOverlay) {
|
||||
const mbgl::MapSnapshotter::LatLngForFn &) {
|
||||
if (!ptr) {
|
||||
std::ostringstream oss;
|
||||
oss << "Made snapshot './snapshot.png' with size w:" << image.size.width << "px h:" << image.size.height << "px";
|
||||
oss << "Made snapshot './snapshot.png' with size w:" << image.size.width << "px h:" << image.size.height
|
||||
<< "px";
|
||||
mbgl::Log::Info(mbgl::Event::General, oss.str());
|
||||
std::ofstream file("./snapshot.png");
|
||||
file << mbgl::encodePNG(image);
|
||||
@@ -761,7 +823,7 @@ void GLFWView::onScroll(GLFWwindow *window, double /*xOffset*/, double yOffset)
|
||||
scale = 1.0 / scale;
|
||||
}
|
||||
|
||||
view->map->scaleBy(scale, mbgl::ScreenCoordinate { view->lastX, view->lastY });
|
||||
view->map->scaleBy(scale, mbgl::ScreenCoordinate{view->lastX, view->lastY});
|
||||
#if defined(MBGL_RENDER_BACKEND_OPENGL) && !defined(MBGL_LAYER_CUSTOM_DISABLE_ALL)
|
||||
if (view->puck && view->puckFollowsCameraCenter) {
|
||||
mbgl::LatLng mapCenter = view->map->getCameraOptions().center.value();
|
||||
@@ -774,25 +836,24 @@ void GLFWView::onWindowResize(GLFWwindow *window, int width, int height) {
|
||||
auto *view = reinterpret_cast<GLFWView *>(glfwGetWindowUserPointer(window));
|
||||
view->width = width;
|
||||
view->height = height;
|
||||
view->map->setSize({ static_cast<uint32_t>(view->width), static_cast<uint32_t>(view->height) });
|
||||
view->map->setSize({static_cast<uint32_t>(view->width), static_cast<uint32_t>(view->height)});
|
||||
}
|
||||
|
||||
void GLFWView::onFramebufferResize(GLFWwindow *window, int width, int height) {
|
||||
auto *view = reinterpret_cast<GLFWView *>(glfwGetWindowUserPointer(window));
|
||||
view->backend->setSize({ static_cast<uint32_t>(width), static_cast<uint32_t>(height) });
|
||||
view->backend->setSize({static_cast<uint32_t>(width), static_cast<uint32_t>(height)});
|
||||
|
||||
// This is only triggered when the framebuffer is resized, but not the window. It can
|
||||
// happen when you move the window between screens with a different pixel ratio.
|
||||
// We are forcing a repaint my invalidating the view, which triggers a rerender with the
|
||||
// new framebuffer dimensions.
|
||||
// This is only triggered when the framebuffer is resized, but not the
|
||||
// window. It can happen when you move the window between screens with a
|
||||
// different pixel ratio. We are forcing a repaint my invalidating the view,
|
||||
// which triggers a rerender with the new framebuffer dimensions.
|
||||
view->invalidate();
|
||||
}
|
||||
|
||||
void GLFWView::onMouseClick(GLFWwindow *window, int button, int action, int modifiers) {
|
||||
auto *view = reinterpret_cast<GLFWView *>(glfwGetWindowUserPointer(window));
|
||||
|
||||
if (button == GLFW_MOUSE_BUTTON_RIGHT ||
|
||||
(button == GLFW_MOUSE_BUTTON_LEFT && modifiers & GLFW_MOD_CONTROL)) {
|
||||
if (button == GLFW_MOUSE_BUTTON_RIGHT || (button == GLFW_MOUSE_BUTTON_LEFT && modifiers & GLFW_MOD_CONTROL)) {
|
||||
view->rotating = action == GLFW_PRESS;
|
||||
view->map->setGestureInProgress(view->rotating);
|
||||
} else if (button == GLFW_MOUSE_BUTTON_LEFT && (modifiers & GLFW_MOD_SHIFT)) {
|
||||
@@ -806,9 +867,13 @@ void GLFWView::onMouseClick(GLFWwindow *window, int button, int action, int modi
|
||||
double now = glfwGetTime();
|
||||
if (now - view->lastClick < 0.4 /* ms */) {
|
||||
if (modifiers & GLFW_MOD_SHIFT) {
|
||||
view->map->scaleBy(0.5, mbgl::ScreenCoordinate { view->lastX, view->lastY }, mbgl::AnimationOptions{{mbgl::Milliseconds(500)}});
|
||||
view->map->scaleBy(0.5,
|
||||
mbgl::ScreenCoordinate{view->lastX, view->lastY},
|
||||
mbgl::AnimationOptions{{mbgl::Milliseconds(500)}});
|
||||
} else {
|
||||
view->map->scaleBy(2.0, mbgl::ScreenCoordinate { view->lastX, view->lastY }, mbgl::AnimationOptions{{mbgl::Milliseconds(500)}});
|
||||
view->map->scaleBy(2.0,
|
||||
mbgl::ScreenCoordinate{view->lastX, view->lastY},
|
||||
mbgl::AnimationOptions{{mbgl::Milliseconds(500)}});
|
||||
}
|
||||
}
|
||||
view->lastClick = now;
|
||||
@@ -822,10 +887,10 @@ void GLFWView::onMouseMove(GLFWwindow *window, double x, double y) {
|
||||
const double dx = x - view->lastX;
|
||||
const double dy = y - view->lastY;
|
||||
if (dx || dy) {
|
||||
view->map->moveBy(mbgl::ScreenCoordinate { dx, dy });
|
||||
view->map->moveBy(mbgl::ScreenCoordinate{dx, dy});
|
||||
}
|
||||
} else if (view->rotating) {
|
||||
view->map->rotateBy({ view->lastX, view->lastY }, { x, y });
|
||||
view->map->rotateBy({view->lastX, view->lastY}, {x, y});
|
||||
} else if (view->pitching) {
|
||||
const double dy = y - view->lastY;
|
||||
if (dy) {
|
||||
@@ -896,12 +961,11 @@ void GLFWView::run() {
|
||||
dirty = false;
|
||||
const double started = glfwGetTime();
|
||||
|
||||
if (animateRouteCallback)
|
||||
animateRouteCallback(map);
|
||||
if (animateRouteCallback) animateRouteCallback(map);
|
||||
|
||||
updateAnimatedAnnotations();
|
||||
|
||||
mbgl::gfx::BackendScope scope { backend->getRendererBackend() };
|
||||
mbgl::gfx::BackendScope scope{backend->getRendererBackend()};
|
||||
|
||||
rendererFrontend->render();
|
||||
|
||||
@@ -929,7 +993,7 @@ float GLFWView::getPixelRatio() const {
|
||||
}
|
||||
|
||||
mbgl::Size GLFWView::getSize() const {
|
||||
return { static_cast<uint32_t>(width), static_cast<uint32_t>(height) };
|
||||
return {static_cast<uint32_t>(width), static_cast<uint32_t>(height)};
|
||||
}
|
||||
|
||||
void GLFWView::invalidate() {
|
||||
@@ -965,8 +1029,8 @@ void GLFWView::setShouldClose() {
|
||||
glfwPostEmptyEvent();
|
||||
}
|
||||
|
||||
void GLFWView::setWindowTitle(const std::string& title) {
|
||||
glfwSetWindowTitle(window, (std::string { "Mapbox GL: " } + title).c_str());
|
||||
void GLFWView::setWindowTitle(const std::string &title) {
|
||||
glfwSetWindowTitle(window, (std::string{"Mapbox GL: "} + title).c_str());
|
||||
}
|
||||
|
||||
void GLFWView::onDidFinishLoadingStyle() {
|
||||
@@ -987,13 +1051,15 @@ void GLFWView::toggle3DExtrusions(bool visible) {
|
||||
void GLFWView::toggleCustomSource() {
|
||||
if (!map->getStyle().getSource("custom")) {
|
||||
mbgl::style::CustomGeometrySource::Options options;
|
||||
options.cancelTileFunction = [](const mbgl::CanonicalTileID&) {};
|
||||
options.fetchTileFunction = [&](const mbgl::CanonicalTileID& tileID) {
|
||||
options.cancelTileFunction = [](const mbgl::CanonicalTileID &) {
|
||||
};
|
||||
options.fetchTileFunction = [&](const mbgl::CanonicalTileID &tileID) {
|
||||
double gridSpacing = 0.1;
|
||||
mbgl::FeatureCollection features;
|
||||
const mbgl::LatLngBounds bounds(tileID);
|
||||
for (double y = ceil(bounds.north() / gridSpacing) * gridSpacing; y >= floor(bounds.south() / gridSpacing) * gridSpacing; y -= gridSpacing) {
|
||||
|
||||
for (double y = ceil(bounds.north() / gridSpacing) * gridSpacing;
|
||||
y >= floor(bounds.south() / gridSpacing) * gridSpacing;
|
||||
y -= gridSpacing) {
|
||||
mapbox::geojson::line_string gridLine;
|
||||
gridLine.emplace_back(bounds.west(), y);
|
||||
gridLine.emplace_back(bounds.east(), y);
|
||||
@@ -1001,7 +1067,9 @@ void GLFWView::toggleCustomSource() {
|
||||
features.emplace_back(gridLine);
|
||||
}
|
||||
|
||||
for (double x = floor(bounds.west() / gridSpacing) * gridSpacing; x <= ceil(bounds.east() / gridSpacing) * gridSpacing; x += gridSpacing) {
|
||||
for (double x = floor(bounds.west() / gridSpacing) * gridSpacing;
|
||||
x <= ceil(bounds.east() / gridSpacing) * gridSpacing;
|
||||
x += gridSpacing) {
|
||||
mapbox::geojson::line_string gridLine;
|
||||
gridLine.emplace_back(x, bounds.south());
|
||||
gridLine.emplace_back(x, bounds.north());
|
||||
@@ -1017,15 +1085,16 @@ void GLFWView::toggleCustomSource() {
|
||||
map->getStyle().addSource(std::make_unique<mbgl::style::CustomGeometrySource>("custom", options));
|
||||
}
|
||||
|
||||
auto* layer = map->getStyle().getLayer("grid");
|
||||
auto *layer = map->getStyle().getLayer("grid");
|
||||
|
||||
if (!layer) {
|
||||
auto lineLayer = std::make_unique<mbgl::style::LineLayer>("grid", "custom");
|
||||
lineLayer->setLineColor(mbgl::Color{ 1.0, 0.0, 0.0, 1.0 });
|
||||
lineLayer->setLineColor(mbgl::Color{1.0, 0.0, 0.0, 1.0});
|
||||
map->getStyle().addLayer(std::move(lineLayer));
|
||||
} else {
|
||||
layer->setVisibility(layer->getVisibility() == mbgl::style::VisibilityType::Visible ?
|
||||
mbgl::style::VisibilityType::None : mbgl::style::VisibilityType::Visible);
|
||||
layer->setVisibility(layer->getVisibility() == mbgl::style::VisibilityType::Visible
|
||||
? mbgl::style::VisibilityType::None
|
||||
: mbgl::style::VisibilityType::Visible);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1036,10 +1105,11 @@ void GLFWView::toggleLocationIndicatorLayer() {
|
||||
if (puck == nullptr) {
|
||||
auto puckLayer = std::make_unique<mbgl::style::LocationIndicatorLayer>("puck");
|
||||
|
||||
puckLayer->setLocationTransition(mbgl::style::TransitionOptions(
|
||||
mbgl::Duration::zero(), mbgl::Duration::zero())); // Note: This is used here for demo purpose.
|
||||
// SDKs should not use this, or else the location
|
||||
// will "jump" to positions.
|
||||
puckLayer->setLocationTransition(
|
||||
mbgl::style::TransitionOptions(mbgl::Duration::zero(),
|
||||
mbgl::Duration::zero())); // Note: This is used here for demo purpose.
|
||||
// SDKs should not use this, or else the location
|
||||
// will "jump" to positions.
|
||||
puckLayer->setLocation(toArray(puckLocation));
|
||||
puckLayer->setAccuracyRadius(50);
|
||||
puckLayer->setAccuracyRadiusColor(
|
||||
|
||||
Reference in New Issue
Block a user