#pragma once #include #include #include #include #include #include #include #include #include #include #include #include #include #include namespace mbgl { class FileSource; class Tileset; namespace style { class VectorSource; class RasterSource; class RasterDEMSource; class GeoJSONSource; class SourceObserver; struct LayerTypeInfo; /** * @brief Holds static data for a certain source type. */ struct SourceTypeInfo { /** * @brief contains the source type as defined in the style specification; */ const char* type; /** * @brief specifies whether the source supports tile prefetching; */ const enum class TilePrefetch : bool { No, Yes } tilePrefetch; /** * @brief specifies whether the source operates with the loaded tile set; */ const enum class TileSet : bool { No, Yes } tileSet; /** * @brief specifies source's tile kind; */ const optional tileKind; }; /** * The runtime representation of a [source](https://www.mapbox.com/mapbox-gl-style-spec/#sources) from the Mapbox Style * Specification. * * `Source` is an abstract base class; concrete derived classes are provided for each source type. `Source` contains * functionality that is common to all layer types: * * * Runtime type information: type predicates and casting * * Accessors for properties common to all source types: ID, etc. * * Cloning and copying * * All other functionality lives in the derived classes. To instantiate a source, create an instance of the desired * type, passing the ID: * * auto vectorSource = std::make_unique("my-vector-source"); */ class Source : public Serializable { public: Source(const Source&) = delete; Source& operator=(const Source&) = delete; virtual ~Source(); std::string getID() const; optional getAttribution() const; // The data from the volatile sources are not stored in a persistent storage. bool isVolatile() const noexcept; void setVolatile(bool) noexcept; // Private implementation class Impl; Immutable baseImpl; void setObserver(SourceObserver*); SourceObserver* observer = nullptr; virtual void loadDescription(FileSource&) = 0; virtual void setSourceData(SourceData) {} /** * @brief Returns resource for loading, if required by this source; returns `nullopt` otherwise. * * If already loaded, this will return nullopt as well for Tiled sources (SourceTypeInfo::TileSet == Yes) * * @return optional */ virtual optional getResource() const { return nullopt; } /** * @brief for tiled sources (SourceTypeInfo::TileSet == Yes) this will return the TileSet when * loaded, nullptr in any other case. * * @return Tileset* or nullptr */ virtual const Tileset* getTileset() const { return nullptr; } /** * @brief Returns the GeoJSON data, if this source supports GeoJSON format; returns `nullptr` otherwise. * * @return const GeoJSONData* */ virtual const GeoJSONData* getGeoJSONData() const { return nullptr; } virtual void setSourceParameters(SourceParameters) {} virtual void invalidateTile(const CanonicalTileID&) {} virtual void invalidateRegion(const LatLngBounds&) {} void setPrefetchZoomDelta(optional delta) noexcept; optional getPrefetchZoomDelta() const noexcept; int32_t getCoveringZoomLevel(double z) const noexcept; uint16_t getTileSize() const; // If the given source supports loading tiles from a server, // sets the minimum tile update interval. // Update network requests that are more frequent than the // minimum tile update interval are suppressed. // // Default value is `Duration::zero()`. void setMinimumTileUpdateInterval(Duration) noexcept; Duration getMinimumTileUpdateInterval() const noexcept; // Sets a limit for how much a parent tile can be overscaled. // // When a set of tiles for a current zoom level is being rendered and some of the // ideal tiles that cover the screen are not yet loaded, parent tile could be // used instead. This might introduce unwanted rendering side-effects, especially // for raster tiles that are overscaled multiple times. // // For example, an overscale factor of 3 would mean that on zoom level 3, the // minimum zoom level of a parent tile that could be used in place of an ideal // tile during rendering would be zoom 0. By default, no limit is set, so any // parent tile may be used. void setMaxOverscaleFactorForParentTiles(optional overscaleFactor) noexcept; optional getMaxOverscaleFactorForParentTiles() const noexcept; void dumpDebugLogs() const; virtual bool supportsLayerType(const mbgl::style::LayerTypeInfo*) const = 0; bool loaded = false; // For use in SDK bindings, which store a reference to a platform-native peer // object here, so that separately-obtained references to this object share // identical platform-native peers. mapbox::base::TypeWrapper peer; optional setProperty(const std::string& name, const conversion::Convertible& value); Value getProperty(const std::string&) const; Value getPropertyDefaultValue(const std::string&) const; virtual mapbox::base::WeakPtr makeWeakPtr() = 0; const SourceTypeInfo* getTypeInfo() const noexcept; Value serialize() const override; protected: explicit Source(Immutable); virtual Mutable createMutable() const noexcept = 0; virtual optional setPropertyInternal(const std::string& name, const conversion::Convertible& value); virtual Value getPropertyInternal(const std::string&) const; virtual Value getPropertyDefaultValueInternal(const std::string&) const; }; } // namespace style } // namespace mbgl