diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2017-07-26 16:09:17 +0200 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2017-07-26 16:09:17 +0200 |
commit | 48e7b7e890941764b2f742649df273c70adbb7bc (patch) | |
tree | 6c6901e8a613ad6ca7758eb26724b16478fdd78e | |
parent | 8d3647317cefc0c1190ca80a7dc411cb4498f5f8 (diff) | |
download | qtlocation-mapboxgl-48e7b7e890941764b2f742649df273c70adbb7bc.tar.gz |
[glfw] Always load settings, and allow CLI args to override them
-rw-r--r-- | platform/glfw/main.cpp | 42 |
1 files changed, 13 insertions, 29 deletions
diff --git a/platform/glfw/main.cpp b/platform/glfw/main.cpp index 6418ddcf78..b2d6404262 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'}, @@ -72,24 +72,19 @@ int main(int argc, char *argv[]) { style = std::string("asset://") + 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; @@ -127,20 +122,11 @@ int main(int argc, char *argv[]) { backend.setMap(&map); - // 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; @@ -193,9 +179,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); |