summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThiago Marcos P. Santos <tmpsantos@gmail.com>2018-10-25 03:10:58 +0300
committerThiago Marcos P. Santos <tmpsantos@gmail.com>2018-10-25 03:15:43 +0300
commitcdbe554f13ad3f9893132ce9c9c7f3e22e5afcc9 (patch)
tree6552754aa33b9b7b29f9775252f3c1da374ec224
parent1b703ed634dc82610ce58c63fbf5a37dc40d9c86 (diff)
downloadqtlocation-mapboxgl-cdbe554f13ad3f9893132ce9c9c7f3e22e5afcc9.tar.gz
[build] Add test appupstream/tmpsantos-core_build
The app is need to fix linker issues.
-rw-r--r--core/CMakeLists.txt12
-rw-r--r--core/app.cpp67
2 files changed, 79 insertions, 0 deletions
diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt
index 4badc3d426..13e721851e 100644
--- a/core/CMakeLists.txt
+++ b/core/CMakeLists.txt
@@ -399,3 +399,15 @@ endif()
target_include_directories(mapbox-gl-native SYSTEM INTERFACE
${GIT_ROOT}/include
)
+
+add_executable(app
+ ${GIT_ROOT}/core/app.cpp
+)
+
+target_link_libraries(app PRIVATE
+ mapbox-gl-native
+)
+
+target_include_directories(app PRIVATE
+ ${GIT_ROOT}/platform/default
+)
diff --git a/core/app.cpp b/core/app.cpp
new file mode 100644
index 0000000000..539f29e57b
--- /dev/null
+++ b/core/app.cpp
@@ -0,0 +1,67 @@
+#include <mbgl/map/map.hpp>
+#include <mbgl/util/image.hpp>
+#include <mbgl/util/run_loop.hpp>
+#include <mbgl/util/default_styles.hpp>
+
+#include <mbgl/gl/headless_frontend.hpp>
+#include <mbgl/util/default_thread_pool.hpp>
+#include <mbgl/storage/default_file_source.hpp>
+#include <mbgl/style/style.hpp>
+
+#include <cstdlib>
+#include <iostream>
+#include <fstream>
+
+int main(int argc, char *argv[]) {
+ std::string style = mbgl::util::default_styles::streets.url;
+
+ const double lat = 0;
+ const double lon = 0;
+ const double zoom = 0;
+ const double bearing = 0;
+ const double pitch = 0;
+ const double pixelRatio = 1;
+
+ const uint32_t width = 512;
+ const uint32_t height = 512;
+ const std::string output = "out.png";
+ const std::string cache = "cache.sqlite";
+ const std::string asset = ".";
+
+ const char* tokenEnv = getenv("MAPBOX_ACCESS_TOKEN");
+ const std::string token = tokenEnv ? tokenEnv : std::string();
+
+ using namespace mbgl;
+
+ util::RunLoop loop;
+ DefaultFileSource fileSource(cache, asset);
+
+ // Set access token if present
+ if (token.size()) {
+ fileSource.setAccessToken(std::string(token));
+ }
+
+ ThreadPool threadPool(4);
+ HeadlessFrontend frontend({ width, height }, pixelRatio, fileSource, threadPool);
+ Map map(frontend, MapObserver::nullObserver(), frontend.getSize(), pixelRatio, fileSource, threadPool, MapMode::Static);
+
+ if (style.find("://") == std::string::npos) {
+ style = std::string("file://") + style;
+ }
+
+ map.getStyle().loadURL(style);
+ map.setLatLngZoom({ lat, lon }, zoom);
+ map.setBearing(bearing);
+ map.setPitch(pitch);
+
+ try {
+ std::ofstream out(output, std::ios::binary);
+ out << encodePNG(frontend.render(map));
+ out.close();
+ } catch(std::exception& e) {
+ std::cout << "Error: " << e.what() << std::endl;
+ exit(1);
+ }
+
+ return 0;
+}