#include #include #include #include #include #include #include namespace mbgl { namespace style { class GeoJSONVTData : public GeoJSONData { public: GeoJSONVTData(const GeoJSON& geoJSON, const mapbox::geojsonvt::Options& options) : impl(geoJSON, options) {} mapbox::geometry::feature_collection 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& features, const mapbox::supercluster::Options& options) : impl(features, options) {} mapbox::geometry::feature_collection 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_, GeoJSONOptions options_) : Source::Impl(SourceType::GeoJSON, std::move(id_)), options(std::move(options_)) { } GeoJSONSource::Impl::Impl(const Impl& other, const GeoJSON& geoJSON) : Source::Impl(other), options(other.options) { double scale = util::EXTENT / util::tileSize; if (options.cluster && geoJSON.is>() && !geoJSON.get>().empty()) { mapbox::supercluster::Options clusterOptions; clusterOptions.maxZoom = options.clusterMaxZoom; clusterOptions.extent = util::EXTENT; clusterOptions.radius = ::round(scale * options.clusterRadius); data = std::make_unique( geoJSON.get>(), clusterOptions); } else { mapbox::geojsonvt::Options vtOptions; vtOptions.maxZoom = options.maxzoom; vtOptions.extent = util::EXTENT; vtOptions.buffer = ::round(scale * options.buffer); vtOptions.tolerance = scale * options.tolerance; data = std::make_unique(geoJSON, vtOptions); } } GeoJSONSource::Impl::~Impl() = default; Range GeoJSONSource::Impl::getZoomRange() const { return { 0, options.maxzoom }; } GeoJSONData* GeoJSONSource::Impl::getData() const { return data.get(); } optional GeoJSONSource::Impl::getAttribution() const { return {}; } } // namespace style } // namespace mbgl