diff options
Diffstat (limited to 'src/mbgl/tile')
-rw-r--r-- | src/mbgl/tile/geojson_tile_data.hpp | 18 | ||||
-rw-r--r-- | src/mbgl/tile/geometry_tile.cpp | 2 | ||||
-rw-r--r-- | src/mbgl/tile/geometry_tile_data.cpp | 35 | ||||
-rw-r--r-- | src/mbgl/tile/geometry_tile_data.hpp | 50 | ||||
-rw-r--r-- | src/mbgl/tile/geometry_tile_worker.cpp | 2 | ||||
-rw-r--r-- | src/mbgl/tile/vector_tile_data.cpp | 22 | ||||
-rw-r--r-- | src/mbgl/tile/vector_tile_data.hpp | 6 |
7 files changed, 68 insertions, 67 deletions
diff --git a/src/mbgl/tile/geojson_tile_data.hpp b/src/mbgl/tile/geojson_tile_data.hpp index 3605af9690..5559965cd7 100644 --- a/src/mbgl/tile/geojson_tile_data.hpp +++ b/src/mbgl/tile/geojson_tile_data.hpp @@ -17,7 +17,7 @@ public: return apply_visitor(ToFeatureType(), feature.geometry); } - PropertyMap getProperties() const override { + const PropertyMap& getProperties() const override { return feature.properties; } @@ -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 { diff --git a/src/mbgl/tile/geometry_tile.cpp b/src/mbgl/tile/geometry_tile.cpp index 7f1bed49f4..a431ae423e 100644 --- a/src/mbgl/tile/geometry_tile.cpp +++ b/src/mbgl/tile/geometry_tile.cpp @@ -360,7 +360,7 @@ void GeometryTile::querySourceFeatures( continue; } - result.push_back(convertFeature(*feature, id.canonical)); + result.emplace_back(convertFeature(*feature, id.canonical)); } } } diff --git a/src/mbgl/tile/geometry_tile_data.cpp b/src/mbgl/tile/geometry_tile_data.cpp index 680f8d1497..5320df6893 100644 --- a/src/mbgl/tile/geometry_tile_data.cpp +++ b/src/mbgl/tile/geometry_tile_data.cpp @@ -57,32 +57,31 @@ std::vector<GeometryCollection> classifyRings(const GeometryCollection& rings) { std::size_t len = rings.size(); if (len <= 1) { - polygons.push_back(rings); + polygons.emplace_back(rings.clone()); return polygons; } GeometryCollection polygon; int8_t ccw = 0; - for (std::size_t i = 0; i < len; i++) { - double area = signedArea(rings[i]); - - if (area == 0) - continue; + for (const auto& ring : rings) { + double area = signedArea(ring); + if (area == 0) continue; - if (ccw == 0) + if (ccw == 0) { ccw = (area < 0 ? -1 : 1); + } if (ccw == (area < 0 ? -1 : 1) && !polygon.empty()) { - polygons.push_back(polygon); - polygon.clear(); + polygons.emplace_back(std::move(polygon)); } - polygon.push_back(rings[i]); + polygon.emplace_back(ring); } - if (!polygon.empty()) - polygons.push_back(polygon); + if (!polygon.empty()) { + polygons.emplace_back(std::move(polygon)); + } return polygons; } @@ -112,7 +111,7 @@ static Feature::geometry_type convertGeometry(const GeometryTileFeature& geometr ); }; - GeometryCollection geometries = geometryTileFeature.getGeometries(); + const GeometryCollection& geometries = geometryTileFeature.getGeometries(); switch (geometryTileFeature.getType()) { case FeatureType::Unknown: { @@ -180,4 +179,14 @@ Feature convertFeature(const GeometryTileFeature& geometryTileFeature, const Can return feature; } +const PropertyMap& GeometryTileFeature::getProperties() const { + static const PropertyMap dummy; + return dummy; +} + +const GeometryCollection& GeometryTileFeature::getGeometries() const { + static const GeometryCollection dummy; + return dummy; +} + } // namespace mbgl diff --git a/src/mbgl/tile/geometry_tile_data.hpp b/src/mbgl/tile/geometry_tile_data.hpp index 6ce67a532e..5d43a68388 100644 --- a/src/mbgl/tile/geometry_tile_data.hpp +++ b/src/mbgl/tile/geometry_tile_data.hpp @@ -35,6 +35,13 @@ public: GeometryCollection(Args&&... args) : std::vector<GeometryCoordinates>(std::forward<Args>(args)...) {} GeometryCollection(std::initializer_list<GeometryCoordinates> args) : std::vector<GeometryCoordinates>(std::move(args)) {} + GeometryCollection(GeometryCollection&&) = default; + GeometryCollection& operator=(GeometryCollection&&) = default; + + GeometryCollection clone() const { return GeometryCollection(*this); } + +private: + GeometryCollection(const GeometryCollection&) = default; }; class GeometryTileFeature { @@ -42,9 +49,9 @@ public: virtual ~GeometryTileFeature() = default; virtual FeatureType getType() const = 0; virtual optional<Value> getValue(const std::string& key) const = 0; - virtual PropertyMap getProperties() const { return PropertyMap(); } + virtual const PropertyMap& getProperties() const; virtual FeatureIdentifier getID() const { return NullValue {}; } - virtual GeometryCollection getGeometries() const = 0; + virtual const GeometryCollection& getGeometries() const; }; class GeometryTileLayer { @@ -90,31 +97,16 @@ struct ToGeometryCollection { return { { geom } }; } GeometryCollection operator()(const mapbox::geometry::multi_point<int16_t>& geom) const { - GeometryCoordinates coordinates; - coordinates.reserve(geom.size()); - for (const auto& point : geom) { - coordinates.emplace_back(point); - } - return { coordinates }; + return { geom }; } GeometryCollection operator()(const mapbox::geometry::line_string<int16_t>& geom) const { - GeometryCoordinates coordinates; - coordinates.reserve(geom.size()); - for (const auto& point : geom) { - coordinates.emplace_back(point); - } - return { coordinates }; + return { geom }; } GeometryCollection operator()(const mapbox::geometry::multi_line_string<int16_t>& geom) const { GeometryCollection collection; collection.reserve(geom.size()); for (const auto& ring : geom) { - GeometryCoordinates coordinates; - coordinates.reserve(ring.size()); - for (const auto& point : ring) { - coordinates.emplace_back(point); - } - collection.push_back(std::move(coordinates)); + collection.emplace_back(ring); } return collection; } @@ -122,25 +114,15 @@ struct ToGeometryCollection { GeometryCollection collection; collection.reserve(geom.size()); for (const auto& ring : geom) { - GeometryCoordinates coordinates; - coordinates.reserve(ring.size()); - for (const auto& point : ring) { - coordinates.emplace_back(point); - } - collection.push_back(std::move(coordinates)); + collection.emplace_back(ring); } return collection; } GeometryCollection operator()(const mapbox::geometry::multi_polygon<int16_t>& geom) const { GeometryCollection collection; - for (auto& polygon : geom) { - for (auto& ring : polygon) { - GeometryCoordinates coordinates; - coordinates.reserve(ring.size()); - for (auto& point : ring) { - coordinates.emplace_back(point); - } - collection.push_back(std::move(coordinates)); + for (const auto& polygon : geom) { + for (const auto& ring : polygon) { + collection.emplace_back(ring); } } return collection; diff --git a/src/mbgl/tile/geometry_tile_worker.cpp b/src/mbgl/tile/geometry_tile_worker.cpp index a69825d346..f4d57e5bfc 100644 --- a/src/mbgl/tile/geometry_tile_worker.cpp +++ b/src/mbgl/tile/geometry_tile_worker.cpp @@ -382,7 +382,7 @@ void GeometryTileWorker::parse() { if (!filter(expression::EvaluationContext { static_cast<float>(this->id.overscaledZ), feature.get() })) continue; - GeometryCollection geometries = feature->getGeometries(); + const GeometryCollection& geometries = feature->getGeometries(); bucket->addFeature(*feature, geometries, {}, PatternLayerMap ()); featureIndex->insert(geometries, i, sourceLayerID, leaderImpl.id); } diff --git a/src/mbgl/tile/vector_tile_data.cpp b/src/mbgl/tile/vector_tile_data.cpp index 2d47515e0f..d53f1deba6 100644 --- a/src/mbgl/tile/vector_tile_data.cpp +++ b/src/mbgl/tile/vector_tile_data.cpp @@ -26,22 +26,26 @@ optional<Value> VectorTileFeature::getValue(const std::string& key) const { return value->is<NullValue>() ? nullopt : std::move(value); } -std::unordered_map<std::string, Value> VectorTileFeature::getProperties() const { - return feature.getProperties(); +const PropertyMap& VectorTileFeature::getProperties() const { + if (!properties) { + properties = feature.getProperties(); + } + return *properties; } 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_, diff --git a/src/mbgl/tile/vector_tile_data.hpp b/src/mbgl/tile/vector_tile_data.hpp index 7c95121a37..f5086936f8 100644 --- a/src/mbgl/tile/vector_tile_data.hpp +++ b/src/mbgl/tile/vector_tile_data.hpp @@ -15,12 +15,14 @@ public: FeatureType getType() const override; optional<Value> getValue(const std::string& key) const override; - std::unordered_map<std::string, Value> getProperties() const override; + const PropertyMap& 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; + mutable optional<PropertyMap> properties; }; class VectorTileLayer : public GeometryTileLayer { |