[core] shared data among AnnotationTileFeature objects
This commit is contained in:
@@ -19,26 +19,64 @@ AnnotationTile::~AnnotationTile() {
|
||||
annotationManager.removeTile(*this);
|
||||
}
|
||||
|
||||
void AnnotationTile::setNecessity(Necessity) {}
|
||||
void AnnotationTile::setNecessity(Necessity) {
|
||||
}
|
||||
|
||||
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_)) {}
|
||||
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_)) {
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user