diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2017-07-26 16:09:17 +0200 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2017-09-22 10:57:15 +0200 |
commit | 3a8dc12a8e9396ff54b06d5207164a97968fd8a5 (patch) | |
tree | 25c79a3875c69cd0bf8e9228bfc828b5131ae191 /platform | |
parent | bd553de7bc5899a8e4a3a9c5e1d27a9f4d10e90e (diff) | |
download | qtlocation-mapboxgl-3a8dc12a8e9396ff54b06d5207164a97968fd8a5.tar.gz |
[glfw] Always load settings, and allow CLI args to override them
Diffstat (limited to 'platform')
-rw-r--r-- | platform/glfw/main.cpp | 44 |
1 files changed, 14 insertions, 30 deletions
diff --git a/platform/glfw/main.cpp b/platform/glfw/main.cpp index 997831cb77..76c843c953 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); |