[core] Fixed annotation icon replacement
Another pass at #3146, including a unit test.
This commit is contained in:
@@ -14,8 +14,8 @@
|
||||
|
||||
using namespace mbgl;
|
||||
|
||||
std::shared_ptr<SpriteImage> defaultMarker() {
|
||||
PremultipliedImage image = decodeImage(util::read_file("test/fixtures/sprites/default_marker.png"));
|
||||
std::shared_ptr<SpriteImage> namedMarker(const std::string &name) {
|
||||
PremultipliedImage image = decodeImage(util::read_file("test/fixtures/sprites/" + name));
|
||||
return std::make_shared<SpriteImage>(image.width, image.height, 1.0, std::string(reinterpret_cast<char*>(image.data.get()), image.size()));
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ TEST(Annotations, PointAnnotation) {
|
||||
|
||||
Map map(view, fileSource, MapMode::Still);
|
||||
map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"), "");
|
||||
map.addAnnotationIcon("default_marker", defaultMarker());
|
||||
map.addAnnotationIcon("default_marker", namedMarker("default_marker.png"));
|
||||
map.addPointAnnotation(PointAnnotation({ 0, 0 }, "default_marker"));
|
||||
|
||||
checkRendering(map, "point_annotation");
|
||||
@@ -96,7 +96,7 @@ TEST(Annotations, AddMultiple) {
|
||||
|
||||
Map map(view, fileSource, MapMode::Still);
|
||||
map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"), "");
|
||||
map.addAnnotationIcon("default_marker", defaultMarker());
|
||||
map.addAnnotationIcon("default_marker", namedMarker("default_marker.png"));
|
||||
map.addPointAnnotation(PointAnnotation({ 0, -10 }, "default_marker"));
|
||||
|
||||
test::render(map);
|
||||
@@ -126,6 +126,25 @@ TEST(Annotations, NonImmediateAdd) {
|
||||
checkRendering(map, "non_immediate_add");
|
||||
}
|
||||
|
||||
TEST(Annotations, UpdatePoint) {
|
||||
auto display = std::make_shared<mbgl::HeadlessDisplay>();
|
||||
HeadlessView view(display, 1);
|
||||
DefaultFileSource fileSource(nullptr, test::getFileSourceRoot());
|
||||
|
||||
Map map(view, fileSource, MapMode::Still);
|
||||
map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"), "");
|
||||
map.addAnnotationIcon("flipped_marker", namedMarker("default_marker.png"));
|
||||
map.addPointAnnotation(PointAnnotation({ 0, 0 }, "flipped_marker"));
|
||||
|
||||
test::render(map);
|
||||
|
||||
map.removeAnnotationIcon("flipped_marker");
|
||||
map.addAnnotationIcon("flipped_marker", namedMarker("flipped_marker.png"));
|
||||
map.update(Update::Annotations);
|
||||
|
||||
checkRendering(map, "update_point");
|
||||
}
|
||||
|
||||
TEST(Annotations, RemovePoint) {
|
||||
auto display = std::make_shared<mbgl::HeadlessDisplay>();
|
||||
HeadlessView view(display, 1);
|
||||
@@ -133,7 +152,7 @@ TEST(Annotations, RemovePoint) {
|
||||
|
||||
Map map(view, fileSource, MapMode::Still);
|
||||
map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"), "");
|
||||
map.addAnnotationIcon("default_marker", defaultMarker());
|
||||
map.addAnnotationIcon("default_marker", namedMarker("default_marker.png"));
|
||||
uint32_t point = map.addPointAnnotation(PointAnnotation({ 0, 0 }, "default_marker"));
|
||||
|
||||
test::render(map);
|
||||
@@ -184,7 +203,7 @@ TEST(Annotations, SwitchStyle) {
|
||||
|
||||
Map map(view, fileSource, MapMode::Still);
|
||||
map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"), "");
|
||||
map.addAnnotationIcon("default_marker", defaultMarker());
|
||||
map.addAnnotationIcon("default_marker", namedMarker("default_marker.png"));
|
||||
map.addPointAnnotation(PointAnnotation({ 0, 0 }, "default_marker"));
|
||||
|
||||
test::render(map);
|
||||
|
||||
Reference in New Issue
Block a user