diff options
author | John Firebaugh <john.firebaugh@gmail.com> | 2017-04-20 17:11:50 -0700 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2017-05-02 08:45:09 -0700 |
commit | 3f0c89d633a5056006557ad5f4b9e446807d00ee (patch) | |
tree | 5405c50dd26a5a393a982e8e0f76b764dbbccf48 /src/mbgl/style/sources/geojson_source_impl.cpp | |
parent | 197751bace6181f2c2dbe4c890f277a0dc7e58b1 (diff) | |
download | qtlocation-mapboxgl-3f0c89d633a5056006557ad5f4b9e446807d00ee.tar.gz |
[core] Refactor Source::*Impls into RenderSources and TilePyramid
Diffstat (limited to 'src/mbgl/style/sources/geojson_source_impl.cpp')
-rw-r--r-- | src/mbgl/style/sources/geojson_source_impl.cpp | 89 |
1 files changed, 45 insertions, 44 deletions
diff --git a/src/mbgl/style/sources/geojson_source_impl.cpp b/src/mbgl/style/sources/geojson_source_impl.cpp index 6431d5faa4..08ed95ea3f 100644 --- a/src/mbgl/style/sources/geojson_source_impl.cpp +++ b/src/mbgl/style/sources/geojson_source_impl.cpp @@ -1,10 +1,12 @@ -#include <mbgl/util/logging.hpp> -#include <mbgl/storage/file_source.hpp> +#include <mbgl/style/sources/geojson_source_impl.hpp> #include <mbgl/style/conversion/geojson.hpp> #include <mbgl/style/source_observer.hpp> -#include <mbgl/style/sources/geojson_source_impl.hpp> -#include <mbgl/tile/geojson_tile.hpp> +#include <mbgl/tile/tile_id.hpp> +#include <mbgl/storage/file_source.hpp> +#include <mbgl/renderer/sources/render_geojson_source.hpp> #include <mbgl/util/rapidjson.hpp> +#include <mbgl/util/constants.cpp> +#include <mbgl/util/logging.hpp> #include <mapbox/geojson.hpp> #include <mapbox/geojson/rapidjson.hpp> @@ -31,6 +33,34 @@ optional<GeoJSON> convertGeoJSON(const JSValue& value, Error& error) { } } // namespace conversion +class GeoJSONVTData : public GeoJSONData { +public: + GeoJSONVTData(const GeoJSON& geoJSON, + const mapbox::geojsonvt::Options& options) + : impl(geoJSON, options) {} + + mapbox::geometry::feature_collection<int16_t> getTile(const CanonicalTileID& tileID) final { + return impl.getTile(tileID.z, tileID.x, tileID.y).features; + } + +private: + mapbox::geojsonvt::GeoJSONVT impl; +}; + +class SuperclusterData : public GeoJSONData { +public: + SuperclusterData(const mapbox::geometry::feature_collection<double>& features, + const mapbox::supercluster::Options& options) + : impl(features, options) {} + + mapbox::geometry::feature_collection<int16_t> getTile(const CanonicalTileID& tileID) final { + return impl.getTile(tileID.z, tileID.x, tileID.y); + } + +private: + mapbox::supercluster::Supercluster impl; +}; + GeoJSONSource::Impl::Impl(std::string id_, Source& base_, const GeoJSONOptions options_) : Source::Impl(SourceType::GeoJSON, std::move(id_), base_), options(options_) { } @@ -52,18 +82,14 @@ optional<std::string> GeoJSONSource::Impl::getURL() const { return url; } - void GeoJSONSource::Impl::setGeoJSON(const GeoJSON& geoJSON) { req.reset(); _setGeoJSON(geoJSON); } -// Private implementation void GeoJSONSource::Impl::_setGeoJSON(const GeoJSON& geoJSON) { double scale = util::EXTENT / util::tileSize; - cache.clear(); - if (options.cluster && geoJSON.is<mapbox::geometry::feature_collection<double>>() && !geoJSON.get<mapbox::geometry::feature_collection<double>>().empty()) { @@ -71,35 +97,15 @@ void GeoJSONSource::Impl::_setGeoJSON(const GeoJSON& geoJSON) { clusterOptions.maxZoom = options.clusterMaxZoom; clusterOptions.extent = util::EXTENT; clusterOptions.radius = std::round(scale * options.clusterRadius); - - const auto& features = geoJSON.get<mapbox::geometry::feature_collection<double>>(); - geoJSONOrSupercluster = - std::make_unique<mapbox::supercluster::Supercluster>(features, clusterOptions); + data = std::make_unique<SuperclusterData>( + geoJSON.get<mapbox::geometry::feature_collection<double>>(), clusterOptions); } else { mapbox::geojsonvt::Options vtOptions; vtOptions.maxZoom = options.maxzoom; vtOptions.extent = util::EXTENT; vtOptions.buffer = std::round(scale * options.buffer); vtOptions.tolerance = scale * options.tolerance; - geoJSONOrSupercluster = std::make_unique<mapbox::geojsonvt::GeoJSONVT>(geoJSON, vtOptions); - } - - for (auto const &item : tiles) { - GeoJSONTile* geoJSONTile = static_cast<GeoJSONTile*>(item.second.get()); - setTileData(*geoJSONTile, geoJSONTile->id); - } -} - -void GeoJSONSource::Impl::setTileData(GeoJSONTile& tile, const OverscaledTileID& tileID) { - if (geoJSONOrSupercluster.is<GeoJSONVTPointer>()) { - tile.updateData(geoJSONOrSupercluster.get<GeoJSONVTPointer>()->getTile(tileID.canonical.z, - tileID.canonical.x, - tileID.canonical.y).features); - } else { - assert(geoJSONOrSupercluster.is<SuperclusterPointer>()); - tile.updateData(geoJSONOrSupercluster.get<SuperclusterPointer>()->getTile(tileID.canonical.z, - tileID.canonical.x, - tileID.canonical.y)); + data = std::make_unique<GeoJSONVTData>(geoJSON, vtOptions); } } @@ -135,8 +141,6 @@ void GeoJSONSource::Impl::loadDescription(FileSource& fileSource) { return; } - invalidateTiles(); - conversion::Error error; optional<GeoJSON> geoJSON = conversion::convertGeoJSON<JSValue>(d, error); if (!geoJSON) { @@ -155,19 +159,16 @@ void GeoJSONSource::Impl::loadDescription(FileSource& fileSource) { }); } -optional<Range<uint8_t>> GeoJSONSource::Impl::getZoomRange() const { - if (loaded) { - return { { 0, options.maxzoom }}; - } - return {}; +std::unique_ptr<RenderSource> GeoJSONSource::Impl::createRenderSource() const { + return std::make_unique<RenderGeoJSONSource>(*this); +} + +Range<uint8_t> GeoJSONSource::Impl::getZoomRange() const { + return { 0, options.maxzoom }; } -std::unique_ptr<Tile> GeoJSONSource::Impl::createTile(const OverscaledTileID& tileID, - const UpdateParameters& parameters) { - assert(loaded); - auto tilePointer = std::make_unique<GeoJSONTile>(tileID, base.getID(), parameters); - setTileData(*tilePointer.get(), tileID); - return std::move(tilePointer); +GeoJSONData* GeoJSONSource::Impl::getData() const { + return data.get(); } } // namespace style |