diff options
author | Thiago Marcos P. Santos <thiago@mapbox.com> | 2016-02-24 23:15:27 +0200 |
---|---|---|
committer | Thiago Marcos P. Santos <thiago@mapbox.com> | 2016-03-02 15:30:37 -0300 |
commit | 2b0749e3c6a4e87b6ad4a9978b1be93f1d57fc21 (patch) | |
tree | 9498c54d7a67d2db85a6c24b8fe25a17af23e041 /bin | |
parent | 7d0dea8dadb4c5cb6da986bccc55634c26d2a209 (diff) | |
download | qtlocation-mapboxgl-2b0749e3c6a4e87b6ad4a9978b1be93f1d57fc21.tar.gz |
[offline] Accept parameters
The defaults remains the same: Bay area at zoom 15.
The key, if not supplied, is taken from the environment.
```
Allowed options:
-s [ --style ] URL Map stylesheet
--north degrees (=37.200000000000003) North latitude
--west degrees (=-122.8) West longitude
--south degrees (=38.100000000000001) South latitude
--east degrees (=-121.7) East longitude
--minZoom number (=0) Min zoom level
--maxZoom number (=15) Max zoom level
--pixelRatio number (=1) Pixel ratio
-t [ --token ] key Mapbox access token
-o [ --output ] file (=offline.db) Output database file name
```
Diffstat (limited to 'bin')
-rw-r--r-- | bin/offline.cpp | 52 | ||||
-rw-r--r-- | bin/offline.gypi | 5 |
2 files changed, 50 insertions, 7 deletions
diff --git a/bin/offline.cpp b/bin/offline.cpp index 7d69273b51..c03149d2f5 100644 --- a/bin/offline.cpp +++ b/bin/offline.cpp @@ -1,3 +1,4 @@ +#include <mbgl/util/default_styles.hpp> #include <mbgl/util/run_loop.hpp> #include <mbgl/util/string.hpp> #include <mbgl/util/io.hpp> @@ -7,20 +8,57 @@ #include <cstdlib> #include <iostream> +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wunknown-pragmas" +#pragma GCC diagnostic ignored "-Wunused-local-typedefs" +#pragma GCC diagnostic ignored "-Wshadow" +#include <boost/program_options.hpp> +#pragma GCC diagnostic pop + +namespace po = boost::program_options; using namespace std::literals::chrono_literals; -int main(int, char * []) { - using namespace mbgl; +int main(int argc, char *argv[]) { + std::string style = mbgl::util::default_styles::streets.url; + double north = 37.2, west = -122.8, south = 38.1, east = -121.7; // Bay area + double minZoom = 0.0, maxZoom = 15.0, pixelRatio = 1.0; + std::string output = "offline.db"; + + const char* tokenEnv = getenv("MAPBOX_ACCESS_TOKEN"); + std::string token = tokenEnv ? tokenEnv : std::string(); + + po::options_description desc("Allowed options"); + desc.add_options() + ("style,s", po::value(&style)->value_name("URL"), "Map stylesheet") + ("north", po::value(&north)->value_name("degrees")->default_value(north), "North latitude") + ("west", po::value(&west)->value_name("degrees")->default_value(west), "West longitude") + ("south", po::value(&south)->value_name("degrees")->default_value(south), "South latitude") + ("east", po::value(&east)->value_name("degrees")->default_value(east), "East longitude") + ("minZoom", po::value(&minZoom)->value_name("number")->default_value(minZoom), "Min zoom level") + ("maxZoom", po::value(&maxZoom)->value_name("number")->default_value(maxZoom), "Max zoom level") + ("pixelRatio", po::value(&pixelRatio)->value_name("number")->default_value(pixelRatio), "Pixel ratio") + ("token,t", po::value(&token)->value_name("key")->default_value(token), "Mapbox access token") + ("output,o", po::value(&output)->value_name("file")->default_value(output), "Output database file name") + ; + + try { + po::variables_map vm; + po::store(po::parse_command_line(argc, argv, desc), vm); + po::notify(vm); + } catch(std::exception& e) { + std::cout << "Error: " << e.what() << std::endl << desc; + exit(1); + } - unlink("offline.db"); + using namespace mbgl; util::RunLoop loop; - DefaultFileSource fileSource("offline.db", "."); - fileSource.setAccessToken(getenv("MAPBOX_ACCESS_TOKEN")); + DefaultFileSource fileSource(output, "."); + fileSource.setAccessToken(token); - LatLngBounds bayArea = LatLngBounds::hull(LatLng(37.2, -122.8), LatLng(38.1, -121.7)); - OfflineTilePyramidRegionDefinition definition("mapbox://styles/mapbox/streets-v8", bayArea, 0, 15, 1.0); + LatLngBounds boundingBox = LatLngBounds::hull(LatLng(north, west), LatLng(south, east)); + OfflineTilePyramidRegionDefinition definition(style, boundingBox, minZoom, maxZoom, pixelRatio); OfflineRegionMetadata metadata; class Observer : public OfflineRegionObserver { diff --git a/bin/offline.gypi b/bin/offline.gypi index b5980ae76d..885a199b36 100644 --- a/bin/offline.gypi +++ b/bin/offline.gypi @@ -28,15 +28,20 @@ 'cflags_cc': [ '<@(boost_cflags)', ], + 'libraries': [ + '<@(boost_libprogram_options_static_libs)' + ], }, 'conditions': [ ['OS == "mac"', { + 'libraries': [ '<@(libraries)' ], 'xcode_settings': { 'OTHER_CPLUSPLUSFLAGS': [ '<@(cflags_cc)' ], } }, { 'cflags_cc': [ '<@(cflags_cc)' ], + 'libraries': [ '<@(libraries)' ], }] ], }, |