2210: Sprites can be removed / updated correctly

This commit is contained in:
Romain Quidet
2015-11-30 14:18:10 +01:00
committed by Minh Nguyễn
parent 02a32b55e4
commit af45d87e54
7 changed files with 24 additions and 5 deletions

View File

@@ -2718,7 +2718,7 @@ std::chrono::steady_clock::duration MGLDurationInSeconds(float duration)
{
// remove sprite
NSString *symbolName = [MGLAnnotationSpritePrefix stringByAppendingString:annotationImage.reuseIdentifier];
_mbglMap->removeSprite(symbolName.UTF8String);
_mbglMap->removeAnnotationIcon(symbolName.UTF8String);
[self installAnnotationImage:annotationImage];
_mbglMap->update(mbgl::Update::Annotations);
}

View File

@@ -159,6 +159,11 @@ void AnnotationManager::addIcon(const std::string& name, std::shared_ptr<const S
spriteStore.setSprite(name, sprite);
spriteAtlas.updateDirty();
}
void AnnotationManager::removeIcon(const std::string& name) {
spriteStore.removeSprite(name);
spriteAtlas.updateDirty();
}
double AnnotationManager::getTopOffsetPixelsForIcon(const std::string& name) {
auto sprite = spriteStore.getSprite(name);

View File

@@ -34,6 +34,7 @@ public:
LatLngBounds getBoundsForAnnotations(const AnnotationIDs&) const;
void addIcon(const std::string& name, std::shared_ptr<const SpriteImage>);
void removeIcon(const std::string& name);
double getTopOffsetPixelsForIcon(const std::string& name);
SpriteAtlas& getSpriteAtlas() { return spriteAtlas; }

View File

@@ -392,7 +392,7 @@ void Map::addAnnotationIcon(const std::string& name, std::shared_ptr<const Sprit
}
void Map::removeAnnotationIcon(const std::string& name) {
addAnnotationIcon(name, nullptr);
removeAnnotationIcon(name);
}
double Map::getTopOffsetPixelsForAnnotationIcon(const std::string& symbol) {

View File

@@ -272,6 +272,11 @@ void MapContext::addAnnotationIcon(const std::string& name, std::shared_ptr<cons
assert(util::ThreadContext::currentlyOn(util::ThreadType::Map));
data.getAnnotationManager()->addIcon(name, sprite);
}
void MapContext::removeAnnotationIcon(const std::string& name) {
assert(util::ThreadContext::currentlyOn(util::ThreadType::Map));
data.getAnnotationManager()->removeIcon(name);
}
double MapContext::getTopOffsetPixelsForAnnotationIcon(const std::string& name) {
assert(util::ThreadContext::currentlyOn(util::ThreadType::Map));
@@ -298,7 +303,7 @@ void MapContext::onLowMemory() {
style->onLowMemory();
asyncInvalidate.send();
}
void MapContext::onTileDataChanged() {
assert(util::ThreadContext::currentlyOn(util::ThreadType::Map));
updateFlags |= Update::Repaint;

View File

@@ -52,6 +52,7 @@ public:
// Annotations
void addAnnotationIcon(const std::string&, std::shared_ptr<const SpriteImage>);
void removeAnnotationIcon(const std::string&);
double getTopOffsetPixelsForAnnotationIcon(const std::string&);
void updateAnnotations();

View File

@@ -187,8 +187,15 @@ void SpriteAtlas::updateDirty() {
// The two names match;
Holder& holder = imageIterator->second;
holder.texture = spriteIterator->second;
copy(holder, imageIterator->first.second);
if (holder.texture != nullptr)
{
copy(holder, imageIterator->first.second);
}
else
{
images.erase(imageIterator);
}
++imageIterator;
// Don't advance the spriteIterator because there might be another sprite with the same
// name, but a different wrap value.