From 2b0749e3c6a4e87b6ad4a9978b1be93f1d57fc21 Mon Sep 17 00:00:00 2001 From: "Thiago Marcos P. Santos" Date: Wed, 24 Feb 2016 23:15:27 +0200 Subject: [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 ``` --- bin/offline.cpp | 52 +++++++++++++++++++++++++++++++++++++++++++++------- bin/offline.gypi | 5 +++++ 2 files changed, 50 insertions(+), 7 deletions(-) (limited to 'bin') 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 #include #include #include @@ -7,20 +8,57 @@ #include #include +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wunknown-pragmas" +#pragma GCC diagnostic ignored "-Wunused-local-typedefs" +#pragma GCC diagnostic ignored "-Wshadow" +#include +#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)' ], }] ], }, -- cgit v1.2.1