summaryrefslogtreecommitdiff
path: root/platform/default/mbgl/map/map_snapshotter.cpp
diff options
context:
space:
mode:
authorIvo van Dongen <info@ivovandongen.nl>2017-10-09 16:49:29 +0300
committerFabian Guerra Soto <fabian.guerra@mapbox.com>2017-11-01 09:23:53 -0400
commitb3834447ff6006e865cec754de31be280cbae3f6 (patch)
treea460e0f86956dc1e09ebfa3efc5d73e791b236e4 /platform/default/mbgl/map/map_snapshotter.cpp
parentdf7755fcd98f98ed546cc02b1ada6feda66a3125 (diff)
downloadqtlocation-mapboxgl-b3834447ff6006e865cec754de31be280cbae3f6.tar.gz
[default] map snapshotter - add function to get screen coordinate from latlng for snapshot
- Wraps the TransformState for the snapshot so that the snapshotter itself is free to be re-used or destroyed
Diffstat (limited to 'platform/default/mbgl/map/map_snapshotter.cpp')
-rw-r--r--platform/default/mbgl/map/map_snapshotter.cpp21
1 files changed, 20 insertions, 1 deletions
diff --git a/platform/default/mbgl/map/map_snapshotter.cpp b/platform/default/mbgl/map/map_snapshotter.cpp
index e542e2fb54..3e930c31f1 100644
--- a/platform/default/mbgl/map/map_snapshotter.cpp
+++ b/platform/default/mbgl/map/map_snapshotter.cpp
@@ -3,9 +3,11 @@
#include <mbgl/actor/actor_ref.hpp>
#include <mbgl/gl/headless_frontend.hpp>
#include <mbgl/map/map.hpp>
+#include <mbgl/map/transform_state.hpp>
#include <mbgl/storage/file_source.hpp>
#include <mbgl/style/style.hpp>
#include <mbgl/util/event.hpp>
+#include <mbgl/map/transform.hpp>
namespace mbgl {
@@ -62,7 +64,24 @@ MapSnapshotter::Impl::Impl(FileSource& fileSource,
void MapSnapshotter::Impl::snapshot(ActorRef<MapSnapshotter::Callback> callback) {
map.renderStill([this, callback = std::move(callback)] (std::exception_ptr error) mutable {
- callback.invoke(&MapSnapshotter::Callback::operator(), error, error ? PremultipliedImage() : frontend.readStillImage());
+
+ // Create lambda that captures the current transform state
+ // and can be used to translate for geographic to screen
+ // coordinates
+ assert (frontend.getTransformState());
+ PointForFn pointForFn { [=, center=map.getLatLng(), transformState = *frontend.getTransformState()] (const LatLng& latLng) {
+ LatLng unwrappedLatLng = latLng.wrapped();
+ unwrappedLatLng.unwrapForShortestPath(center);
+ Transform transform { transformState };
+ return transform.latLngToScreenCoordinate(unwrappedLatLng);
+ }};
+
+ callback.invoke(
+ &MapSnapshotter::Callback::operator(),
+ error,
+ error ? PremultipliedImage() : frontend.readStillImage(),
+ std::move(pointForFn)
+ );
});
}