#pragma once #include #include #include #include #include #include #include #include #include namespace mbgl { class AsyncRequest; class Scheduler; namespace style { struct GeoJSONOptions { // GeoJSON-VT options uint8_t minzoom = 0; uint8_t maxzoom = 18; uint16_t tileSize = util::tileSize; uint16_t buffer = 128; double tolerance = 0.375; bool lineMetrics = false; // Supercluster options bool cluster = false; uint16_t clusterRadius = 50; uint8_t clusterMaxZoom = 17; using ClusterExpression = std::pair, std::shared_ptr>; using ClusterProperties = std::map; ClusterProperties clusterProperties; static Immutable defaultOptions(); }; class GeoJSONData { public: using TileFeatures = mapbox::feature::feature_collection; using Features = mapbox::feature::feature_collection; static std::shared_ptr create(const GeoJSON&, const Immutable& = GeoJSONOptions::defaultOptions(), std::shared_ptr scheduler = nullptr); virtual ~GeoJSONData() = default; virtual void getTile(const CanonicalTileID&, const std::function&) = 0; // SuperclusterData virtual Features getChildren(std::uint32_t) = 0; virtual Features getLeaves(std::uint32_t, std::uint32_t limit = 10u, std::uint32_t offset = 0u) = 0; virtual std::uint8_t getClusterExpansionZoom(std::uint32_t) = 0; virtual std::shared_ptr getScheduler() { return nullptr; } }; class GeoJSONSource final : public Source { public: GeoJSONSource(std::string id, Immutable = GeoJSONOptions::defaultOptions()); ~GeoJSONSource() final; void setURL(const std::string& url); void setGeoJSON(const GeoJSON&); void setGeoJSONData(std::shared_ptr); optional getURL() const; const GeoJSONOptions& getOptions() const; class Impl; const Impl& impl() const; void loadDescription(FileSource&) final; bool supportsLayerType(const mbgl::style::LayerTypeInfo*) const override; mapbox::base::WeakPtr makeWeakPtr() override { return weakFactory.makeWeakPtr(); } protected: Mutable createMutable() const noexcept final; private: optional url; std::unique_ptr req; std::shared_ptr threadPool; mapbox::base::WeakPtrFactory weakFactory {this}; }; template <> inline bool Source::is() const { return getType() == SourceType::GeoJSON; } } // namespace style } // namespace mbgl