summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMinh Nguyễn <mxn@1ec5.org>2015-12-15 21:04:15 -0800
committerMinh Nguyễn <mxn@1ec5.org>2015-12-15 21:04:15 -0800
commite304033552fd423db5324545216f9cf3a1e62150 (patch)
treea7e162af70b10e440a515d43b6fef9e618decf6a
parent0f37b670bac6aace6b83148ccee3b63e42a6896c (diff)
downloadqtlocation-mapboxgl-e304033552fd423db5324545216f9cf3a1e62150.tar.gz
[core] Fixed annotation icon replacement
Another pass at #3146, including a unit test.
-rw-r--r--src/mbgl/map/map.cpp2
-rw-r--r--src/mbgl/sprite/sprite_atlas.cpp5
-rw-r--r--test/api/annotations.cpp31
-rw-r--r--test/fixtures/annotations/update_point/expected.pngbin0 -> 2949 bytes
-rw-r--r--test/fixtures/sprites/flipped_marker.pngbin0 -> 1615 bytes
5 files changed, 28 insertions, 10 deletions
diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp
index c07eda6b46..5e22e8aeef 100644
--- a/src/mbgl/map/map.cpp
+++ b/src/mbgl/map/map.cpp
@@ -392,7 +392,7 @@ void Map::addAnnotationIcon(const std::string& name, std::shared_ptr<const Sprit
}
void Map::removeAnnotationIcon(const std::string& name) {
- removeAnnotationIcon(name);
+ context->invoke(&MapContext::removeAnnotationIcon, name);
}
double Map::getTopOffsetPixelsForAnnotationIcon(const std::string& symbol) {
diff --git a/src/mbgl/sprite/sprite_atlas.cpp b/src/mbgl/sprite/sprite_atlas.cpp
index 202218f51c..d09330e17b 100644
--- a/src/mbgl/sprite/sprite_atlas.cpp
+++ b/src/mbgl/sprite/sprite_atlas.cpp
@@ -189,11 +189,10 @@ void SpriteAtlas::updateDirty() {
holder.texture = spriteIterator->second;
if (holder.texture != nullptr) {
copy(holder, imageIterator->first.second);
+ ++imageIterator;
} else {
- images.erase(imageIterator);
+ images.erase(imageIterator++);
}
-
- ++imageIterator;
// Don't advance the spriteIterator because there might be another sprite with the same
// name, but a different wrap value.
}
diff --git a/test/api/annotations.cpp b/test/api/annotations.cpp
index 1040040220..104ccd2f26 100644
--- a/test/api/annotations.cpp
+++ b/test/api/annotations.cpp
@@ -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);
diff --git a/test/fixtures/annotations/update_point/expected.png b/test/fixtures/annotations/update_point/expected.png
new file mode 100644
index 0000000000..3b6ca22747
--- /dev/null
+++ b/test/fixtures/annotations/update_point/expected.png
Binary files differ
diff --git a/test/fixtures/sprites/flipped_marker.png b/test/fixtures/sprites/flipped_marker.png
new file mode 100644
index 0000000000..34ab6dfb7c
--- /dev/null
+++ b/test/fixtures/sprites/flipped_marker.png
Binary files differ