[core] Force getGeometries() return const ref
This commit is contained in:
committed by
Mikhail Pozdnyakov
parent
6798d21eda
commit
852fef66ef
@@ -35,7 +35,7 @@ public:
|
||||
return properties.count(key) ? properties.at(key) : optional<Value>();
|
||||
}
|
||||
|
||||
GeometryCollection getGeometries() const override {
|
||||
const GeometryCollection& getGeometries() const override {
|
||||
return geometry;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -58,7 +58,7 @@ FeatureIdentifier AnnotationTileFeature::getID() const {
|
||||
return data->id;
|
||||
}
|
||||
|
||||
GeometryCollection AnnotationTileFeature::getGeometries() const {
|
||||
const GeometryCollection& AnnotationTileFeature::getGeometries() const {
|
||||
return data->geometries;
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ public:
|
||||
FeatureType getType() const override;
|
||||
optional<Value> getValue(const std::string&) const override;
|
||||
FeatureIdentifier getID() const override;
|
||||
GeometryCollection getGeometries() const override;
|
||||
const GeometryCollection& getGeometries() const override;
|
||||
|
||||
private:
|
||||
std::shared_ptr<const AnnotationTileFeatureData> data;
|
||||
|
||||
@@ -159,7 +159,7 @@ void FeatureIndex::addFeature(
|
||||
continue;
|
||||
}
|
||||
|
||||
result[layerID].push_back(convertFeature(*geometryTileFeature, tileID));
|
||||
result[layerID].emplace_back(convertFeature(*geometryTileFeature, tileID));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ public:
|
||||
optional<Value> getValue(const std::string& key) const override { return feature->getValue(key); };
|
||||
std::unordered_map<std::string,Value> getProperties() const override { return feature->getProperties(); };
|
||||
FeatureIdentifier getID() const override { return feature->getID(); };
|
||||
GeometryCollection getGeometries() const override { return geometry; };
|
||||
const GeometryCollection& getGeometries() const override { return geometry; };
|
||||
|
||||
friend bool operator < (const SymbolFeature& lhs, const SymbolFeature& rhs) {
|
||||
return lhs.sortKey < rhs.sortKey;
|
||||
|
||||
@@ -167,7 +167,7 @@ bool RenderCircleLayer::queryIntersectsFeature(
|
||||
projectQueryGeometry(translatedQueryGeometry, posMatrix, transformState.getSize());
|
||||
auto transformedSize = alignWithMap ? size * pixelsToTileUnits : size;
|
||||
|
||||
auto geometry = feature.getGeometries();
|
||||
const auto& geometry = feature.getGeometries();
|
||||
for (auto& ring : geometry) {
|
||||
for (auto& point : ring) {
|
||||
const GeometryCoordinate& transformedPoint = alignWithMap ? point : projectPoint(point, posMatrix, transformState.getSize());
|
||||
|
||||
@@ -17,7 +17,7 @@ public:
|
||||
}
|
||||
PropertyMap getProperties() const override { return feature.properties; }
|
||||
FeatureIdentifier getID() const override { return feature.id; }
|
||||
GeometryCollection getGeometries() const override { return {}; }
|
||||
const GeometryCollection& getGeometries() const override { return geometry; }
|
||||
optional<mbgl::Value> getValue(const std::string& key) const override {
|
||||
auto it = feature.properties.find(key);
|
||||
if (it != feature.properties.end()) {
|
||||
@@ -25,6 +25,8 @@ public:
|
||||
}
|
||||
return optional<mbgl::Value>();
|
||||
}
|
||||
|
||||
GeometryCollection geometry;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -25,15 +25,17 @@ public:
|
||||
return feature.id;
|
||||
}
|
||||
|
||||
GeometryCollection getGeometries() const override {
|
||||
GeometryCollection geometry = apply_visitor(ToGeometryCollection(), feature.geometry);
|
||||
const GeometryCollection& getGeometries() const override {
|
||||
if (!geometry) {
|
||||
geometry = apply_visitor(ToGeometryCollection(), feature.geometry);
|
||||
|
||||
// https://github.com/mapbox/geojson-vt-cpp/issues/44
|
||||
if (getType() == FeatureType::Polygon) {
|
||||
geometry = fixupPolygons(geometry);
|
||||
// https://github.com/mapbox/geojson-vt-cpp/issues/44
|
||||
if (getType() == FeatureType::Polygon) {
|
||||
geometry = fixupPolygons(*geometry);
|
||||
}
|
||||
}
|
||||
|
||||
return geometry;
|
||||
return *geometry;
|
||||
}
|
||||
|
||||
optional<Value> getValue(const std::string& key) const override {
|
||||
@@ -43,6 +45,8 @@ public:
|
||||
}
|
||||
return optional<Value>();
|
||||
}
|
||||
|
||||
mutable optional<GeometryCollection> geometry;
|
||||
};
|
||||
|
||||
class GeoJSONTileLayer : public GeometryTileLayer {
|
||||
|
||||
@@ -360,7 +360,7 @@ void GeometryTile::querySourceFeatures(
|
||||
continue;
|
||||
}
|
||||
|
||||
result.push_back(convertFeature(*feature, id.canonical));
|
||||
result.emplace_back(convertFeature(*feature, id.canonical));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,7 +112,7 @@ static Feature::geometry_type convertGeometry(const GeometryTileFeature& geometr
|
||||
);
|
||||
};
|
||||
|
||||
GeometryCollection geometries = geometryTileFeature.getGeometries();
|
||||
const GeometryCollection& geometries = geometryTileFeature.getGeometries();
|
||||
|
||||
switch (geometryTileFeature.getType()) {
|
||||
case FeatureType::Unknown: {
|
||||
|
||||
@@ -44,7 +44,7 @@ public:
|
||||
virtual optional<Value> getValue(const std::string& key) const = 0;
|
||||
virtual PropertyMap getProperties() const { return PropertyMap(); }
|
||||
virtual FeatureIdentifier getID() const { return NullValue {}; }
|
||||
virtual GeometryCollection getGeometries() const = 0;
|
||||
virtual const GeometryCollection& getGeometries() const = 0;
|
||||
};
|
||||
|
||||
class GeometryTileLayer {
|
||||
|
||||
@@ -34,14 +34,15 @@ FeatureIdentifier VectorTileFeature::getID() const {
|
||||
return feature.getID();
|
||||
}
|
||||
|
||||
GeometryCollection VectorTileFeature::getGeometries() const {
|
||||
const float scale = float(util::EXTENT) / feature.getExtent();
|
||||
auto lines = feature.getGeometries<GeometryCollection>(scale);
|
||||
if (feature.getVersion() >= 2 || feature.getType() != mapbox::vector_tile::GeomType::POLYGON) {
|
||||
return lines;
|
||||
} else {
|
||||
return fixupPolygons(lines);
|
||||
const GeometryCollection& VectorTileFeature::getGeometries() const {
|
||||
if (!lines) {
|
||||
const float scale = float(util::EXTENT) / feature.getExtent();
|
||||
lines = feature.getGeometries<GeometryCollection>(scale);
|
||||
if (feature.getVersion() < 2 && feature.getType() == mapbox::vector_tile::GeomType::POLYGON) {
|
||||
lines = fixupPolygons(*lines);
|
||||
}
|
||||
}
|
||||
return *lines;
|
||||
}
|
||||
|
||||
VectorTileLayer::VectorTileLayer(std::shared_ptr<const std::string> data_,
|
||||
|
||||
@@ -17,10 +17,11 @@ public:
|
||||
optional<Value> getValue(const std::string& key) const override;
|
||||
std::unordered_map<std::string, Value> getProperties() const override;
|
||||
FeatureIdentifier getID() const override;
|
||||
GeometryCollection getGeometries() const override;
|
||||
const GeometryCollection& getGeometries() const override;
|
||||
|
||||
private:
|
||||
mapbox::vector_tile::feature feature;
|
||||
mutable optional<GeometryCollection> lines;
|
||||
};
|
||||
|
||||
class VectorTileLayer : public GeometryTileLayer {
|
||||
|
||||
@@ -33,7 +33,7 @@ public:
|
||||
return properties.count(key) ? properties.at(key) : optional<Value>();
|
||||
}
|
||||
|
||||
GeometryCollection getGeometries() const override {
|
||||
const GeometryCollection& getGeometries() const override {
|
||||
return geometry;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user