summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/mbgl/annotation/annotation_manager.cpp2
-rw-r--r--src/mbgl/annotation/annotation_tile.cpp67
-rw-r--r--src/mbgl/annotation/annotation_tile.hpp37
-rw-r--r--src/mbgl/annotation/shape_annotation_impl.cpp4
-rw-r--r--src/mbgl/annotation/symbol_annotation_impl.cpp2
5 files changed, 82 insertions, 30 deletions
diff --git a/src/mbgl/annotation/annotation_manager.cpp b/src/mbgl/annotation/annotation_manager.cpp
index 05b1b13d2d..bc23a94adf 100644
--- a/src/mbgl/annotation/annotation_manager.cpp
+++ b/src/mbgl/annotation/annotation_manager.cpp
@@ -133,7 +133,7 @@ std::unique_ptr<AnnotationTileData> AnnotationManager::getTileData(const Canonic
auto tileData = std::make_unique<AnnotationTileData>();
- AnnotationTileLayer& pointLayer = tileData->layers.emplace(PointLayerID, PointLayerID).first->second;
+ AnnotationTileLayer& pointLayer = tileData->addLayer(PointLayerID);
LatLngBounds tileBounds(tileID);
diff --git a/src/mbgl/annotation/annotation_tile.cpp b/src/mbgl/annotation/annotation_tile.cpp
index 67a2d128ba..e8c62effd8 100644
--- a/src/mbgl/annotation/annotation_tile.cpp
+++ b/src/mbgl/annotation/annotation_tile.cpp
@@ -19,26 +19,64 @@ AnnotationTile::~AnnotationTile() {
annotationManager.removeTile(*this);
}
-void AnnotationTile::setNecessity(Necessity) {}
+void AnnotationTile::setNecessity(Necessity) {
+}
+
+class AnnotationTileFeatureData {
+public:
+ AnnotationTileFeatureData(const AnnotationID id_,
+ FeatureType type_,
+ GeometryCollection&& geometries_,
+ std::unordered_map<std::string, std::string>&& properties_)
+ : id(id_),
+ type(type_),
+ geometries(std::move(geometries_)),
+ properties(std::move(properties_)) {
+ }
-AnnotationTileFeature::AnnotationTileFeature(const AnnotationID id_,
- FeatureType type_, GeometryCollection geometries_,
- std::unordered_map<std::string, std::string> properties_)
- : id(id_),
- type(type_),
- properties(std::move(properties_)),
- geometries(std::move(geometries_)) {}
+ AnnotationID id;
+ FeatureType type;
+ GeometryCollection geometries;
+ std::unordered_map<std::string, std::string> properties;
+};
+
+AnnotationTileFeature::AnnotationTileFeature(std::shared_ptr<const AnnotationTileFeatureData> data_)
+ : data(std::move(data_)) {
+}
+
+AnnotationTileFeature::~AnnotationTileFeature() = default;
+
+FeatureType AnnotationTileFeature::getType() const {
+ return data->type;
+}
optional<Value> AnnotationTileFeature::getValue(const std::string& key) const {
- auto it = properties.find(key);
- if (it != properties.end()) {
+ auto it = data->properties.find(key);
+ if (it != data->properties.end()) {
return optional<Value>(it->second);
}
return optional<Value>();
}
-AnnotationTileLayer::AnnotationTileLayer(std::string name_)
- : name(std::move(name_)) {}
+optional<FeatureIdentifier> AnnotationTileFeature::getID() const {
+ return { static_cast<uint64_t>(data->id) };
+}
+
+GeometryCollection AnnotationTileFeature::getGeometries() const {
+ return data->geometries;
+}
+
+AnnotationTileLayer::AnnotationTileLayer(std::string name_) : name(std::move(name_)) {
+}
+
+void AnnotationTileLayer::addFeature(const AnnotationID id,
+ FeatureType type,
+ GeometryCollection geometries,
+ std::unordered_map<std::string, std::string> properties) {
+
+ features.emplace_back(std::make_shared<AnnotationTileFeatureData>(
+ id, type, std::move(geometries), std::move(properties)));
+}
std::unique_ptr<GeometryTileData> AnnotationTileData::clone() const {
return std::make_unique<AnnotationTileData>(*this);
@@ -52,4 +90,9 @@ const GeometryTileLayer* AnnotationTileData::getLayer(const std::string& name) c
return nullptr;
}
+AnnotationTileLayer& AnnotationTileData::addLayer(const std::string& name) {
+ // Only constructs a new layer if it doesn't yet exist, otherwise, we'll use the existing one.
+ return layers.emplace(name, name).first->second;
+}
+
} // namespace mbgl
diff --git a/src/mbgl/annotation/annotation_tile.hpp b/src/mbgl/annotation/annotation_tile.hpp
index ea4ff5ebd5..68a4d342ac 100644
--- a/src/mbgl/annotation/annotation_tile.hpp
+++ b/src/mbgl/annotation/annotation_tile.hpp
@@ -11,8 +11,7 @@ class TileParameters;
class AnnotationTile : public GeometryTile {
public:
- AnnotationTile(const OverscaledTileID&,
- const TileParameters&);
+ AnnotationTile(const OverscaledTileID&, const TileParameters&);
~AnnotationTile() override;
void setNecessity(Necessity) final;
@@ -21,37 +20,45 @@ private:
AnnotationManager& annotationManager;
};
+class AnnotationTileFeatureData;
+
class AnnotationTileFeature : public GeometryTileFeature {
public:
- AnnotationTileFeature(AnnotationID, FeatureType, GeometryCollection,
- std::unordered_map<std::string, std::string> properties = {{}});
+ AnnotationTileFeature(std::shared_ptr<const AnnotationTileFeatureData>);
+ ~AnnotationTileFeature() override;
- FeatureType getType() const override { return type; }
+ FeatureType getType() const override;
optional<Value> getValue(const std::string&) const override;
- optional<FeatureIdentifier> getID() const override { return { static_cast<uint64_t>(id) }; }
- GeometryCollection getGeometries() const override { return geometries; }
+ optional<FeatureIdentifier> getID() const override;
+ GeometryCollection getGeometries() const override;
- const AnnotationID id;
- const FeatureType type;
- const std::unordered_map<std::string, std::string> properties;
- const GeometryCollection geometries;
+private:
+ std::shared_ptr<const AnnotationTileFeatureData> data;
};
class AnnotationTileLayer : public GeometryTileLayer {
public:
AnnotationTileLayer(std::string);
- std::size_t featureCount() const override { return features.size(); }
+ std::size_t featureCount() const override {
+ return features.size();
+ }
std::unique_ptr<GeometryTileFeature> getFeature(std::size_t i) const override {
return std::make_unique<AnnotationTileFeature>(features.at(i));
}
- std::string getName() const override { return name; };
+ std::string getName() const override {
+ return name;
+ }
- std::vector<AnnotationTileFeature> features;
+ void addFeature(const AnnotationID,
+ FeatureType,
+ GeometryCollection,
+ std::unordered_map<std::string, std::string> properties = { {} });
private:
+ std::vector<std::shared_ptr<const AnnotationTileFeatureData>> features;
std::string name;
};
@@ -59,7 +66,9 @@ class AnnotationTileData : public GeometryTileData {
public:
std::unique_ptr<GeometryTileData> clone() const override;
const GeometryTileLayer* getLayer(const std::string&) const override;
+ AnnotationTileLayer& addLayer(const std::string&);
+private:
std::unordered_map<std::string, AnnotationTileLayer> layers;
};
diff --git a/src/mbgl/annotation/shape_annotation_impl.cpp b/src/mbgl/annotation/shape_annotation_impl.cpp
index d3ddf62b9e..05ffce382d 100644
--- a/src/mbgl/annotation/shape_annotation_impl.cpp
+++ b/src/mbgl/annotation/shape_annotation_impl.cpp
@@ -38,7 +38,7 @@ void ShapeAnnotationImpl::updateTileData(const CanonicalTileID& tileID, Annotati
if (shapeTile.features.empty())
return;
- AnnotationTileLayer& layer = data.layers.emplace(layerID, layerID).first->second;
+ AnnotationTileLayer& layer = data.addLayer(layerID);
ToGeometryCollection toGeometryCollection;
ToFeatureType toFeatureType;
@@ -53,7 +53,7 @@ void ShapeAnnotationImpl::updateTileData(const CanonicalTileID& tileID, Annotati
renderGeometry = fixupPolygons(renderGeometry);
}
- layer.features.emplace_back(id, featureType, renderGeometry);
+ layer.addFeature(id, featureType, renderGeometry);
}
}
diff --git a/src/mbgl/annotation/symbol_annotation_impl.cpp b/src/mbgl/annotation/symbol_annotation_impl.cpp
index e5ae5f4b91..c95eb481b5 100644
--- a/src/mbgl/annotation/symbol_annotation_impl.cpp
+++ b/src/mbgl/annotation/symbol_annotation_impl.cpp
@@ -18,7 +18,7 @@ void SymbolAnnotationImpl::updateLayer(const CanonicalTileID& tileID, Annotation
LatLng latLng { annotation.geometry.y, annotation.geometry.x };
TileCoordinate coordinate = TileCoordinate::fromLatLng(0, latLng);
GeometryCoordinate tilePoint = TileCoordinate::toGeometryCoordinate(UnwrappedTileID(0, tileID), coordinate.p);
- layer.features.emplace_back(id, FeatureType::Point, GeometryCollection {{ {{ tilePoint }} }}, featureProperties);
+ layer.addFeature(id, FeatureType::Point, GeometryCollection {{ {{ tilePoint }} }}, featureProperties);
}
} // namespace mbgl