diff options
Diffstat (limited to 'include/mbgl')
-rw-r--r-- | include/mbgl/style/layer.hpp | 2 | ||||
-rw-r--r-- | include/mbgl/style/source.hpp | 74 | ||||
-rw-r--r-- | include/mbgl/style/source_data.hpp | 39 | ||||
-rw-r--r-- | include/mbgl/style/source_parameters.hpp | 15 | ||||
-rw-r--r-- | include/mbgl/style/sources/custom_geometry_source.hpp | 10 | ||||
-rw-r--r-- | include/mbgl/style/sources/geojson_source.hpp | 25 | ||||
-rw-r--r-- | include/mbgl/style/sources/image_source.hpp | 17 | ||||
-rw-r--r-- | include/mbgl/style/sources/raster_dem_source.hpp | 14 | ||||
-rw-r--r-- | include/mbgl/style/sources/raster_source.hpp | 18 | ||||
-rw-r--r-- | include/mbgl/style/sources/vector_source.hpp | 9 | ||||
-rw-r--r-- | include/mbgl/style/types.hpp | 12 | ||||
-rw-r--r-- | include/mbgl/tile/tile_kind.hpp | 7 |
12 files changed, 156 insertions, 86 deletions
diff --git a/include/mbgl/style/layer.hpp b/include/mbgl/style/layer.hpp index 9884ad0a35..13a2ec014f 100644 --- a/include/mbgl/style/layer.hpp +++ b/include/mbgl/style/layer.hpp @@ -61,7 +61,7 @@ struct LayerTypeInfo { /** * @brief contains the Id of the supported tile type. Used for internal checks. - * The contained values correspond to \c Tile::Kind enum. + * The contained values correspond to \c TileKind enum. */ const enum class TileKind : uint8_t { Geometry, Raster, RasterDEM, NotRequired } tileKind; }; diff --git a/include/mbgl/style/source.hpp b/include/mbgl/style/source.hpp index eada63d12d..3727d944f8 100644 --- a/include/mbgl/style/source.hpp +++ b/include/mbgl/style/source.hpp @@ -1,19 +1,23 @@ #pragma once +#include <mapbox/std/weak.hpp> +#include <mapbox/util/type_wrapper.hpp> +#include <mbgl/style/source_data.hpp> +#include <mbgl/style/source_parameters.hpp> #include <mbgl/style/types.hpp> +#include <mbgl/tile/tile_kind.hpp> #include <mbgl/util/chrono.hpp> +#include <mbgl/util/feature.hpp> #include <mbgl/util/immutable.hpp> #include <mbgl/util/optional.hpp> - -#include <mapbox/std/weak.hpp> -#include <mapbox/util/type_wrapper.hpp> - +#include <mbgl/util/variant.hpp> #include <memory> #include <string> namespace mbgl { class FileSource; +class Tileset; namespace style { @@ -25,6 +29,27 @@ 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 bool supportsTilePrefetch; + + /** + * @brief specifies source's tile kind; + * + */ + const optional<TileKind> tileKind; +}; + +/** * The runtime representation of a [source](https://www.mapbox.com/mapbox-gl-style-spec/#sources) from the Mapbox Style * Specification. * @@ -47,22 +72,6 @@ public: virtual ~Source(); - // Check whether this source is of the given subtype. - template <class T> - bool is() const; - - // Dynamically cast this source to the given subtype. - template <class T> - T* as() { - return is<T>() ? reinterpret_cast<T*>(this) : nullptr; - } - - template <class T> - const T* as() const { - return is<T>() ? reinterpret_cast<const T*>(this) : nullptr; - } - - SourceType getType() const; std::string getID() const; optional<std::string> getAttribution() const; @@ -78,9 +87,25 @@ public: SourceObserver* observer = nullptr; virtual void loadDescription(FileSource&) = 0; + + virtual void setSourceData(SourceData){}; + + virtual SourceDataResult getSourceData() const { return {}; } + + virtual const variant<std::string, Tileset>* getURLOrTileset() const { return nullptr; } + + virtual void setSourceParameters(SourceParameters){}; + + virtual void invalidateTile(const CanonicalTileID&) {} + virtual void invalidateRegion(const LatLngBounds&) {} + void setPrefetchZoomDelta(optional<uint8_t> delta) noexcept; optional<uint8_t> 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 @@ -103,6 +128,7 @@ public: // parent tile may be used. void setMaxOverscaleFactorForParentTiles(optional<uint8_t> overscaleFactor) noexcept; optional<uint8_t> getMaxOverscaleFactorForParentTiles() const noexcept; + void dumpDebugLogs() const; virtual bool supportsLayerType(const mbgl::style::LayerTypeInfo*) const = 0; @@ -116,8 +142,16 @@ public: virtual mapbox::base::WeakPtr<Source> makeWeakPtr() = 0; + const SourceTypeInfo* getTypeInfo() const noexcept; + + virtual Value serialize() const; + protected: explicit Source(Immutable<Impl>); + + void serializeUrlOrTileSet(Value&, const variant<std::string, Tileset>*) const; + void serializeTileSet(Value&, const mbgl::Tileset&) const; + virtual Mutable<Impl> createMutable() const noexcept = 0; }; diff --git a/include/mbgl/style/source_data.hpp b/include/mbgl/style/source_data.hpp new file mode 100644 index 0000000000..366adff0df --- /dev/null +++ b/include/mbgl/style/source_data.hpp @@ -0,0 +1,39 @@ +#pragma once + +#include <mbgl/util/geojson.hpp> +#include <mbgl/util/image.hpp> +#include <mbgl/util/optional.hpp> +#include <memory> +#include <string> + +namespace mbgl { +namespace style { + +class GeoJSONData; + +struct SourceData { + SourceData() = default; + explicit SourceData(std::string url_) : url(std::move(url_)) {} + explicit SourceData(PremultipliedImage image_) : image(std::move(image_)) {} + explicit SourceData(GeoJSON geoJSON_) : geoJSON(std::move(geoJSON_)) {} + explicit SourceData(std::shared_ptr<GeoJSONData> data) : geoJSONData(std::move(data)) {} + + optional<std::string> url; + optional<PremultipliedImage> image; + optional<GeoJSON> geoJSON; + std::shared_ptr<GeoJSONData> geoJSONData; +}; + +struct SourceDataResult { + SourceDataResult() = default; + explicit SourceDataResult(const std::string& url_) : url(&url_) {} + explicit SourceDataResult(std::weak_ptr<PremultipliedImage>& image_) : image(std::move(image_)) {} + explicit SourceDataResult(std::weak_ptr<GeoJSONData> data) : geoJSONData(std::move(data)) {} + + const std::string* url = nullptr; + std::weak_ptr<const PremultipliedImage> image; + std::weak_ptr<const GeoJSONData> geoJSONData; +}; + +} // namespace style +} // namespace mbgl diff --git a/include/mbgl/style/source_parameters.hpp b/include/mbgl/style/source_parameters.hpp new file mode 100644 index 0000000000..0d7891f193 --- /dev/null +++ b/include/mbgl/style/source_parameters.hpp @@ -0,0 +1,15 @@ +#pragma once + +#include <mbgl/util/geo.hpp> +#include <mbgl/util/optional.hpp> + +namespace mbgl { +namespace style { + +struct SourceParameters { + explicit SourceParameters(std::array<LatLng, 4> bounds_) : bounds(bounds_) {} + optional<std::array<LatLng, 4>> bounds; +}; + +} // namespace style +} // namespace mbgl diff --git a/include/mbgl/style/sources/custom_geometry_source.hpp b/include/mbgl/style/sources/custom_geometry_source.hpp index 250886c209..6687f0f148 100644 --- a/include/mbgl/style/sources/custom_geometry_source.hpp +++ b/include/mbgl/style/sources/custom_geometry_source.hpp @@ -9,7 +9,6 @@ namespace mbgl { class OverscaledTileID; -class CanonicalTileID; template <class T> class Actor; class ThreadPool; @@ -41,8 +40,8 @@ public: ~CustomGeometrySource() final; void loadDescription(FileSource&) final; void setTileData(const CanonicalTileID&, const GeoJSON&); - void invalidateTile(const CanonicalTileID&); - void invalidateRegion(const LatLngBounds&); + void invalidateTile(const CanonicalTileID&) override; + void invalidateRegion(const LatLngBounds&) override; // Private implementation class Impl; const Impl& impl() const; @@ -60,10 +59,5 @@ private: mapbox::base::WeakPtrFactory<Source> weakFactory {this}; }; -template <> -inline bool Source::is<CustomGeometrySource>() const { - return getType() == SourceType::CustomVector; -} - } // namespace style } // namespace mbgl diff --git a/include/mbgl/style/sources/geojson_source.hpp b/include/mbgl/style/sources/geojson_source.hpp index b728b340ea..7d8cc8a013 100644 --- a/include/mbgl/style/sources/geojson_source.hpp +++ b/include/mbgl/style/sources/geojson_source.hpp @@ -1,13 +1,12 @@ #pragma once +#include <map> #include <mbgl/style/expression/expression.hpp> #include <mbgl/style/source.hpp> #include <mbgl/tile/tile_id.hpp> #include <mbgl/util/constants.hpp> #include <mbgl/util/geojson.hpp> #include <mbgl/util/optional.hpp> - -#include <map> #include <memory> #include <utility> @@ -37,6 +36,7 @@ struct GeoJSONOptions { static Immutable<GeoJSONOptions> defaultOptions(); }; + class GeoJSONData { public: using TileFeatures = mapbox::feature::feature_collection<int16_t>; @@ -49,9 +49,9 @@ public: virtual void getTile(const CanonicalTileID&, const std::function<void(TileFeatures)>&) = 0; // SuperclusterData - virtual Features getChildren(std::uint32_t) = 0; - virtual Features getLeaves(std::uint32_t, std::uint32_t limit, std::uint32_t offset) = 0; - virtual std::uint8_t getClusterExpansionZoom(std::uint32_t) = 0; + virtual Features getChildren(std::uint32_t) const = 0; + virtual Features getLeaves(std::uint32_t, std::uint32_t limit, std::uint32_t offset) const = 0; + virtual std::uint8_t getClusterExpansionZoom(std::uint32_t) const = 0; virtual std::shared_ptr<Scheduler> getScheduler() { return nullptr; } }; @@ -64,7 +64,9 @@ public: void setURL(const std::string& url); void setGeoJSON(const GeoJSON&); void setGeoJSONData(std::shared_ptr<GeoJSONData>); + void setSourceData(SourceData data) override; + SourceDataResult getSourceData() const override; optional<std::string> getURL() const; const GeoJSONOptions& getOptions() const; @@ -75,9 +77,9 @@ public: bool supportsLayerType(const mbgl::style::LayerTypeInfo*) const override; - mapbox::base::WeakPtr<Source> makeWeakPtr() override { - return weakFactory.makeWeakPtr(); - } + mapbox::base::WeakPtr<Source> makeWeakPtr() override { return weakFactory.makeWeakPtr(); } + + Value serialize() const override; protected: Mutable<Source::Impl> createMutable() const noexcept final; @@ -86,13 +88,8 @@ private: optional<std::string> url; std::unique_ptr<AsyncRequest> req; std::shared_ptr<Scheduler> threadPool; - mapbox::base::WeakPtrFactory<Source> weakFactory {this}; + mapbox::base::WeakPtrFactory<Source> weakFactory{this}; }; -template <> -inline bool Source::is<GeoJSONSource>() const { - return getType() == SourceType::GeoJSON; -} - } // namespace style } // namespace mbgl diff --git a/include/mbgl/style/sources/image_source.hpp b/include/mbgl/style/sources/image_source.hpp index 32971ef3d6..5d2e72027f 100644 --- a/include/mbgl/style/sources/image_source.hpp +++ b/include/mbgl/style/sources/image_source.hpp @@ -16,9 +16,11 @@ public: ~ImageSource() override; optional<std::string> getURL() const; - void setURL(const std::string& url); + void setURL(const std::string& url); void setImage(PremultipliedImage&&); + void setSourceData(SourceData) override; + SourceDataResult getSourceData() const override; void setCoordinates(const std::array<LatLng, 4>&); std::array<LatLng, 4> getCoordinates() const; @@ -30,9 +32,9 @@ public: bool supportsLayerType(const mbgl::style::LayerTypeInfo*) const override; - mapbox::base::WeakPtr<Source> makeWeakPtr() override { - return weakFactory.makeWeakPtr(); - } + mapbox::base::WeakPtr<Source> makeWeakPtr() override { return weakFactory.makeWeakPtr(); } + + Value serialize() const override; protected: Mutable<Source::Impl> createMutable() const noexcept final; @@ -40,13 +42,8 @@ protected: private: optional<std::string> url; std::unique_ptr<AsyncRequest> req; - mapbox::base::WeakPtrFactory<Source> weakFactory {this}; + mapbox::base::WeakPtrFactory<Source> weakFactory{this}; }; -template <> -inline bool Source::is<ImageSource>() const { - return getType() == SourceType::Image; -} - } // namespace style } // namespace mbgl diff --git a/include/mbgl/style/sources/raster_dem_source.hpp b/include/mbgl/style/sources/raster_dem_source.hpp index 42e27cd078..14eed64545 100644 --- a/include/mbgl/style/sources/raster_dem_source.hpp +++ b/include/mbgl/style/sources/raster_dem_source.hpp @@ -14,12 +14,16 @@ class RasterDEMSource : public RasterSource { public: RasterDEMSource(std::string id, variant<std::string, Tileset> urlOrTileset, uint16_t tileSize); bool supportsLayerType(const mbgl::style::LayerTypeInfo*) const override; -}; -template <> -inline bool Source::is<RasterDEMSource>() const { - return getType() == SourceType::RasterDEM; -} + class Impl; + const Impl& impl() const; + + Value serialize() const override; + +protected: + Mutable<Source::Impl> createMutable() const noexcept final; + Mutable<Source::Impl> createMutable(Tileset tileset) const noexcept final; +}; } // namespace style } // namespace mbgl diff --git a/include/mbgl/style/sources/raster_source.hpp b/include/mbgl/style/sources/raster_source.hpp index e06c3404e9..d84a9576c1 100644 --- a/include/mbgl/style/sources/raster_source.hpp +++ b/include/mbgl/style/sources/raster_source.hpp @@ -12,14 +12,12 @@ namespace style { class RasterSource : public Source { public: - RasterSource(std::string id, variant<std::string, Tileset> urlOrTileset, uint16_t tileSize, SourceType sourceType = SourceType::Raster); + RasterSource(std::string id, variant<std::string, Tileset> urlOrTileset, uint16_t tileSize); ~RasterSource() override; - const variant<std::string, Tileset>& getURLOrTileset() const; + const variant<std::string, Tileset>* getURLOrTileset() const final; optional<std::string> getURL() const; - uint16_t getTileSize() const; - class Impl; const Impl& impl() const; @@ -31,8 +29,13 @@ public: return weakFactory.makeWeakPtr(); } + Value serialize() const override; + protected: - Mutable<Source::Impl> createMutable() const noexcept final; + RasterSource(Immutable<Impl>&&, variant<std::string, Tileset> urlOrTileset_); + + Mutable<Source::Impl> createMutable() const noexcept override; + virtual Mutable<Source::Impl> createMutable(Tileset tileset) const noexcept; private: const variant<std::string, Tileset> urlOrTileset; @@ -40,10 +43,5 @@ private: mapbox::base::WeakPtrFactory<Source> weakFactory {this}; }; -template <> -inline bool Source::is<RasterSource>() const { - return getType() == SourceType::Raster; -} - } // namespace style } // namespace mbgl diff --git a/include/mbgl/style/sources/vector_source.hpp b/include/mbgl/style/sources/vector_source.hpp index 83fcae95d6..27fd78cce5 100644 --- a/include/mbgl/style/sources/vector_source.hpp +++ b/include/mbgl/style/sources/vector_source.hpp @@ -16,7 +16,7 @@ public: optional<float> minZoom = nullopt); ~VectorSource() final; - const variant<std::string, Tileset>& getURLOrTileset() const; + const variant<std::string, Tileset>* getURLOrTileset() const final; optional<std::string> getURL() const; class Impl; @@ -30,6 +30,8 @@ public: return weakFactory.makeWeakPtr(); } + Value serialize() const override; + protected: Mutable<Source::Impl> createMutable() const noexcept final; @@ -41,10 +43,5 @@ private: optional<float> minZoom; }; -template <> -inline bool Source::is<VectorSource>() const { - return getType() == SourceType::Vector; -} - } // namespace style } // namespace mbgl diff --git a/include/mbgl/style/types.hpp b/include/mbgl/style/types.hpp index 5d88dafb33..7c3657e7ee 100644 --- a/include/mbgl/style/types.hpp +++ b/include/mbgl/style/types.hpp @@ -6,18 +6,6 @@ namespace mbgl { namespace style { -// TODO: should be in public source.hpp header -enum class SourceType : uint8_t { - Vector, - Raster, - RasterDEM, - GeoJSON, - Video, - Annotations, - Image, - CustomVector -}; - enum class VisibilityType : bool { Visible, None, diff --git a/include/mbgl/tile/tile_kind.hpp b/include/mbgl/tile/tile_kind.hpp new file mode 100644 index 0000000000..16e50b802c --- /dev/null +++ b/include/mbgl/tile/tile_kind.hpp @@ -0,0 +1,7 @@ +#pragma once + +namespace mbgl { + +enum class TileKind : uint8_t { Geometry, Raster, RasterDEM }; + +} // namespace mbgl
\ No newline at end of file |