[core] shared data among AnnotationTileFeature objects
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user