summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Loer <chris.loer@gmail.com>2018-08-06 13:27:57 -0700
committerChris Loer <chris.loer@gmail.com>2018-08-06 13:52:36 -0700
commit12c7b68e478dde33d886adfd868d02169cca69ca (patch)
tree61d61da6718ef8f188a51bde4b9af2485a5a1fdb
parent1a94eb47c011b13cef0f412aafa2eb9ae75e418a (diff)
downloadqtlocation-mapboxgl-upstream/no-static-annotations.tar.gz
[core, node] Don't create an annotation source in static map modes.upstream/no-static-annotations
Fixes issue #12545.
-rw-r--r--src/mbgl/annotation/annotation_manager.cpp42
-rw-r--r--src/mbgl/annotation/annotation_manager.hpp6
-rw-r--r--src/mbgl/map/map.cpp4
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<LineAnnotationImpl>(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<FillAnnotationImpl>(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<AnnotationTileData> 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<AnnotationSource>());
+ if (!style->impl->getSource(SourceID)) {
+ style->impl->addSource(std::make_unique<AnnotationSource>());
std::unique_ptr<SymbolLayer> layer = std::make_unique<SymbolLayer>(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<std::mutex> 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<style::Image>(image.second));
+ style->impl->addImage(std::make_unique<style::Image>(image.second));
}
}
@@ -215,19 +227,25 @@ static std::string prefixedImageID(const std::string& id) {
}
void AnnotationManager::addImage(std::unique_ptr<style::Image> image) {
+ if (!style) {
+ return;
+ }
std::lock_guard<std::mutex> 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<style::Image>(inserted.first->second));
+ style->impl->addImage(std::make_unique<style::Image>(inserted.first->second));
}
void AnnotationManager::removeImage(const std::string& id_) {
+ if (!style) {
+ return;
+ }
std::lock_guard<std::mutex> 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<AnnotationTileData> getTileData(const CanonicalTileID&);
- std::reference_wrapper<style::Style> 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<Style>(scheduler, fileSource, pixelRatio)),
- annotationManager(*style) {
+ annotationManager(mode == MapMode::Continuous ? style.get() : NULL) {
style->impl->setObserver(this);
rendererFrontend.setObserver(*this);
@@ -233,7 +233,7 @@ void Map::setStyle(std::unique_ptr<Style> style) {
assert(style);
impl->onStyleLoading();
impl->style = std::move(style);
- impl->annotationManager.setStyle(*impl->style);
+ impl->annotationManager.setStyle(impl->mode == MapMode::Continuous ? impl->style.get() : NULL);
}
#pragma mark - Transitions