diff --git a/src/mbgl/style/source_impl.hpp b/src/mbgl/style/source_impl.hpp index 0de3760fc31..c7ed36b3c22 100644 --- a/src/mbgl/style/source_impl.hpp +++ b/src/mbgl/style/source_impl.hpp @@ -83,6 +83,7 @@ class Source::Impl : public TileObserver, private util::noncopyable { Source& base; SourceObserver* observer = nullptr; + std::map> tiles; private: // TileObserver implementation. @@ -93,7 +94,6 @@ class Source::Impl : public TileObserver, private util::noncopyable { virtual Range getZoomRange() = 0; virtual std::unique_ptr createTile(const OverscaledTileID&, const UpdateParameters&) = 0; - std::map> tiles; std::map renderTiles; TileCache cache; }; diff --git a/src/mbgl/style/sources/geojson_source_impl.cpp b/src/mbgl/style/sources/geojson_source_impl.cpp index 032576b47e9..5b7ba4fc773 100644 --- a/src/mbgl/style/sources/geojson_source_impl.cpp +++ b/src/mbgl/style/sources/geojson_source_impl.cpp @@ -65,6 +65,24 @@ void GeoJSONSource::Impl::setGeoJSON(const GeoJSON& geoJSON) { geoJSONOrSupercluster = std::make_unique(features, clusterOptions); } + + for (auto const &item : tiles) { + GeoJSONTile* geoJSONTile = static_cast(item.second.get()); + setTileData(*geoJSONTile, geoJSONTile->id); + } +} + +void GeoJSONSource::Impl::setTileData(GeoJSONTile& tile, const OverscaledTileID& tileID) { + if (geoJSONOrSupercluster.is()) { + tile.updateData(geoJSONOrSupercluster.get()->getTile(tileID.canonical.z, + tileID.canonical.x, + tileID.canonical.y).features); + } else { + assert(geoJSONOrSupercluster.is()); + tile.updateData(geoJSONOrSupercluster.get()->getTile(tileID.canonical.z, + tileID.canonical.x, + tileID.canonical.y)); + } } void GeoJSONSource::Impl::loadDescription(FileSource& fileSource) { @@ -126,20 +144,9 @@ Range GeoJSONSource::Impl::getZoomRange() { std::unique_ptr GeoJSONSource::Impl::createTile(const OverscaledTileID& tileID, const UpdateParameters& parameters) { assert(loaded); - if (geoJSONOrSupercluster.is()) { - return std::make_unique(tileID, base.getID(), parameters, - geoJSONOrSupercluster.get()->getTile( - tileID.canonical.z, - tileID.canonical.x, - tileID.canonical.y).features); - } else { - assert(geoJSONOrSupercluster.is()); - return std::make_unique(tileID, base.getID(), parameters, - geoJSONOrSupercluster.get()->getTile( - tileID.canonical.z, - tileID.canonical.x, - tileID.canonical.y)); - } + auto tilePointer = std::make_unique(tileID, base.getID(), parameters); + setTileData(*tilePointer.get(), tileID); + return std::move(tilePointer); } } // namespace style diff --git a/src/mbgl/style/sources/geojson_source_impl.hpp b/src/mbgl/style/sources/geojson_source_impl.hpp index cf079e472ce..9572355f2c8 100644 --- a/src/mbgl/style/sources/geojson_source_impl.hpp +++ b/src/mbgl/style/sources/geojson_source_impl.hpp @@ -3,6 +3,7 @@ #include #include #include +#include namespace mbgl { @@ -19,6 +20,7 @@ class GeoJSONSource::Impl : public Source::Impl { optional getURL(); void setGeoJSON(const GeoJSON&); + void setTileData(GeoJSONTile&, const OverscaledTileID& tileID); void loadDescription(FileSource&) final; diff --git a/src/mbgl/tile/geojson_tile.cpp b/src/mbgl/tile/geojson_tile.cpp index 2b302e14ec3..61437b79b1a 100644 --- a/src/mbgl/tile/geojson_tile.cpp +++ b/src/mbgl/tile/geojson_tile.cpp @@ -77,9 +77,11 @@ class GeoJSONTileData : public GeometryTileData, GeoJSONTile::GeoJSONTile(const OverscaledTileID& overscaledTileID, std::string sourceID_, - const style::UpdateParameters& parameters, - const mapbox::geometry::feature_collection& features) + const style::UpdateParameters& parameters) : GeometryTile(overscaledTileID, sourceID_, parameters) { +} + +void GeoJSONTile::updateData(const mapbox::geometry::feature_collection& features) { setData(std::make_unique(features)); } diff --git a/src/mbgl/tile/geojson_tile.hpp b/src/mbgl/tile/geojson_tile.hpp index be5a50c7a4a..28804087366 100644 --- a/src/mbgl/tile/geojson_tile.hpp +++ b/src/mbgl/tile/geojson_tile.hpp @@ -13,9 +13,10 @@ class GeoJSONTile : public GeometryTile { public: GeoJSONTile(const OverscaledTileID&, std::string sourceID, - const style::UpdateParameters&, - const mapbox::geometry::feature_collection&); + const style::UpdateParameters&); + void updateData(const mapbox::geometry::feature_collection&); + void setNecessity(Necessity) final; };