From 12c7b68e478dde33d886adfd868d02169cca69ca Mon Sep 17 00:00:00 2001 From: Chris Loer Date: Mon, 6 Aug 2018 13:27:57 -0700 Subject: [core, node] Don't create an annotation source in static map modes. Fixes issue #12545. --- src/mbgl/annotation/annotation_manager.cpp | 42 +++++++++++++++++++++--------- src/mbgl/annotation/annotation_manager.hpp | 6 ++--- src/mbgl/map/map.cpp | 4 +-- 3 files changed, 35 insertions(+), 17 deletions(-) diff --git a/src/mbgl/annotation/annotation_manager.cpp b/src/mbgl/annotation/annotation_manager.cpp index 41eedf17dc..b81becbec2 100644 --- a/src/mbgl/annotation/annotation_manager.cpp +++ b/src/mbgl/annotation/annotation_manager.cpp @@ -21,13 +21,13 @@ const std::string AnnotationManager::SourceID = "com.mapbox.annotations"; const std::string AnnotationManager::PointLayerID = "com.mapbox.annotations.points"; const std::string AnnotationManager::ShapeLayerID = "com.mapbox.annotations.shape."; -AnnotationManager::AnnotationManager(Style& style_) +AnnotationManager::AnnotationManager(Style* style_) : style(style_) { }; AnnotationManager::~AnnotationManager() = default; -void AnnotationManager::setStyle(Style& style_) { +void AnnotationManager::setStyle(Style* style_) { style = style_; } @@ -66,15 +66,21 @@ void AnnotationManager::add(const AnnotationID& id, const SymbolAnnotation& anno } void AnnotationManager::add(const AnnotationID& id, const LineAnnotation& annotation) { + if (!style) { + return; + } ShapeAnnotationImpl& impl = *shapeAnnotations.emplace(id, std::make_unique(id, annotation)).first->second; - impl.updateStyle(*style.get().impl); + impl.updateStyle(*style->impl); } void AnnotationManager::add(const AnnotationID& id, const FillAnnotation& annotation) { + if (!style) { + return; + } ShapeAnnotationImpl& impl = *shapeAnnotations.emplace(id, std::make_unique(id, annotation)).first->second; - impl.updateStyle(*style.get().impl); + impl.updateStyle(*style->impl); } void AnnotationManager::update(const AnnotationID& id, const SymbolAnnotation& annotation) { @@ -119,12 +125,15 @@ void AnnotationManager::update(const AnnotationID& id, const FillAnnotation& ann } void AnnotationManager::remove(const AnnotationID& id) { + if (!style) { + return; + } if (symbolAnnotations.find(id) != symbolAnnotations.end()) { symbolTree.remove(symbolAnnotations.at(id)); symbolAnnotations.erase(id); } else if (shapeAnnotations.find(id) != shapeAnnotations.end()) { auto it = shapeAnnotations.find(id); - *style.get().impl->removeLayer(it->second->layerID); + *style->impl->removeLayer(it->second->layerID); shapeAnnotations.erase(it); } else { assert(false); // Should never happen @@ -154,10 +163,13 @@ std::unique_ptr AnnotationManager::getTileData(const Canonic } void AnnotationManager::updateStyle() { + if (!style) { + return; + } // Create annotation source, point layer, and point bucket. We do everything via Style::Impl // because we don't want annotation mutations to trigger Style::Impl::styleMutated to be set. - if (!style.get().impl->getSource(SourceID)) { - style.get().impl->addSource(std::make_unique()); + if (!style->impl->getSource(SourceID)) { + style->impl->addSource(std::make_unique()); std::unique_ptr layer = std::make_unique(PointLayerID, SourceID); @@ -167,13 +179,13 @@ void AnnotationManager::updateStyle() { layer->setIconAllowOverlap(true); layer->setIconIgnorePlacement(true); - style.get().impl->addLayer(std::move(layer)); + style->impl->addLayer(std::move(layer)); } std::lock_guard lock(mutex); for (const auto& shape : shapeAnnotations) { - shape.second->updateStyle(*style.get().impl); + shape.second->updateStyle(*style->impl); } for (const auto& image : images) { @@ -183,7 +195,7 @@ void AnnotationManager::updateStyle() { // of which images need to be added because we don't know if the style is the same // instance as in the last updateStyle call. If it's a new style, we need to add all // images.) - style.get().impl->addImage(std::make_unique(image.second)); + style->impl->addImage(std::make_unique(image.second)); } } @@ -215,19 +227,25 @@ static std::string prefixedImageID(const std::string& id) { } void AnnotationManager::addImage(std::unique_ptr image) { + if (!style) { + return; + } std::lock_guard lock(mutex); const std::string id = prefixedImageID(image->getID()); images.erase(id); auto inserted = images.emplace(id, style::Image(id, image->getImage().clone(), image->getPixelRatio(), image->isSdf())); - style.get().impl->addImage(std::make_unique(inserted.first->second)); + style->impl->addImage(std::make_unique(inserted.first->second)); } void AnnotationManager::removeImage(const std::string& id_) { + if (!style) { + return; + } std::lock_guard lock(mutex); const std::string id = prefixedImageID(id_); images.erase(id); - style.get().impl->removeImage(id); + style->impl->removeImage(id); } double AnnotationManager::getTopOffsetPixelsForImage(const std::string& id_) { diff --git a/src/mbgl/annotation/annotation_manager.hpp b/src/mbgl/annotation/annotation_manager.hpp index 326565f8bc..6d8c374783 100644 --- a/src/mbgl/annotation/annotation_manager.hpp +++ b/src/mbgl/annotation/annotation_manager.hpp @@ -25,7 +25,7 @@ class Style; class AnnotationManager : private util::noncopyable { public: - AnnotationManager(style::Style&); + AnnotationManager(style::Style*); ~AnnotationManager(); AnnotationID addAnnotation(const Annotation&); @@ -36,7 +36,7 @@ public: void removeImage(const std::string&); double getTopOffsetPixelsForImage(const std::string&); - void setStyle(style::Style&); + void setStyle(style::Style*); void onStyleLoaded(); void updateData(); @@ -63,7 +63,7 @@ private: std::unique_ptr getTileData(const CanonicalTileID&); - std::reference_wrapper style; + style::Style* style; std::mutex mutex; diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp index c177299485..120fc42ef5 100644 --- a/src/mbgl/map/map.cpp +++ b/src/mbgl/map/map.cpp @@ -129,7 +129,7 @@ Map::Impl::Impl(Map& map_, mode(mode_), pixelRatio(pixelRatio_), style(std::make_unique