Support extra annotations for snapshotter for iOS (#3963)

Co-authored-by: Wei Chen <wei.chen@grabtaxi.com>
Co-authored-by: Stefan Karschti <4198736+stefankarschti@users.noreply.github.com>
This commit is contained in:
Wei Chen
2025-11-25 18:20:38 +08:00
committed by GitHub
parent 5a0c5f9f97
commit 7f81af1d0b
6 changed files with 300 additions and 1 deletions

View File

@@ -7,9 +7,18 @@
#include <mbgl/util/client_options.hpp>
#include <mbgl/util/run_loop.hpp>
#include <mbgl/util/timer.hpp>
#include <mbgl/util/io.hpp>
using namespace mbgl;
static PremultipliedImage namedImage(const std::string& name) {
return decodeImage(util::read_file("test/fixtures/sprites/" + name + ".png"));
}
static std::unique_ptr<style::Image> namedMarker(const std::string& name) {
return std::make_unique<style::Image>(name, namedImage(name), 1.0f);
}
class SnapshotterObserver final : public MapSnapshotterObserver {
public:
~SnapshotterObserver() = default;
@@ -137,3 +146,31 @@ TEST(MapSnapshotter, TEST_REQUIRES_SERVER(runtimeStyling)) {
runLoop.run();
}
TEST(MapSnapshotter, TEST_REQUIRES_SERVER(annotation)) {
util::RunLoop runLoop;
MapSnapshotter snapshotter(Size{256, 128}, 1.0f, ResourceOptions(), ClientOptions());
snapshotter.setStyleURL("http://127.0.0.1:3000/online/style.json");
snapshotter.addAnnotationImage(namedMarker("default_marker"));
snapshotter.addAnnotation(SymbolAnnotation{Point<double>{0, 0}, "default_marker"});
FillAnnotation fillAnnotation{Polygon<double>{{{{0, 0}, {0, 45}, {45, 45}, {45, 0}}}}};
fillAnnotation.color = Color::red();
snapshotter.addAnnotation(fillAnnotation);
LineAnnotation lineAnnotation{LineString<double>{{{0, 0}, {45, 45}, {30, 0}}}};
lineAnnotation.color = Color::blue();
lineAnnotation.width = {5};
snapshotter.addAnnotation(lineAnnotation);
snapshotter.snapshot([&runLoop](std::exception_ptr ptr,
mbgl::PremultipliedImage image,
mbgl::MapSnapshotter::Attributions,
mbgl::MapSnapshotter::PointForFn,
mbgl::MapSnapshotter::LatLngForFn) {
EXPECT_EQ(nullptr, ptr);
EXPECT_EQ(256, image.size.width);
EXPECT_EQ(128, image.size.height);
test::checkImage("test/fixtures/map/map_snapshotter_annotation", image, 0.005, 0.1);
runLoop.stop();
});
runLoop.run();
}