summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2017-05-31 08:45:33 -0700
committerJohn Firebaugh <john.firebaugh@gmail.com>2017-06-05 19:38:08 -0700
commitf983c2716b807669561e09fc86b765d79938be30 (patch)
treec5f6ef1d5509840e569d0ac050ca79b16b3748b4 /src
parent74af076d405a089fac70a47e41fe92d04d97fc50 (diff)
downloadqtlocation-mapboxgl-f983c2716b807669561e09fc86b765d79938be30.tar.gz
[core] Fix several bugs in AnnotationManager
Diffstat (limited to 'src')
-rw-r--r--src/mbgl/annotation/annotation_manager.cpp18
1 files changed, 12 insertions, 6 deletions
diff --git a/src/mbgl/annotation/annotation_manager.cpp b/src/mbgl/annotation/annotation_manager.cpp
index 9ea47acadb..f40b9176fb 100644
--- a/src/mbgl/annotation/annotation_manager.cpp
+++ b/src/mbgl/annotation/annotation_manager.cpp
@@ -200,24 +200,30 @@ void AnnotationManager::removeTile(AnnotationTile& tile) {
tiles.erase(&tile);
}
+// To ensure that annotation images do not collide with images from the style,
+// we prefix input image IDs with "com.mapbox.annotations".
+static std::string prefixedImageID(const std::string& id) {
+ return AnnotationManager::SourceID + "." + id;
+}
+
void AnnotationManager::addImage(std::unique_ptr<style::Image> image) {
- // To ensure that annotation images do not collide with images from the style,
- // create a new image with the input ID prefixed by "com.mapbox.annotations".
- std::string id = SourceID + "." + image->getID();
+ const std::string id = prefixedImageID(image->getID());
images.erase(id);
images.emplace(id,
style::Image(id, image->getImage().clone(), image->getPixelRatio(), image->isSdf()));
obsoleteImages.erase(id);
}
-void AnnotationManager::removeImage(const std::string& id) {
+void AnnotationManager::removeImage(const std::string& id_) {
+ const std::string id = prefixedImageID(id_);
images.erase(id);
obsoleteImages.insert(id);
}
-double AnnotationManager::getTopOffsetPixelsForImage(const std::string& id) {
+double AnnotationManager::getTopOffsetPixelsForImage(const std::string& id_) {
+ const std::string id = prefixedImageID(id_);
auto it = images.find(id);
- return it == images.end() ? -(it->second.getImage().size.height / it->second.getPixelRatio()) / 2 : 0;
+ return it != images.end() ? -(it->second.getImage().size.height / it->second.getPixelRatio()) / 2 : 0;
}
} // namespace mbgl