summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIvo van Dongen <info@ivovandongen.nl>2017-10-09 16:49:29 +0300
committerIvo van Dongen <ivovandongen@users.noreply.github.com>2017-10-31 19:52:08 +0200
commit87b735aaf71557b157a092a8025e6126ed2d8611 (patch)
tree87c02b5364fda184f0017237c97331b677332686
parent316f2bed4b49ea575f4a36ed000d3b43345f0d45 (diff)
downloadqtlocation-mapboxgl-87b735aaf71557b157a092a8025e6126ed2d8611.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
-rw-r--r--platform/default/mbgl/map/map_snapshotter.cpp21
-rw-r--r--platform/default/mbgl/map/map_snapshotter.hpp4
2 files changed, 23 insertions, 2 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)
+ );
});
}
diff --git a/platform/default/mbgl/map/map_snapshotter.hpp b/platform/default/mbgl/map/map_snapshotter.hpp
index 2450fa7612..b3cfb3058f 100644
--- a/platform/default/mbgl/map/map_snapshotter.hpp
+++ b/platform/default/mbgl/map/map_snapshotter.hpp
@@ -3,6 +3,7 @@
#include <mbgl/util/image.hpp>
#include <mbgl/util/thread.hpp>
#include <mbgl/util/optional.hpp>
+#include <mbgl/util/geo.hpp>
#include <exception>
#include <memory>
@@ -46,7 +47,8 @@ public:
void setRegion(const LatLngBounds&);
LatLngBounds getRegion() const;
- using Callback = std::function<void (std::exception_ptr, PremultipliedImage)>;
+ using PointForFn = std::function<ScreenCoordinate (const LatLng&)>;
+ using Callback = std::function<void (std::exception_ptr, PremultipliedImage, PointForFn)>;
void snapshot(ActorRef<Callback>);
private: