[core] map snapshotter - add mutators
This commit is contained in:
committed by
Ivo van Dongen
parent
a815c16ab3
commit
d37144d2f8
@@ -20,6 +20,18 @@ public:
|
||||
const optional<LatLngBounds> region,
|
||||
const optional<std::string> programCacheDir);
|
||||
|
||||
void setStyleURL(std::string styleURL);
|
||||
std::string getStyleURL() const;
|
||||
|
||||
void setSize(Size);
|
||||
Size getSize() const;
|
||||
|
||||
void setCameraOptions(CameraOptions);
|
||||
CameraOptions getCameraOptions() const;
|
||||
|
||||
void setRegion(LatLngBounds);
|
||||
LatLngBounds getRegion() const;
|
||||
|
||||
void snapshot(ActorRef<MapSnapshotter::Callback>);
|
||||
|
||||
private:
|
||||
@@ -44,9 +56,7 @@ MapSnapshotter::Impl::Impl(FileSource& fileSource,
|
||||
|
||||
// Set region, if specified
|
||||
if (region) {
|
||||
mbgl::EdgeInsets insets = { 0, 0, 0, 0 };
|
||||
std::vector<LatLng> latLngs = { region->southwest(), region->northeast() };
|
||||
map.jumpTo(map.cameraForLatLngs(latLngs, insets));
|
||||
this->setRegion(*region);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,6 +66,41 @@ void MapSnapshotter::Impl::snapshot(ActorRef<MapSnapshotter::Callback> callback)
|
||||
});
|
||||
}
|
||||
|
||||
void MapSnapshotter::Impl::setStyleURL(std::string styleURL) {
|
||||
map.getStyle().loadURL(styleURL);
|
||||
}
|
||||
|
||||
std::string MapSnapshotter::Impl::getStyleURL() const {
|
||||
return map.getStyle().getURL();
|
||||
}
|
||||
|
||||
void MapSnapshotter::Impl::setSize(Size size) {
|
||||
map.setSize(size);
|
||||
}
|
||||
|
||||
Size MapSnapshotter::Impl::getSize() const {
|
||||
return map.getSize();
|
||||
}
|
||||
|
||||
void MapSnapshotter::Impl::setCameraOptions(CameraOptions cameraOptions) {
|
||||
map.jumpTo(cameraOptions);
|
||||
}
|
||||
|
||||
CameraOptions MapSnapshotter::Impl::getCameraOptions() const {
|
||||
EdgeInsets insets;
|
||||
return map.getCameraOptions(insets);
|
||||
}
|
||||
|
||||
void MapSnapshotter::Impl::setRegion(LatLngBounds region) {
|
||||
mbgl::EdgeInsets insets = { 0, 0, 0, 0 };
|
||||
std::vector<LatLng> latLngs = { region.southwest(), region.northeast() };
|
||||
map.jumpTo(map.cameraForLatLngs(latLngs, insets));
|
||||
}
|
||||
|
||||
LatLngBounds MapSnapshotter::Impl::getRegion() const {
|
||||
return map.latLngBoundsForCamera(getCameraOptions());
|
||||
}
|
||||
|
||||
MapSnapshotter::MapSnapshotter(FileSource& fileSource,
|
||||
Scheduler& scheduler,
|
||||
const std::string& styleURL,
|
||||
@@ -70,7 +115,39 @@ MapSnapshotter::MapSnapshotter(FileSource& fileSource,
|
||||
MapSnapshotter::~MapSnapshotter() = default;
|
||||
|
||||
void MapSnapshotter::snapshot(ActorRef<MapSnapshotter::Callback> callback) {
|
||||
impl->actor().invoke(&Impl::snapshot, std::move(callback));
|
||||
impl->actor().invoke(&Impl::snapshot, std::move(callback));
|
||||
}
|
||||
|
||||
void MapSnapshotter::setStyleURL(const std::string& styleURL) {
|
||||
impl->actor().invoke(&Impl::setStyleURL, styleURL);
|
||||
}
|
||||
|
||||
std::string MapSnapshotter::getStyleURL() const {
|
||||
return impl->actor().ask(&Impl::getStyleURL).get();
|
||||
}
|
||||
|
||||
void MapSnapshotter::setSize(const Size& size) {
|
||||
impl->actor().invoke(&Impl::setSize, size);
|
||||
}
|
||||
|
||||
Size MapSnapshotter::getSize() const {
|
||||
return impl->actor().ask(&Impl::getSize).get();
|
||||
}
|
||||
|
||||
void MapSnapshotter::setCameraOptions(const CameraOptions& options) {
|
||||
impl->actor().invoke(&Impl::setCameraOptions, options);
|
||||
}
|
||||
|
||||
CameraOptions MapSnapshotter::getCameraOptions() const {
|
||||
return impl->actor().ask(&Impl::getCameraOptions).get();
|
||||
}
|
||||
|
||||
void MapSnapshotter::setRegion(const LatLngBounds& bounds) {
|
||||
impl->actor().invoke(&Impl::setRegion, std::move(bounds));
|
||||
}
|
||||
|
||||
LatLngBounds MapSnapshotter::getRegion() const {
|
||||
return impl->actor().ask(&Impl::getRegion).get();
|
||||
}
|
||||
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <mbgl/util/optional.hpp>
|
||||
|
||||
#include <exception>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <functional>
|
||||
|
||||
@@ -16,6 +17,10 @@ class FileSource;
|
||||
class Size;
|
||||
class LatLngBounds;
|
||||
|
||||
namespace style {
|
||||
class Style;
|
||||
} // namespace style
|
||||
|
||||
class MapSnapshotter {
|
||||
public:
|
||||
MapSnapshotter(FileSource& fileSource,
|
||||
@@ -29,6 +34,18 @@ public:
|
||||
|
||||
~MapSnapshotter();
|
||||
|
||||
void setStyleURL(const std::string& styleURL);
|
||||
std::string getStyleURL() const;
|
||||
|
||||
void setSize(const Size&);
|
||||
Size getSize() const;
|
||||
|
||||
void setCameraOptions(const CameraOptions&);
|
||||
CameraOptions getCameraOptions() const;
|
||||
|
||||
void setRegion(const LatLngBounds&);
|
||||
LatLngBounds getRegion() const;
|
||||
|
||||
using Callback = std::function<void (std::exception_ptr, PremultipliedImage)>;
|
||||
void snapshot(ActorRef<Callback>);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user