Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
2210: Sprites can be removed / updated correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
Romain Quidet committed Dec 15, 2015
1 parent 360c8bb commit fbb5ece
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 5 deletions.
2 changes: 1 addition & 1 deletion platform/ios/MGLMapView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -2696,7 +2696,7 @@ - (void)annotationImageNeedsRedisplay:(MGLAnnotationImage *)annotationImage
{
// remove sprite
NSString *symbolName = [MGLAnnotationSpritePrefix stringByAppendingString:annotationImage.reuseIdentifier];
_mbglMap->removeSprite(symbolName.UTF8String);
_mbglMap->removeAnnotationIcon(symbolName.UTF8String);
[self installAnnotationImage:annotationImage];
_mbglMap->update(mbgl::Update::Annotations);
}
Expand Down
5 changes: 5 additions & 0 deletions src/mbgl/annotation/annotation_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/mbgl/annotation/annotation_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class AnnotationManager : private util::noncopyable {
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; }

Expand Down
2 changes: 1 addition & 1 deletion src/mbgl/map/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,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) {
Expand Down
7 changes: 6 additions & 1 deletion src/mbgl/map/map_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -298,7 +303,7 @@ void MapContext::onLowMemory() {
style->onLowMemory();
asyncInvalidate.send();
}

void MapContext::onTileDataChanged() {
assert(util::ThreadContext::currentlyOn(util::ThreadType::Map));
updateFlags |= Update::Repaint;
Expand Down
1 change: 1 addition & 0 deletions src/mbgl/map/map_context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class MapContext : public Style::Observer {

// Annotations
void addAnnotationIcon(const std::string&, std::shared_ptr<const SpriteImage>);
void removeAnnotationIcon(const std::string&);
double getTopOffsetPixelsForAnnotationIcon(const std::string&);
void updateAnnotations();

Expand Down
11 changes: 9 additions & 2 deletions src/mbgl/sprite/sprite_atlas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit fbb5ece

Please sign in to comment.