From e304033552fd423db5324545216f9cf3a1e62150 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguy=E1=BB=85n?= Date: Tue, 15 Dec 2015 21:04:15 -0800 Subject: [PATCH] [core] Fixed annotation icon replacement Another pass at #3146, including a unit test. --- src/mbgl/map/map.cpp | 2 +- src/mbgl/sprite/sprite_atlas.cpp | 5 ++- test/api/annotations.cpp | 31 ++++++++++++++---- .../annotations/update_point/expected.png | Bin 0 -> 2949 bytes test/fixtures/sprites/flipped_marker.png | Bin 0 -> 1615 bytes 5 files changed, 28 insertions(+), 10 deletions(-) create mode 100644 test/fixtures/annotations/update_point/expected.png create mode 100644 test/fixtures/sprites/flipped_marker.png diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp index c07eda6b46a..5e22e8aeeff 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_ptrinvoke(&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 202218f51ce..d09330e17bf 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 1040040220e..104ccd2f264 100644 --- a/test/api/annotations.cpp +++ b/test/api/annotations.cpp @@ -14,8 +14,8 @@ using namespace mbgl; -std::shared_ptr defaultMarker() { - PremultipliedImage image = decodeImage(util::read_file("test/fixtures/sprites/default_marker.png")); +std::shared_ptr namedMarker(const std::string &name) { + PremultipliedImage image = decodeImage(util::read_file("test/fixtures/sprites/" + name)); return std::make_shared(image.width, image.height, 1.0, std::string(reinterpret_cast(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(); + 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(); 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 0000000000000000000000000000000000000000..3b6ca22747cf1cf05a0579410785f1604e61dd42 GIT binary patch literal 2949 zcmeH}c{H1Q8pmI5jHNa7Fw?7P$>p|G4^gx#_Mw*AO^(==)YeKugjj>?YHy8YhT7Vz zo597!jVcC_wrcI-G*`4l;!Z4;h%LcQ$Sd>GPG{zy`Tw5N_n+VMd*1K!d6x4#@B6#y z37f)Li`~bT3|5_o(=#&Ejc8OP=NLbtgD|V0HmJ+ zfShjuU|df0|2TD0FEYn-{Wfyfdb>u0i*y=4-}SwGmf}Ih>S8$#U(%y z0AQVpf=pZ#DFTs-i^nISQf+h(6e!5vcO!KX2NKdX8{Gg;AA}=;7=<`zY;J6#Ypa4l zAgqa3qEUWM&L6{}osDiRiIjjsBFSX3G1<(RK#W12wY0QEnwTO@O^qOhQBoS76p?C# zPtyAU`8UTYDhW%BOCZG&@Q8hGL?j`ZWTUIQpXk%`p-xg<^nWtplRmZuHHh4QgFI_& zg8amWLaq0`C~sn16qI?NZ+q7IK>0tuk9n+-`^o>Sm=B#Ec%fEpRjiSp#%8PH@k~Du z0F;~EoE*@paw}}l_~V!p!1`1&SFBfb)XJ0Uw&7pED%C`zmB0FW8m)QL(U-`b^KY!A z92b`wCUV1agT7T6o`06FVUu7WuZ(w9I{nS5OAFrx`IMTk;=2<4dh6~ifSAr+?X_c8 zV-I#W;c*>iYiC3hZ_#YE#hj;afRZ}GJ_nGKhkZ6a58?lug!R#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