summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2016-08-27 15:26:15 -0700
committerJohn Firebaugh <john.firebaugh@gmail.com>2016-08-29 08:08:44 -0700
commite126dc3a5a3857b24246432153b0554d630b6234 (patch)
tree55cfde3bb7ed61dba029537f030a4d43f2d4c9c2 /src
parentd9f63c6d76ff33dfbefa57eb124efe10d5c7592a (diff)
downloadqtlocation-mapboxgl-e126dc3a5a3857b24246432153b0554d630b6234.tar.gz
[core] Fix updates of line and fill annotations
Diffstat (limited to 'src')
-rw-r--r--src/mbgl/annotation/annotation_manager.cpp17
-rw-r--r--src/mbgl/annotation/annotation_manager.hpp2
-rw-r--r--src/mbgl/annotation/fill_annotation_impl.cpp23
-rw-r--r--src/mbgl/annotation/line_annotation_impl.cpp25
-rw-r--r--src/mbgl/style/style.cpp4
-rw-r--r--src/mbgl/style/style.hpp4
6 files changed, 42 insertions, 33 deletions
diff --git a/src/mbgl/annotation/annotation_manager.cpp b/src/mbgl/annotation/annotation_manager.cpp
index 4e837d370d..f1ddf99602 100644
--- a/src/mbgl/annotation/annotation_manager.cpp
+++ b/src/mbgl/annotation/annotation_manager.cpp
@@ -42,7 +42,7 @@ void AnnotationManager::removeAnnotation(const AnnotationID& id) {
symbolTree.remove(symbolAnnotations.at(id));
symbolAnnotations.erase(id);
} else if (shapeAnnotations.find(id) != shapeAnnotations.end()) {
- obsoleteShapeAnnotationLayers.push_back(shapeAnnotations.at(id)->layerID);
+ obsoleteShapeAnnotationLayers.insert(shapeAnnotations.at(id)->layerID);
shapeAnnotations.erase(id);
}
}
@@ -54,18 +54,21 @@ void AnnotationManager::add(const AnnotationID& id, const SymbolAnnotation& anno
}
void AnnotationManager::add(const AnnotationID& id, const LineAnnotation& annotation, const uint8_t maxZoom) {
- shapeAnnotations.emplace(id,
- std::make_unique<LineAnnotationImpl>(id, annotation, maxZoom));
+ ShapeAnnotationImpl& impl = *shapeAnnotations.emplace(id,
+ std::make_unique<LineAnnotationImpl>(id, annotation, maxZoom)).first->second;
+ obsoleteShapeAnnotationLayers.erase(impl.layerID);
}
void AnnotationManager::add(const AnnotationID& id, const FillAnnotation& annotation, const uint8_t maxZoom) {
- shapeAnnotations.emplace(id,
- std::make_unique<FillAnnotationImpl>(id, annotation, maxZoom));
+ ShapeAnnotationImpl& impl = *shapeAnnotations.emplace(id,
+ std::make_unique<FillAnnotationImpl>(id, annotation, maxZoom)).first->second;
+ obsoleteShapeAnnotationLayers.erase(impl.layerID);
}
void AnnotationManager::add(const AnnotationID& id, const StyleSourcedAnnotation& annotation, const uint8_t maxZoom) {
- shapeAnnotations.emplace(id,
- std::make_unique<StyleSourcedAnnotationImpl>(id, annotation, maxZoom));
+ ShapeAnnotationImpl& impl = *shapeAnnotations.emplace(id,
+ std::make_unique<StyleSourcedAnnotationImpl>(id, annotation, maxZoom)).first->second;
+ obsoleteShapeAnnotationLayers.erase(impl.layerID);
}
Update AnnotationManager::update(const AnnotationID& id, const SymbolAnnotation& annotation, const uint8_t maxZoom) {
diff --git a/src/mbgl/annotation/annotation_manager.hpp b/src/mbgl/annotation/annotation_manager.hpp
index a0f25fdf57..a9afa0d52d 100644
--- a/src/mbgl/annotation/annotation_manager.hpp
+++ b/src/mbgl/annotation/annotation_manager.hpp
@@ -73,7 +73,7 @@ private:
SymbolAnnotationTree symbolTree;
SymbolAnnotationMap symbolAnnotations;
ShapeAnnotationMap shapeAnnotations;
- std::vector<std::string> obsoleteShapeAnnotationLayers;
+ std::set<std::string> obsoleteShapeAnnotationLayers;
std::set<AnnotationTile*> tiles;
SpriteStore spriteStore;
diff --git a/src/mbgl/annotation/fill_annotation_impl.cpp b/src/mbgl/annotation/fill_annotation_impl.cpp
index fe520451f7..0c69bc4fe5 100644
--- a/src/mbgl/annotation/fill_annotation_impl.cpp
+++ b/src/mbgl/annotation/fill_annotation_impl.cpp
@@ -13,16 +13,19 @@ FillAnnotationImpl::FillAnnotationImpl(AnnotationID id_, FillAnnotation annotati
}
void FillAnnotationImpl::updateStyle(Style& style) const {
- if (style.getLayer(layerID))
- return;
-
- std::unique_ptr<FillLayer> layer = std::make_unique<FillLayer>(layerID, AnnotationManager::SourceID);
- layer->setSourceLayer(layerID);
- layer->setFillOpacity(annotation.opacity);
- layer->setFillColor(annotation.color);
- layer->setFillOutlineColor(annotation.outlineColor);
-
- style.addLayer(std::move(layer), AnnotationManager::PointLayerID);
+ Layer* layer = style.getLayer(layerID);
+ FillLayer* fillLayer = layer ? layer->as<FillLayer>() : nullptr;
+
+ if (!fillLayer) {
+ fillLayer = style.addLayer(
+ std::make_unique<FillLayer>(layerID, AnnotationManager::SourceID),
+ AnnotationManager::PointLayerID)->as<FillLayer>();
+ fillLayer->setSourceLayer(layerID);
+ }
+
+ fillLayer->setFillOpacity(annotation.opacity);
+ fillLayer->setFillColor(annotation.color);
+ fillLayer->setFillOutlineColor(annotation.outlineColor);
}
const ShapeAnnotationGeometry& FillAnnotationImpl::geometry() const {
diff --git a/src/mbgl/annotation/line_annotation_impl.cpp b/src/mbgl/annotation/line_annotation_impl.cpp
index f18ca9fadc..5ec5a2a49f 100644
--- a/src/mbgl/annotation/line_annotation_impl.cpp
+++ b/src/mbgl/annotation/line_annotation_impl.cpp
@@ -13,17 +13,20 @@ LineAnnotationImpl::LineAnnotationImpl(AnnotationID id_, LineAnnotation annotati
}
void LineAnnotationImpl::updateStyle(Style& style) const {
- if (style.getLayer(layerID))
- return;
-
- std::unique_ptr<LineLayer> layer = std::make_unique<LineLayer>(layerID, AnnotationManager::SourceID);
- layer->setSourceLayer(layerID);
- layer->setLineJoin(LineJoinType::Round);
- layer->setLineOpacity(annotation.opacity);
- layer->setLineWidth(annotation.width);
- layer->setLineColor(annotation.color);
-
- style.addLayer(std::move(layer), AnnotationManager::PointLayerID);
+ Layer* layer = style.getLayer(layerID);
+ LineLayer* lineLayer = layer ? layer->as<LineLayer>() : nullptr;
+
+ if (!lineLayer) {
+ lineLayer = style.addLayer(
+ std::make_unique<LineLayer>(layerID, AnnotationManager::SourceID),
+ AnnotationManager::PointLayerID)->as<LineLayer>();
+ lineLayer->setSourceLayer(layerID);
+ }
+
+ lineLayer->setLineJoin(LineJoinType::Round);
+ lineLayer->setLineOpacity(annotation.opacity);
+ lineLayer->setLineWidth(annotation.width);
+ lineLayer->setLineColor(annotation.color);
}
const ShapeAnnotationGeometry& LineAnnotationImpl::geometry() const {
diff --git a/src/mbgl/style/style.cpp b/src/mbgl/style/style.cpp
index e04384a96e..ae6bc14b8b 100644
--- a/src/mbgl/style/style.cpp
+++ b/src/mbgl/style/style.cpp
@@ -154,7 +154,7 @@ Layer* Style::getLayer(const std::string& id) const {
return it != layers.end() ? it->get() : nullptr;
}
-void Style::addLayer(std::unique_ptr<Layer> layer, optional<std::string> before) {
+Layer* Style::addLayer(std::unique_ptr<Layer> layer, optional<std::string> before) {
// TODO: verify source
if (SymbolLayer* symbolLayer = layer->as<SymbolLayer>()) {
@@ -167,7 +167,7 @@ void Style::addLayer(std::unique_ptr<Layer> layer, optional<std::string> before)
customLayer->impl->initialize();
}
- layers.emplace(before ? findLayer(*before) : layers.end(), std::move(layer));
+ return layers.emplace(before ? findLayer(*before) : layers.end(), std::move(layer))->get();
}
void Style::removeLayer(const std::string& id) {
diff --git a/src/mbgl/style/style.hpp b/src/mbgl/style/style.hpp
index 149a0f0803..06a25385b6 100644
--- a/src/mbgl/style/style.hpp
+++ b/src/mbgl/style/style.hpp
@@ -65,8 +65,8 @@ public:
std::vector<const Layer*> getLayers() const;
Layer* getLayer(const std::string& id) const;
- void addLayer(std::unique_ptr<Layer>,
- optional<std::string> beforeLayerID = {});
+ Layer* addLayer(std::unique_ptr<Layer>,
+ optional<std::string> beforeLayerID = {});
void removeLayer(const std::string& layerID);
std::string getName() const;