Add support for parsing MLT-format vector tile sources (#3246)
Co-authored-by: Bart Louwers <bart@emeel.net> Co-authored-by: Bart Louwers <bart.louwers@gmail.com>
This commit is contained in:
@@ -8,8 +8,8 @@ namespace style {
|
||||
namespace conversion {
|
||||
|
||||
template <>
|
||||
struct Converter<RasterDEMOptions> {
|
||||
std::optional<RasterDEMOptions> operator()(const Convertible& value, Error& error) const;
|
||||
struct Converter<SourceOptions> {
|
||||
std::optional<SourceOptions> operator()(const Convertible& value, Error& error) const;
|
||||
};
|
||||
|
||||
} // namespace conversion
|
||||
@@ -7,8 +7,9 @@
|
||||
namespace mbgl {
|
||||
namespace style {
|
||||
|
||||
struct RasterDEMOptions {
|
||||
std::optional<Tileset::DEMEncoding> encoding = std::nullopt;
|
||||
struct SourceOptions {
|
||||
std::optional<Tileset::RasterEncoding> rasterEncoding = std::nullopt;
|
||||
std::optional<Tileset::VectorEncoding> vectorEncoding = std::nullopt;
|
||||
};
|
||||
|
||||
// NOTE: Any derived class must invalidate `weakFactory` in the destructor
|
||||
@@ -17,7 +18,7 @@ public:
|
||||
RasterDEMSource(std::string id,
|
||||
variant<std::string, Tileset> urlOrTileset,
|
||||
uint16_t tileSize,
|
||||
std::optional<RasterDEMOptions> options = std::nullopt);
|
||||
std::optional<SourceOptions> options = std::nullopt);
|
||||
~RasterDEMSource() override;
|
||||
bool supportsLayerType(const mbgl::style::LayerTypeInfo*) const override;
|
||||
|
||||
@@ -25,7 +26,7 @@ protected:
|
||||
void setTilesetOverrides(Tileset& tileset) override;
|
||||
|
||||
private:
|
||||
std::optional<RasterDEMOptions> options;
|
||||
std::optional<SourceOptions> options;
|
||||
};
|
||||
|
||||
template <>
|
||||
|
||||
@@ -16,7 +16,8 @@ public:
|
||||
VectorSource(std::string id,
|
||||
variant<std::string, Tileset> urlOrTileset,
|
||||
std::optional<float> maxZoom = std::nullopt,
|
||||
std::optional<float> minZoom = std::nullopt);
|
||||
std::optional<float> minZoom = std::nullopt,
|
||||
Tileset::VectorEncoding encoding = Tileset::VectorEncoding::Mapbox);
|
||||
|
||||
void setTilesetOverrides(Tileset& tileset) override;
|
||||
|
||||
@@ -30,11 +31,14 @@ public:
|
||||
|
||||
bool supportsLayerType(const mbgl::style::LayerTypeInfo*) const override;
|
||||
|
||||
Tileset::VectorEncoding getEncoding() const noexcept { return encoding; }
|
||||
|
||||
mapbox::base::WeakPtr<Source> makeWeakPtr() override { return weakFactory.makeWeakPtr(); }
|
||||
|
||||
private:
|
||||
std::optional<float> maxZoom;
|
||||
std::optional<float> minZoom;
|
||||
Tileset::VectorEncoding encoding;
|
||||
mapbox::base::WeakPtrFactory<Source> weakFactory{this}; // Must remain last
|
||||
};
|
||||
|
||||
|
||||
@@ -18,38 +18,40 @@ public:
|
||||
XYZ,
|
||||
TMS
|
||||
};
|
||||
enum class DEMEncoding : bool {
|
||||
Mapbox,
|
||||
Terrarium
|
||||
enum class RasterEncoding : std::uint8_t {
|
||||
Mapbox, // Mapbox DEM
|
||||
Terrarium, // Terrarium DEM
|
||||
};
|
||||
enum class VectorEncoding : std::uint8_t {
|
||||
Mapbox, // Mapbox Vector Tiles (MVT)
|
||||
MLT, // MapLibre Tiles
|
||||
};
|
||||
|
||||
std::vector<std::string> tiles;
|
||||
Range<uint8_t> zoomRange;
|
||||
std::string attribution;
|
||||
Scheme scheme;
|
||||
// DEMEncoding is not supported by the TileJSON spec
|
||||
DEMEncoding encoding;
|
||||
std::optional<RasterEncoding> rasterEncoding;
|
||||
std::optional<VectorEncoding> vectorEncoding;
|
||||
std::optional<LatLngBounds> bounds;
|
||||
|
||||
Tileset(std::vector<std::string> tiles_ = std::vector<std::string>(),
|
||||
Range<uint8_t> zoomRange_ = {0, util::DEFAULT_MAX_ZOOM},
|
||||
std::string attribution_ = {},
|
||||
Scheme scheme_ = Scheme::XYZ,
|
||||
DEMEncoding encoding_ = DEMEncoding::Mapbox)
|
||||
std::optional<RasterEncoding> rasterEncoding_ = std::nullopt,
|
||||
std::optional<VectorEncoding> encoding_ = std::nullopt)
|
||||
: tiles(std::move(tiles_)),
|
||||
zoomRange(zoomRange_),
|
||||
attribution(std::move(attribution_)),
|
||||
scheme(scheme_),
|
||||
encoding(encoding_) {};
|
||||
rasterEncoding(rasterEncoding_),
|
||||
vectorEncoding(encoding_) {}
|
||||
|
||||
// TileJSON also includes center and zoom but they are not used by mbgl.
|
||||
|
||||
friend bool operator==(const Tileset& lhs, const Tileset& rhs) noexcept {
|
||||
return std::tie(lhs.tiles, lhs.zoomRange, lhs.attribution, lhs.scheme, lhs.bounds) ==
|
||||
std::tie(rhs.tiles, rhs.zoomRange, rhs.attribution, rhs.scheme, rhs.bounds);
|
||||
}
|
||||
|
||||
friend bool operator!=(const Tileset& lhs, const Tileset& rhs) noexcept { return !(lhs == rhs); }
|
||||
bool operator==(const Tileset&) const = default;
|
||||
bool operator!=(const Tileset&) const = default;
|
||||
};
|
||||
|
||||
} // namespace mbgl
|
||||
|
||||
Reference in New Issue
Block a user