From 3a8dc12a8e9396ff54b06d5207164a97968fd8a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20K=C3=A4fer?= Date: Wed, 26 Jul 2017 16:09:17 +0200 Subject: [PATCH] [glfw] Always load settings, and allow CLI args to override them --- platform/glfw/main.cpp | 44 ++++++++++++++---------------------------- 1 file changed, 14 insertions(+), 30 deletions(-) diff --git a/platform/glfw/main.cpp b/platform/glfw/main.cpp index 997831cb7..76c843c95 100644 --- a/platform/glfw/main.cpp +++ b/platform/glfw/main.cpp @@ -34,12 +34,12 @@ void quit_handler(int) { } int main(int argc, char *argv[]) { + // Load settings + mbgl::Settings_JSON settings; + bool fullscreen = false; bool benchmark = false; std::string style; - double latitude = 0, longitude = 0; - double bearing = 0, zoom = 1, pitch = 0; - bool skipConfig = false; const struct option long_options[] = { {"fullscreen", no_argument, nullptr, 'f'}, @@ -69,24 +69,19 @@ int main(int argc, char *argv[]) { style = std::string(optarg); break; case 'x': - longitude = atof(optarg); - skipConfig = true; + settings.longitude = atof(optarg); break; case 'y': - latitude = atof(optarg); - skipConfig = true; + settings.latitude = atof(optarg); break; case 'z': - zoom = atof(optarg); - skipConfig = true; + settings.zoom = atof(optarg); break; case 'r': - bearing = atof(optarg); - skipConfig = true; + settings.bearing = atof(optarg); break; case 'p': - pitch = atof(optarg); - skipConfig = true; + settings.pitch = atof(optarg); break; default: break; @@ -124,24 +119,15 @@ int main(int argc, char *argv[]) { backend.setMap(&map); - if (style.find("://") == std::string::npos) { + if (!style.empty() && style.find("://") == std::string::npos) { style = std::string("file://") + style; } - // Load settings - mbgl::Settings_JSON settings; + map.setLatLngZoom(mbgl::LatLng(settings.latitude, settings.longitude), settings.zoom); + map.setBearing(settings.bearing); + map.setPitch(settings.pitch); + map.setDebug(mbgl::MapDebugOptions(settings.debug)); - if (skipConfig) { - map.setLatLngZoom(mbgl::LatLng(latitude, longitude), zoom); - map.setBearing(bearing); - map.setPitch(pitch); - mbgl::Log::Info(mbgl::Event::General, "Location: %f/%f (z%.2f, %.2f deg)", latitude, longitude, zoom, bearing); - } else { - map.setLatLngZoom(mbgl::LatLng(settings.latitude, settings.longitude), settings.zoom); - map.setBearing(settings.bearing); - map.setPitch(settings.pitch); - map.setDebug(mbgl::MapDebugOptions(settings.debug)); - } view->setChangeStyleCallback([&map] () { static uint8_t currentStyleIndex; @@ -194,9 +180,7 @@ int main(int argc, char *argv[]) { settings.bearing = map.getBearing(); settings.pitch = map.getPitch(); settings.debug = mbgl::EnumType(map.getDebug()); - if (!skipConfig) { - settings.save(); - } + settings.save(); mbgl::Log::Info(mbgl::Event::General, R"(Exit location: --lat="%f" --lon="%f" --zoom="%f" --bearing "%f")", settings.latitude, settings.longitude, settings.zoom, settings.bearing);