From 408946a6ab8ad8b859868fa545dd39ba1d87a212 Mon Sep 17 00:00:00 2001 From: Nathan Gass Date: Thu, 19 Aug 2021 20:51:58 +0200 Subject: [PATCH] Fix platform linux (#133) * minimal changes to get platform linux to compile again * adapt mbgl-glfw api for keyss to mbgl-offline and mbgl-render, use maptiler configuration for all three binaries --- bin/render.cpp | 7 +++-- .../src/mbgl/storage/http_file_source.cpp | 9 +++--- platform/glfw/main.cpp | 30 +++++++++---------- render-test/file_source.cpp | 4 +-- 4 files changed, 25 insertions(+), 25 deletions(-) diff --git a/bin/render.cpp b/bin/render.cpp index 1680e1c44..5417bfc88 100644 --- a/bin/render.cpp +++ b/bin/render.cpp @@ -2,7 +2,6 @@ #include #include #include -#include #include #include @@ -53,7 +52,6 @@ int main(int argc, char *argv[]) { exit(2); } - std::string style = styleValue ? args::get(styleValue) : mbgl::util::default_styles::streets.url; const double lat = latValue ? args::get(latValue) : 0; const double lon = lonValue ? args::get(lonValue) : 0; const double zoom = zoomValue ? args::get(zoomValue) : 0; @@ -75,12 +73,15 @@ int main(int argc, char *argv[]) { using namespace mbgl; + auto mapTilerConfiguration = mbgl::TileServerOptions::MapTilerConfiguration(); + std::string style = styleValue ? args::get(styleValue) : mapTilerConfiguration.defaultStyles().at(0).getUrl(); + util::RunLoop loop; HeadlessFrontend frontend({ width, height }, pixelRatio); Map map(frontend, MapObserver::nullObserver(), MapOptions().withMapMode(MapMode::Static).withSize(frontend.getSize()).withPixelRatio(pixelRatio), - ResourceOptions().withCachePath(cache_file).withAssetPath(asset_root).withApiKey(std::string(apikey))); + ResourceOptions().withCachePath(cache_file).withAssetPath(asset_root).withApiKey(apikey).withTileServerOptions(mapTilerConfiguration)); if (style.find("://") == std::string::npos) { style = std::string("file://") + style; diff --git a/platform/default/src/mbgl/storage/http_file_source.cpp b/platform/default/src/mbgl/storage/http_file_source.cpp index 7b875c137..687ac49f7 100644 --- a/platform/default/src/mbgl/storage/http_file_source.cpp +++ b/platform/default/src/mbgl/storage/http_file_source.cpp @@ -1,5 +1,4 @@ #include -#include #include #include #include @@ -233,14 +232,14 @@ int HTTPFileSource::Impl::startTimeout(CURLM * /* multi */, long timeout_ms, voi return 0; } -void HTTPFileSource::setResourceOptions(ResourceOptions options) { +void HTTPFileSource::Impl::setResourceOptions(ResourceOptions options) { std::lock_guard lock(resourceOptionsMutex); resourceOptions = options; } -ResourceOptions& HTTPFileSource::getResourceOptions() { +ResourceOptions HTTPFileSource::Impl::getResourceOptions() { std::lock_guard lock(resourceOptionsMutex); - return resourceOptions; + return resourceOptions.clone(); } HTTPRequest::HTTPRequest(HTTPFileSource::Impl* context_, Resource resource_, FileSource::Callback callback_) @@ -439,7 +438,7 @@ void HTTPFileSource::setResourceOptions(ResourceOptions options) { impl->setResourceOptions(options.clone()); } -ResourceOptions& HTTPFileSource::getResourceOptions() { +ResourceOptions HTTPFileSource::getResourceOptions() { return impl->getResourceOptions(); } diff --git a/platform/glfw/main.cpp b/platform/glfw/main.cpp index c9df6d269..f926bb667 100644 --- a/platform/glfw/main.cpp +++ b/platform/glfw/main.cpp @@ -7,7 +7,6 @@ #include #include #include -#include #include #include #include @@ -47,6 +46,7 @@ int main(int argc, char *argv[]) { args::ValueFlag testDirValue( argumentParser, "directory", "Root directory for test generation", {"testDir"}); args::ValueFlag backendValue(argumentParser, "backend", "Rendering backend", {"backend"}); + args::ValueFlag apikeyValue(argumentParser, "key", "API key", {'t', "apikey"}); args::ValueFlag styleValue(argumentParser, "URL", "Map stylesheet", {'s', "style"}); args::ValueFlag cacheDBValue(argumentParser, "file", "Cache database file name", {'c', "cache"}); args::ValueFlag lonValue(argumentParser, "degrees", "Longitude", {'x', "lon"}); @@ -96,13 +96,13 @@ int main(int argc, char *argv[]) { } // Set access token if present - std::string token(getenv("MAPBOX_ACCESS_TOKEN") ?: ""); - if (token.empty()) { - mbgl::Log::Warning(mbgl::Event::Setup, "no access token set. mapbox.com tiles won't work."); - } + const char* apikeyEnv = getenv("MGL_API_KEY"); + const std::string apikey = apikeyValue ? args::get(apikeyValue) : (apikeyEnv ? apikeyEnv : std::string()); + auto mapTilerConfiguration = mbgl::TileServerOptions::MapTilerConfiguration(); mbgl::ResourceOptions resourceOptions; - resourceOptions.withCachePath(cacheDB).withApiKey(token); + resourceOptions.withCachePath(cacheDB).withApiKey(apikey).withTileServerOptions(mapTilerConfiguration); + auto orderedStyles = mapTilerConfiguration.defaultStyles(); GLFWView backend(fullscreen, benchmark, resourceOptions); view = &backend; @@ -150,18 +150,18 @@ int main(int argc, char *argv[]) { mbgl::Log::Info(mbgl::Event::Setup, "Application is %s. Press `O` to toggle online status.", settings.online ? "online" : "offline"); }); - view->setChangeStyleCallback([&map] () { + view->setChangeStyleCallback([&map,&orderedStyles] () { static uint8_t currentStyleIndex; - if (++currentStyleIndex == mbgl::util::default_styles::numOrderedStyles) { + if (++currentStyleIndex == orderedStyles.size()) { currentStyleIndex = 0; } - mbgl::util::default_styles::DefaultStyle newStyle = mbgl::util::default_styles::orderedStyles[currentStyleIndex]; - map.getStyle().loadURL(newStyle.url); - view->setWindowTitle(newStyle.name); + mbgl::util::DefaultStyle newStyle = orderedStyles[currentStyleIndex]; + map.getStyle().loadURL(newStyle.getUrl()); + view->setWindowTitle(newStyle.getName()); - mbgl::Log::Info(mbgl::Event::Setup, "Changed style to: %s", newStyle.name); + mbgl::Log::Info(mbgl::Event::Setup, "Changed style to: %s", newStyle.getName().c_str()); }); // Resource loader controls top-level request processing and can resume / pause all managed sources simultaneously. @@ -194,9 +194,9 @@ int main(int argc, char *argv[]) { if (style.empty()) { const char *url = getenv("MAPBOX_STYLE_URL"); if (url == nullptr) { - mbgl::util::default_styles::DefaultStyle newStyle = mbgl::util::default_styles::orderedStyles[0]; - style = newStyle.url; - view->setWindowTitle(newStyle.name); + mbgl::util::DefaultStyle newStyle = orderedStyles[0]; + style = newStyle.getUrl(); + view->setWindowTitle(newStyle.getName()); } else { style = url; view->setWindowTitle(url); diff --git a/render-test/file_source.cpp b/render-test/file_source.cpp index f840cfb03..f01cb264c 100644 --- a/render-test/file_source.cpp +++ b/render-test/file_source.cpp @@ -79,8 +79,8 @@ void ProxyFileSource::setResourceOptions(ResourceOptions options) { resourceOptions = options; } -ResourceOptions& ProxyFileSource::getResourceOptions() { - return resourceOptions; +ResourceOptions ProxyFileSource::getResourceOptions() { + return resourceOptions.clone(); }