diff options
author | Mikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com> | 2018-11-28 16:03:09 +0200 |
---|---|---|
committer | Mikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com> | 2018-11-28 17:18:38 +0200 |
commit | ad03e42b2890fd430e99e543a40be42f09f47fba (patch) | |
tree | 0644ddaab4f30ac1dc2c59507125cad832b366b2 /src/mbgl/annotation | |
parent | a0b8f01c1baf640f34c0f46ba22efd399b7a0012 (diff) | |
download | qtlocation-mapboxgl-ad03e42b2890fd430e99e543a40be42f09f47fba.tar.gz |
[core] LayerManager can disable annotations
At the moment, the annotations implementation in the `mapbox-gl-native`
core is creating concrete layer instances apart from `LayerManager/LayerFactory`
code path.
So, annotations must be disabled if the `LayerManager` implementation does
not provide line, fill or symbol layers (those, used by the annotations).
Note: in future, annotations implementation will be moved from the core to the
platform SDK level(see https://github.com/mapbox/mapbox-plugins-android/tree/master/plugin-annotation)
and `LayerManager` won't need to disable it.
Diffstat (limited to 'src/mbgl/annotation')
-rw-r--r-- | src/mbgl/annotation/annotation_manager.cpp | 23 | ||||
-rw-r--r-- | src/mbgl/annotation/annotation_manager.hpp | 2 |
2 files changed, 22 insertions, 3 deletions
diff --git a/src/mbgl/annotation/annotation_manager.cpp b/src/mbgl/annotation/annotation_manager.cpp index 1baf83179e..17cf77865c 100644 --- a/src/mbgl/annotation/annotation_manager.cpp +++ b/src/mbgl/annotation/annotation_manager.cpp @@ -13,6 +13,15 @@ #include <boost/function_output_iterator.hpp> +// Note: LayerManager::annotationsEnabled is defined +// at compile time, so that linker (with LTO on) is able +// to optimize out the unreachable code. +#define CHECK_ANNOTATIONS_ENABLED_AND_RETURN(result) \ +if (!LayerManager::annotationsEnabled) { \ + assert(false); \ + return result; \ +} + namespace mbgl { using namespace style; @@ -28,14 +37,17 @@ AnnotationManager::AnnotationManager(Style& style_) AnnotationManager::~AnnotationManager() = default; void AnnotationManager::setStyle(Style& style_) { + CHECK_ANNOTATIONS_ENABLED_AND_RETURN(); style = style_; } void AnnotationManager::onStyleLoaded() { + CHECK_ANNOTATIONS_ENABLED_AND_RETURN(); updateStyle(); } AnnotationID AnnotationManager::addAnnotation(const Annotation& annotation) { + CHECK_ANNOTATIONS_ENABLED_AND_RETURN(nextID++); std::lock_guard<std::mutex> lock(mutex); AnnotationID id = nextID++; Annotation::visit(annotation, [&] (const auto& annotation_) { @@ -46,6 +58,7 @@ AnnotationID AnnotationManager::addAnnotation(const Annotation& annotation) { } bool AnnotationManager::updateAnnotation(const AnnotationID& id, const Annotation& annotation) { + CHECK_ANNOTATIONS_ENABLED_AND_RETURN(true); std::lock_guard<std::mutex> lock(mutex); Annotation::visit(annotation, [&] (const auto& annotation_) { this->update(id, annotation_); @@ -54,6 +67,7 @@ bool AnnotationManager::updateAnnotation(const AnnotationID& id, const Annotatio } void AnnotationManager::removeAnnotation(const AnnotationID& id) { + CHECK_ANNOTATIONS_ENABLED_AND_RETURN(); std::lock_guard<std::mutex> lock(mutex); remove(id); dirty = true; @@ -119,6 +133,7 @@ void AnnotationManager::update(const AnnotationID& id, const FillAnnotation& ann } void AnnotationManager::remove(const AnnotationID& id) { + CHECK_ANNOTATIONS_ENABLED_AND_RETURN(); if (symbolAnnotations.find(id) != symbolAnnotations.end()) { symbolTree.remove(symbolAnnotations.at(id)); symbolAnnotations.erase(id); @@ -194,6 +209,7 @@ void AnnotationManager::updateStyle() { } void AnnotationManager::updateData() { + CHECK_ANNOTATIONS_ENABLED_AND_RETURN(); std::lock_guard<std::mutex> lock(mutex); if (dirty) { for (auto& tile : tiles) { @@ -204,12 +220,14 @@ void AnnotationManager::updateData() { } void AnnotationManager::addTile(AnnotationTile& tile) { + CHECK_ANNOTATIONS_ENABLED_AND_RETURN(); std::lock_guard<std::mutex> lock(mutex); tiles.insert(&tile); tile.setData(getTileData(tile.id.canonical)); } void AnnotationManager::removeTile(AnnotationTile& tile) { + CHECK_ANNOTATIONS_ENABLED_AND_RETURN(); std::lock_guard<std::mutex> lock(mutex); tiles.erase(&tile); } @@ -221,6 +239,7 @@ static std::string prefixedImageID(const std::string& id) { } void AnnotationManager::addImage(std::unique_ptr<style::Image> image) { + CHECK_ANNOTATIONS_ENABLED_AND_RETURN(); std::lock_guard<std::mutex> lock(mutex); const std::string id = prefixedImageID(image->getID()); images.erase(id); @@ -230,6 +249,7 @@ void AnnotationManager::addImage(std::unique_ptr<style::Image> image) { } void AnnotationManager::removeImage(const std::string& id_) { + CHECK_ANNOTATIONS_ENABLED_AND_RETURN(); std::lock_guard<std::mutex> lock(mutex); const std::string id = prefixedImageID(id_); images.erase(id); @@ -237,10 +257,11 @@ void AnnotationManager::removeImage(const std::string& id_) { } double AnnotationManager::getTopOffsetPixelsForImage(const std::string& id_) { + CHECK_ANNOTATIONS_ENABLED_AND_RETURN(0.0); std::lock_guard<std::mutex> lock(mutex); 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.0; } } // namespace mbgl diff --git a/src/mbgl/annotation/annotation_manager.hpp b/src/mbgl/annotation/annotation_manager.hpp index 326565f8bc..6c794d7f84 100644 --- a/src/mbgl/annotation/annotation_manager.hpp +++ b/src/mbgl/annotation/annotation_manager.hpp @@ -84,8 +84,6 @@ private: ImageMap images; std::unordered_set<AnnotationTile*> tiles; - - friend class AnnotationTile; }; } // namespace mbgl |