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:
@@ -3,7 +3,7 @@
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
DEMData::DEMData(const PremultipliedImage& _image, Tileset::DEMEncoding _encoding)
|
||||
DEMData::DEMData(const PremultipliedImage& _image, Tileset::RasterEncoding _encoding)
|
||||
: dim(_image.size.height),
|
||||
// extra two pixels per row for border backfilling on either edge
|
||||
stride(dim + 2),
|
||||
@@ -99,7 +99,7 @@ const std::array<float, 4>& DEMData::getUnpackVector() const {
|
||||
// https://aws.amazon.com/public-datasets/terrain/
|
||||
static const std::array<float, 4> unpackTerrarium = {{256.0f, 1.0f, 1.0f / 256.0f, 32768.0f}};
|
||||
|
||||
return encoding == Tileset::DEMEncoding::Terrarium ? unpackTerrarium : unpackMapbox;
|
||||
return encoding == Tileset::RasterEncoding::Terrarium ? unpackTerrarium : unpackMapbox;
|
||||
}
|
||||
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace mbgl {
|
||||
|
||||
class DEMData {
|
||||
public:
|
||||
DEMData(const PremultipliedImage& image, Tileset::DEMEncoding encoding);
|
||||
DEMData(const PremultipliedImage& image, Tileset::RasterEncoding encoding);
|
||||
void backfillBorder(const DEMData& borderTileData, int8_t dx, int8_t dy);
|
||||
|
||||
int32_t get(int32_t x, int32_t y) const;
|
||||
@@ -24,7 +24,7 @@ public:
|
||||
|
||||
const int32_t dim;
|
||||
const int32_t stride;
|
||||
const Tileset::DEMEncoding encoding;
|
||||
const Tileset::RasterEncoding encoding;
|
||||
|
||||
private:
|
||||
std::shared_ptr<PremultipliedImage> image;
|
||||
|
||||
@@ -54,10 +54,10 @@ std::size_t totalVerticesCheck(const GeometryCollection& polygon) {
|
||||
|
||||
void addFillIndices(SegmentVector& fillSegments,
|
||||
gfx::IndexVector<gfx::Triangles>& fillIndexes,
|
||||
std::vector<uint32_t>& indices,
|
||||
std::size_t startVertices,
|
||||
std::size_t totalVertices) {
|
||||
std::size_t nIndices = indices.size();
|
||||
const std::span<const uint32_t>& indices,
|
||||
const std::size_t startVertices,
|
||||
const std::size_t totalVertices) {
|
||||
const std::size_t nIndices = indices.size();
|
||||
assert(nIndices % 3 == 0);
|
||||
|
||||
if (fillSegments.empty() ||
|
||||
@@ -66,10 +66,13 @@ void addFillIndices(SegmentVector& fillSegments,
|
||||
}
|
||||
|
||||
auto& triangleSegment = fillSegments.back();
|
||||
assert(triangleSegment.vertexLength <= std::numeric_limits<uint16_t>::max());
|
||||
assert(triangleSegment.vertexLength + totalVertices <= std::numeric_limits<uint16_t>::max());
|
||||
const auto triangleIndex = static_cast<uint16_t>(triangleSegment.vertexLength);
|
||||
|
||||
for (std::size_t i = 0; i < nIndices; i += 3) {
|
||||
assert(
|
||||
std::max({triangleIndex + indices[i + 0], triangleIndex + indices[i + 1], triangleIndex + indices[i + 2]}) <
|
||||
triangleIndex + totalVertices);
|
||||
fillIndexes.emplace_back(
|
||||
triangleIndex + indices[i], triangleIndex + indices[i + 1], triangleIndex + indices[i + 2]);
|
||||
}
|
||||
@@ -78,8 +81,8 @@ void addFillIndices(SegmentVector& fillSegments,
|
||||
triangleSegment.indexLength += nIndices;
|
||||
}
|
||||
|
||||
void addOutlineIndices(std::size_t base,
|
||||
std::size_t nVertices,
|
||||
void addOutlineIndices(const std::size_t base,
|
||||
const std::size_t nVertices,
|
||||
SegmentVector& lineSegments,
|
||||
gfx::IndexVector<gfx::Lines>& lineIndexes) {
|
||||
if (nVertices == 0) return;
|
||||
@@ -206,21 +209,36 @@ void generateFillAndOutineBuffers(const GeometryCollection& geometry,
|
||||
gfx::PolylineGeneratorOptions lineOptions;
|
||||
lineOptions.type = FeatureType::Polygon;
|
||||
|
||||
// If we have pre-tessellated geometry, multi-polygons are tessellated
|
||||
// together, so we need to add them to the fill segment all at once.
|
||||
if (!geometry.getTriangles().empty()) {
|
||||
const std::size_t startVertices = fillVertices.elements();
|
||||
std::size_t totalVertices = 0;
|
||||
for (const auto& polygon : geometry) {
|
||||
totalVertices += polygon.size();
|
||||
addRingVertices(fillVertices, polygon);
|
||||
}
|
||||
addFillIndices(fillSegments, fillIndexes, geometry.getTriangles(), startVertices, totalVertices);
|
||||
return;
|
||||
}
|
||||
|
||||
for (auto& polygon : classifyRings(geometry)) {
|
||||
// Optimize polygons with many interior rings for earcut tesselation.
|
||||
limitHoles(polygon, 500);
|
||||
|
||||
std::size_t totalVertices = totalVerticesCheck(polygon);
|
||||
std::size_t startVertices = fillVertices.elements();
|
||||
const std::size_t totalVertices = totalVerticesCheck(polygon);
|
||||
const std::size_t startVertices = fillVertices.elements();
|
||||
|
||||
for (const auto& ring : polygon) {
|
||||
std::size_t base = fillVertices.elements();
|
||||
std::size_t nVertices = addRingVertices(fillVertices, ring);
|
||||
const std::size_t base = fillVertices.elements();
|
||||
const std::size_t nVertices = addRingVertices(fillVertices, ring);
|
||||
addOutlineIndices(base, nVertices, basicLineSegments, basicLineIndexes);
|
||||
lineGenerator.generate(ring, lineOptions);
|
||||
}
|
||||
|
||||
// tessellate, if no triangles are provided
|
||||
std::vector<uint32_t> indices = mapbox::earcut(polygon);
|
||||
|
||||
addFillIndices(fillSegments, fillIndexes, indices, startVertices, totalVertices);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,13 +11,13 @@ namespace gfx {
|
||||
|
||||
class HillshadePrepareDrawableData : public DrawableData {
|
||||
public:
|
||||
HillshadePrepareDrawableData(int32_t stride_, Tileset::DEMEncoding encoding_, uint8_t maxzoom_)
|
||||
HillshadePrepareDrawableData(int32_t stride_, Tileset::RasterEncoding encoding_, uint8_t maxzoom_)
|
||||
: stride(stride_),
|
||||
encoding(encoding_),
|
||||
maxzoom(maxzoom_) {}
|
||||
|
||||
int32_t stride;
|
||||
Tileset::DEMEncoding encoding;
|
||||
Tileset::RasterEncoding encoding;
|
||||
uint8_t maxzoom;
|
||||
};
|
||||
|
||||
|
||||
78
src/mbgl/programs/programs.cpp
Normal file
78
src/mbgl/programs/programs.cpp
Normal file
@@ -0,0 +1,78 @@
|
||||
#include <mbgl/programs/programs.hpp>
|
||||
#include <mbgl/programs/background_program.hpp>
|
||||
#include <mbgl/programs/circle_program.hpp>
|
||||
#include <mbgl/programs/heatmap_program.hpp>
|
||||
#include <mbgl/programs/hillshade_program.hpp>
|
||||
#include <mbgl/programs/fill_extrusion_program.hpp>
|
||||
#include <mbgl/programs/fill_program.hpp>
|
||||
#include <mbgl/programs/line_program.hpp>
|
||||
#include <mbgl/programs/raster_program.hpp>
|
||||
#include <mbgl/programs/symbol_program.hpp>
|
||||
#include <mbgl/util/logging.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
Programs::Programs(const ProgramParameters& programParameters_)
|
||||
: programParameters(programParameters_) {}
|
||||
|
||||
Programs::~Programs() = default;
|
||||
|
||||
namespace {
|
||||
/// @brief Register a list of types with a shader registry instance
|
||||
/// @tparam ...T Type list parameter pack
|
||||
/// @param registry A shader registry instance
|
||||
/// programParameters_ ProgramParameters used to initialize each instance
|
||||
template <typename... T>
|
||||
void registerTypes(gfx::ShaderRegistry& registry, const ProgramParameters& programParameters_) {
|
||||
/// The following fold expression will create a shared_ptr for every type
|
||||
/// in the parameter pack and register it with the shader registry.
|
||||
|
||||
/// Registration calls are wrapped in a lambda that throws on registration
|
||||
/// failure, we shouldn't expect registration to faill unless the shader
|
||||
/// registry instance provided already has conflicting programs present.
|
||||
(
|
||||
[](bool expr) {
|
||||
if (!expr) {
|
||||
throw std::runtime_error("Failed to register " + std::string(T::Name) + " with shader registry!");
|
||||
}
|
||||
}(registry.getLegacyGroup().registerShader(std::make_shared<T>(programParameters_))),
|
||||
...);
|
||||
}
|
||||
} // namespace
|
||||
|
||||
void Programs::registerWith(gfx::ShaderRegistry& registry) {
|
||||
#if MLN_LEGACY_RENDERER
|
||||
/// The following types will be registered
|
||||
registerTypes<BackgroundProgram,
|
||||
BackgroundPatternProgram,
|
||||
RasterProgram,
|
||||
HeatmapProgram,
|
||||
HeatmapTextureProgram,
|
||||
HillshadeProgram,
|
||||
HillshadePrepareProgram,
|
||||
FillProgram,
|
||||
FillPatternProgram,
|
||||
FillOutlineProgram,
|
||||
FillOutlinePatternProgram,
|
||||
FillExtrusionProgram,
|
||||
FillExtrusionPatternProgram,
|
||||
CircleProgram,
|
||||
LineProgram,
|
||||
LineGradientProgram,
|
||||
LineSDFProgram,
|
||||
LinePatternProgram,
|
||||
SymbolIconProgram,
|
||||
SymbolSDFIconProgram,
|
||||
SymbolSDFTextProgram,
|
||||
SymbolTextAndIconProgram,
|
||||
CollisionBoxProgram,
|
||||
CollisionCircleProgram,
|
||||
DebugProgram,
|
||||
ClippingMaskProgram>(registry, programParameters);
|
||||
#else
|
||||
/// The following types will be registered
|
||||
registerTypes<DebugProgram, ClippingMaskProgram>(registry, programParameters);
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace mbgl
|
||||
@@ -6,7 +6,7 @@ namespace mbgl {
|
||||
|
||||
using namespace style;
|
||||
|
||||
HillshadeBucket::HillshadeBucket(PremultipliedImage&& image_, Tileset::DEMEncoding encoding)
|
||||
HillshadeBucket::HillshadeBucket(PremultipliedImage&& image_, Tileset::RasterEncoding encoding)
|
||||
: demdata(image_, encoding) {}
|
||||
|
||||
HillshadeBucket::HillshadeBucket(DEMData&& demdata_)
|
||||
|
||||
@@ -19,8 +19,8 @@ using HillshadeLayoutVertex = gfx::Vertex<TypeList<attributes::pos, attributes::
|
||||
|
||||
class HillshadeBucket final : public Bucket {
|
||||
public:
|
||||
HillshadeBucket(PremultipliedImage&&, Tileset::DEMEncoding encoding);
|
||||
HillshadeBucket(std::shared_ptr<PremultipliedImage>, Tileset::DEMEncoding encoding);
|
||||
HillshadeBucket(PremultipliedImage&&, Tileset::RasterEncoding encoding);
|
||||
HillshadeBucket(std::shared_ptr<PremultipliedImage>, Tileset::RasterEncoding encoding);
|
||||
HillshadeBucket(DEMData&&);
|
||||
~HillshadeBucket() override;
|
||||
|
||||
|
||||
@@ -79,7 +79,7 @@ void LineBucket::addGeometry(const GeometryCoordinates& coordinates,
|
||||
const std::size_t first = [&coordinates, &len] {
|
||||
std::size_t i = 0;
|
||||
// If the line has duplicate vertices at the start, adjust index to remove them.
|
||||
while (i < len - 1 && coordinates[i] == coordinates[i + 1]) {
|
||||
while (i + 1 < len && coordinates[i] == coordinates[i + 1]) {
|
||||
i++;
|
||||
}
|
||||
return i;
|
||||
@@ -102,17 +102,16 @@ void LineBucket::addGeometry(const GeometryCoordinates& coordinates,
|
||||
return;
|
||||
}
|
||||
|
||||
const auto& props = feature.getProperties();
|
||||
auto clip_start_it = props.find("mapbox_clip_start");
|
||||
auto clip_end_it = props.find("mapbox_clip_end");
|
||||
if (clip_start_it != props.end() && clip_end_it != props.end()) {
|
||||
const auto clip_start = feature.getValue("mapbox_clip_start");
|
||||
const auto clip_end = feature.getValue("mapbox_clip_end");
|
||||
if (clip_start && clip_end) {
|
||||
double total_length = 0.0;
|
||||
for (std::size_t i = first; i < len - 1; ++i) {
|
||||
total_length += util::dist<double>(coordinates[i], coordinates[i + 1]);
|
||||
}
|
||||
|
||||
options.clipDistances = gfx::PolylineGeneratorDistances{
|
||||
*numericValue<double>(clip_start_it->second), *numericValue<double>(clip_end_it->second), total_length};
|
||||
*numericValue<double>(*clip_start), *numericValue<double>(*clip_end), total_length};
|
||||
}
|
||||
|
||||
options.joinType = layout.evaluate<LineJoin>(zoom, feature, canonical);
|
||||
|
||||
@@ -22,8 +22,8 @@ constexpr std::array<float, 4> unpackMapbox = {{6553.6f, 25.6f, 0.1f, 10000.0f}}
|
||||
// https://aws.amazon.com/public-datasets/terrain/
|
||||
constexpr std::array<float, 4> unpackTerrarium = {{256.0f, 1.0f, 1.0f / 256.0f, 32768.0f}};
|
||||
|
||||
constexpr const std::array<float, 4>& getUnpackVector(const Tileset::DEMEncoding encoding) {
|
||||
return (encoding == Tileset::DEMEncoding::Terrarium) ? unpackTerrarium : unpackMapbox;
|
||||
constexpr const std::array<float, 4>& getUnpackVector(const Tileset::RasterEncoding encoding) {
|
||||
return (encoding == Tileset::RasterEncoding::Terrarium) ? unpackTerrarium : unpackMapbox;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ std::unique_ptr<RenderSource> RenderSource::create(const Immutable<Source::Impl>
|
||||
const TaggedScheduler& threadPool_) {
|
||||
switch (impl->type) {
|
||||
case SourceType::Vector:
|
||||
// the TileSet isn't available yet, so we can't make different sources by format
|
||||
return std::make_unique<RenderVectorSource>(staticImmutableCast<TileSource::Impl>(impl),
|
||||
std::move(threadPool_));
|
||||
case SourceType::Raster:
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
#include <mbgl/renderer/sources/render_vector_source.hpp>
|
||||
|
||||
#include <mbgl/renderer/render_tile.hpp>
|
||||
#include <mbgl/renderer/paint_parameters.hpp>
|
||||
#include <mbgl/tile/vector_tile.hpp>
|
||||
#include <mbgl/renderer/tile_parameters.hpp>
|
||||
#include <mbgl/tile/vector_mlt_tile.hpp>
|
||||
#include <mbgl/tile/vector_mvt_tile.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
@@ -20,17 +22,29 @@ void RenderVectorSource::updateInternal(const Tileset& tileset,
|
||||
const bool needsRendering,
|
||||
const bool needsRelayout,
|
||||
const TileParameters& parameters) {
|
||||
tilePyramid.update(layers,
|
||||
needsRendering,
|
||||
needsRelayout,
|
||||
parameters,
|
||||
*baseImpl,
|
||||
util::tileSize_I,
|
||||
tileset.zoomRange,
|
||||
tileset.bounds,
|
||||
[&](const OverscaledTileID& tileID, TileObserver* observer_) {
|
||||
return std::make_unique<VectorTile>(tileID, baseImpl->id, parameters, tileset, observer_);
|
||||
});
|
||||
tilePyramid.update(
|
||||
layers,
|
||||
needsRendering,
|
||||
needsRelayout,
|
||||
parameters,
|
||||
*baseImpl,
|
||||
util::tileSize_I,
|
||||
tileset.zoomRange,
|
||||
tileset.bounds,
|
||||
[&](const OverscaledTileID& tileID, TileObserver* observer_) -> std::unique_ptr<VectorTile> {
|
||||
if (!isMLT.has_value()) {
|
||||
auto impl = staticImmutableCast<style::TileSource::Impl>(baseImpl);
|
||||
assert(impl->tileset); // we should have one by now
|
||||
if (impl->tileset) {
|
||||
isMLT = (impl->tileset->vectorEncoding == Tileset::VectorEncoding::MLT);
|
||||
}
|
||||
}
|
||||
if (isMLT && *isMLT) {
|
||||
return std::make_unique<VectorMLTTile>(tileID, baseImpl->id, parameters, tileset, observer_);
|
||||
} else {
|
||||
return std::make_unique<VectorMVTTile>(tileID, baseImpl->id, parameters, tileset, observer_);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -17,6 +17,9 @@ private:
|
||||
bool needsRelayout,
|
||||
const TileParameters&) override;
|
||||
const std::optional<Tileset>& getTileset() const override;
|
||||
|
||||
private:
|
||||
std::optional<bool> isMLT;
|
||||
};
|
||||
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
#include <mbgl/style/conversion/raster_dem_options.hpp>
|
||||
#include <mbgl/style/conversion_impl.hpp>
|
||||
#include <mbgl/style/expression/dsl.hpp>
|
||||
|
||||
#include <sstream>
|
||||
|
||||
namespace mbgl {
|
||||
namespace style {
|
||||
namespace conversion {
|
||||
|
||||
std::optional<RasterDEMOptions> Converter<RasterDEMOptions>::operator()(const Convertible& value, Error& error) const {
|
||||
RasterDEMOptions options;
|
||||
|
||||
auto encodingValue = objectMember(value, "encoding");
|
||||
if (encodingValue) {
|
||||
std::optional<std::string> encoding = toString(*encodingValue);
|
||||
if (encoding && *encoding == "terrarium") {
|
||||
options.encoding = {Tileset::DEMEncoding::Terrarium};
|
||||
} else if (encoding && *encoding == "mapbox") {
|
||||
options.encoding = {Tileset::DEMEncoding::Mapbox};
|
||||
} else {
|
||||
error.message =
|
||||
"invalid raster-dem encoding type - valid types are 'mapbox' "
|
||||
"and 'terrarium'";
|
||||
return std::nullopt;
|
||||
}
|
||||
}
|
||||
|
||||
return {std::move(options)};
|
||||
}
|
||||
|
||||
} // namespace conversion
|
||||
} // namespace style
|
||||
} // namespace mbgl
|
||||
@@ -2,7 +2,7 @@
|
||||
#include <mbgl/style/conversion/coordinate.hpp>
|
||||
#include <mbgl/style/conversion/geojson.hpp>
|
||||
#include <mbgl/style/conversion/geojson_options.hpp>
|
||||
#include <mbgl/style/conversion/raster_dem_options.hpp>
|
||||
#include <mbgl/style/conversion/source_options.hpp>
|
||||
#include <mbgl/style/conversion/tileset.hpp>
|
||||
#include <mbgl/style/conversion_impl.hpp>
|
||||
#include <mbgl/style/sources/geojson_source.hpp>
|
||||
@@ -16,8 +16,8 @@ namespace mbgl {
|
||||
namespace style {
|
||||
namespace conversion {
|
||||
|
||||
// A tile source can either specify a URL to TileJSON, or inline TileJSON.
|
||||
namespace {
|
||||
// A tile source can either specify a URL to TileJSON, or inline TileJSON.
|
||||
std::optional<variant<std::string, Tileset>> convertURLOrTileset(const Convertible& value, Error& error) {
|
||||
auto urlVal = objectMember(value, "url");
|
||||
if (!urlVal) {
|
||||
@@ -25,7 +25,7 @@ std::optional<variant<std::string, Tileset>> convertURLOrTileset(const Convertib
|
||||
if (!tileset) {
|
||||
return std::nullopt;
|
||||
}
|
||||
return {*tileset};
|
||||
return {std::move(*tileset)};
|
||||
}
|
||||
|
||||
std::optional<std::string> url = toString(*urlVal);
|
||||
@@ -34,7 +34,7 @@ std::optional<variant<std::string, Tileset>> convertURLOrTileset(const Convertib
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
return {*url};
|
||||
return {std::move(*url)};
|
||||
}
|
||||
|
||||
std::optional<std::unique_ptr<Source>> convertRasterSource(const std::string& id,
|
||||
@@ -83,7 +83,7 @@ std::optional<std::unique_ptr<Source>> convertRasterDEMSource(const std::string&
|
||||
parameters. Since style.json can contain TileJSON parameter overrides or non-TileJSON spec parameters, a
|
||||
separate mechanism is needed. Ideally these two pathways share parsing logic.
|
||||
*/
|
||||
std::optional<RasterDEMOptions> options = convert<RasterDEMOptions>(value, error);
|
||||
auto options = convert<SourceOptions>(value, error);
|
||||
|
||||
return {std::make_unique<RasterDEMSource>(id, std::move(*urlOrTileset), tileSize, options)};
|
||||
}
|
||||
@@ -91,11 +91,11 @@ std::optional<std::unique_ptr<Source>> convertRasterDEMSource(const std::string&
|
||||
std::optional<std::unique_ptr<Source>> convertVectorSource(const std::string& id,
|
||||
const Convertible& value,
|
||||
Error& error) {
|
||||
std::optional<variant<std::string, Tileset>> urlOrTileset = convertURLOrTileset(value, error);
|
||||
auto urlOrTileset = convertURLOrTileset(value, error);
|
||||
if (!urlOrTileset) {
|
||||
return std::nullopt;
|
||||
}
|
||||
auto maxzoomValue = objectMember(value, "maxzoom");
|
||||
const auto maxzoomValue = objectMember(value, "maxzoom");
|
||||
std::optional<float> maxzoom;
|
||||
if (maxzoomValue) {
|
||||
maxzoom = toNumber(*maxzoomValue);
|
||||
@@ -104,7 +104,7 @@ std::optional<std::unique_ptr<Source>> convertVectorSource(const std::string& id
|
||||
return std::nullopt;
|
||||
}
|
||||
}
|
||||
auto minzoomValue = objectMember(value, "minzoom");
|
||||
const auto minzoomValue = objectMember(value, "minzoom");
|
||||
std::optional<float> minzoom;
|
||||
if (minzoomValue) {
|
||||
minzoom = toNumber(*minzoomValue);
|
||||
@@ -113,7 +113,20 @@ std::optional<std::unique_ptr<Source>> convertVectorSource(const std::string& id
|
||||
return std::nullopt;
|
||||
}
|
||||
}
|
||||
return {std::make_unique<VectorSource>(id, std::move(*urlOrTileset), std::move(maxzoom), std::move(minzoom))};
|
||||
const auto encodingValue = objectMember(value, "encoding");
|
||||
auto encoding = Tileset::VectorEncoding::Mapbox;
|
||||
if (encodingValue) {
|
||||
const auto encodingStr = toString(*encodingValue);
|
||||
if (encodingStr && encodingStr == "mvt") {
|
||||
encoding = Tileset::VectorEncoding::Mapbox;
|
||||
} else if (encodingStr && encodingStr == "mlt") {
|
||||
encoding = Tileset::VectorEncoding::MLT;
|
||||
} else {
|
||||
error.message = "invalid encoding";
|
||||
return std::nullopt;
|
||||
}
|
||||
}
|
||||
return {std::make_unique<VectorSource>(id, std::move(*urlOrTileset), maxzoom, minzoom, encoding)};
|
||||
}
|
||||
|
||||
std::optional<std::unique_ptr<Source>> convertGeoJSONSource(const std::string& id,
|
||||
|
||||
33
src/mbgl/style/conversion/source_options.cpp
Normal file
33
src/mbgl/style/conversion/source_options.cpp
Normal file
@@ -0,0 +1,33 @@
|
||||
#include <mbgl/style/conversion/source_options.hpp>
|
||||
#include <mbgl/style/conversion_impl.hpp>
|
||||
#include <mbgl/style/expression/dsl.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
namespace style {
|
||||
namespace conversion {
|
||||
|
||||
std::optional<SourceOptions> Converter<SourceOptions>::operator()(const Convertible& value, Error& error) const {
|
||||
const auto encodingValue = objectMember(value, "encoding");
|
||||
if (encodingValue) {
|
||||
const auto encoding = toString(*encodingValue);
|
||||
if (encoding && *encoding == "terrarium") {
|
||||
return {{.rasterEncoding = Tileset::RasterEncoding::Terrarium}};
|
||||
} else if (encoding && *encoding == "mapbox") {
|
||||
return {{.rasterEncoding = Tileset::RasterEncoding::Mapbox}};
|
||||
} else if (encoding && *encoding == "mvt") {
|
||||
return {{.vectorEncoding = Tileset::VectorEncoding::Mapbox}};
|
||||
} else if (encoding && *encoding == "mlt") {
|
||||
return {{.vectorEncoding = Tileset::VectorEncoding::MLT}};
|
||||
} else {
|
||||
error.message =
|
||||
"invalid encoding - valid types are 'mapbox' and 'terrarium' for raster sources, 'mvt' and 'mlt' for "
|
||||
"vector sources";
|
||||
return std::nullopt;
|
||||
}
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
} // namespace conversion
|
||||
} // namespace style
|
||||
} // namespace mbgl
|
||||
@@ -1,5 +1,5 @@
|
||||
#include <mbgl/style/conversion/tileset.hpp>
|
||||
#include <mbgl/style/conversion/raster_dem_options.hpp>
|
||||
#include <mbgl/style/conversion/source_options.hpp>
|
||||
#include <mbgl/style/conversion_impl.hpp>
|
||||
#include <mbgl/util/geo.hpp>
|
||||
#include <mbgl/math/clamp.hpp>
|
||||
@@ -39,10 +39,13 @@ std::optional<Tileset> Converter<Tileset>::operator()(const Convertible& value,
|
||||
}
|
||||
}
|
||||
|
||||
auto rasterDEMOptions = convert<RasterDEMOptions>(value, error);
|
||||
if (rasterDEMOptions) {
|
||||
if (std::optional<Tileset::DEMEncoding> encoding = rasterDEMOptions.value().encoding) {
|
||||
result.encoding = encoding.value();
|
||||
auto options = convert<SourceOptions>(value, error);
|
||||
if (options) {
|
||||
if (const auto encoding = options->rasterEncoding) {
|
||||
result.rasterEncoding = encoding;
|
||||
}
|
||||
if (const auto encoding = options->vectorEncoding) {
|
||||
result.vectorEncoding = encoding;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace style {
|
||||
RasterDEMSource::RasterDEMSource(std::string id,
|
||||
variant<std::string, Tileset> urlOrTileset_,
|
||||
uint16_t tileSize,
|
||||
std::optional<RasterDEMOptions> options_)
|
||||
std::optional<SourceOptions> options_)
|
||||
: RasterSource(std::move(id), std::move(urlOrTileset_), tileSize, SourceType::RasterDEM),
|
||||
options(std::move(options_)) {}
|
||||
|
||||
@@ -30,8 +30,8 @@ bool RasterDEMSource::supportsLayerType(const mbgl::style::LayerTypeInfo* info)
|
||||
|
||||
void RasterDEMSource::setTilesetOverrides(Tileset& tileset) {
|
||||
if (options) {
|
||||
if (std::optional<Tileset::DEMEncoding> encoding = options.value().encoding) {
|
||||
tileset.encoding = encoding.value();
|
||||
if (const auto encoding = options->rasterEncoding) {
|
||||
tileset.rasterEncoding = encoding;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include <mbgl/util/constants.hpp>
|
||||
#include <mbgl/util/exception.hpp>
|
||||
#include <mbgl/util/mapbox.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace mbgl {
|
||||
namespace style {
|
||||
@@ -17,10 +18,12 @@ namespace style {
|
||||
VectorSource::VectorSource(std::string id,
|
||||
variant<std::string, Tileset> urlOrTileset_,
|
||||
std::optional<float> maxZoom_,
|
||||
std::optional<float> minZoom_)
|
||||
std::optional<float> minZoom_,
|
||||
Tileset::VectorEncoding encoding_)
|
||||
: TileSource(id, urlOrTileset_, util::tileSize_I, SourceType::Vector),
|
||||
maxZoom(std::move(maxZoom_)),
|
||||
minZoom(std::move(minZoom_)) {}
|
||||
minZoom(std::move(minZoom_)),
|
||||
encoding(encoding_) {}
|
||||
|
||||
void VectorSource::setTilesetOverrides(Tileset& tileset) {
|
||||
if (maxZoom) {
|
||||
|
||||
@@ -4,11 +4,14 @@
|
||||
#include <mbgl/util/feature.hpp>
|
||||
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <span>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
|
||||
namespace mlt {
|
||||
class MapLibreTile;
|
||||
}
|
||||
namespace mbgl {
|
||||
|
||||
class CanonicalTileID;
|
||||
@@ -44,8 +47,17 @@ public:
|
||||
|
||||
GeometryCollection clone() const { return GeometryCollection(*this); }
|
||||
|
||||
const auto& getTriangles() const { return triangles; }
|
||||
void setTriangles(std::shared_ptr<const mlt::MapLibreTile> owner, std::span<const std::uint32_t> triangles_) {
|
||||
triangleOwner = std::move(owner);
|
||||
triangles = triangles_;
|
||||
}
|
||||
|
||||
private:
|
||||
GeometryCollection(const GeometryCollection&) = default;
|
||||
|
||||
std::shared_ptr<const mlt::MapLibreTile> triangleOwner;
|
||||
std::span<const std::uint32_t> triangles = {};
|
||||
};
|
||||
|
||||
class GeometryTileFeature {
|
||||
|
||||
@@ -24,7 +24,7 @@ RasterDEMTile::RasterDEMTile(const OverscaledTileID& id_,
|
||||
threadPool(parameters.threadPool),
|
||||
mailbox(std::make_shared<Mailbox>(*Scheduler::GetCurrent())),
|
||||
worker(parameters.threadPool, ActorRef<RasterDEMTile>(*this, mailbox)) {
|
||||
encoding = tileset.encoding;
|
||||
encoding = tileset.rasterEncoding.value_or(Tileset::RasterEncoding::Mapbox);
|
||||
if (id.canonical.y == 0) {
|
||||
// this tile doesn't have upper neighboring tiles so marked those as backfilled
|
||||
neighboringTiles = neighboringTiles | DEMTileNeighbors::NoUpper;
|
||||
|
||||
@@ -99,7 +99,7 @@ private:
|
||||
Actor<RasterDEMTileWorker> worker;
|
||||
|
||||
uint64_t correlationID = 0;
|
||||
Tileset::DEMEncoding encoding;
|
||||
Tileset::RasterEncoding encoding;
|
||||
|
||||
// Contains the Bucket object for the tile. Buckets are render
|
||||
// objects and they get added by tile parsing operations.
|
||||
|
||||
@@ -11,7 +11,7 @@ RasterDEMTileWorker::RasterDEMTileWorker(const ActorRef<RasterDEMTileWorker>&, A
|
||||
|
||||
void RasterDEMTileWorker::parse(const std::shared_ptr<const std::string>& data,
|
||||
uint64_t correlationID,
|
||||
Tileset::DEMEncoding encoding) {
|
||||
Tileset::RasterEncoding encoding) {
|
||||
if (!data) {
|
||||
parent.invoke(&RasterDEMTile::onParsed, nullptr,
|
||||
correlationID); // No data; empty tile.
|
||||
|
||||
@@ -14,7 +14,9 @@ class RasterDEMTileWorker {
|
||||
public:
|
||||
RasterDEMTileWorker(const ActorRef<RasterDEMTileWorker>&, ActorRef<RasterDEMTile>);
|
||||
|
||||
void parse(const std::shared_ptr<const std::string>& data, uint64_t correlationID, Tileset::DEMEncoding encoding);
|
||||
void parse(const std::shared_ptr<const std::string>& data,
|
||||
uint64_t correlationID,
|
||||
Tileset::RasterEncoding encoding);
|
||||
|
||||
private:
|
||||
ActorRef<RasterDEMTile> parent;
|
||||
|
||||
24
src/mbgl/tile/vector_mlt_tile.cpp
Normal file
24
src/mbgl/tile/vector_mlt_tile.cpp
Normal file
@@ -0,0 +1,24 @@
|
||||
#include <mbgl/tile/vector_mlt_tile.hpp>
|
||||
|
||||
#include <mbgl/renderer/tile_parameters.hpp>
|
||||
#include <mbgl/tile/tile_loader_impl.hpp>
|
||||
#include <mbgl/tile/vector_mlt_tile_data.hpp>
|
||||
|
||||
#include <utility>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
VectorMLTTile::VectorMLTTile(const OverscaledTileID& id_,
|
||||
std::string sourceID_,
|
||||
const TileParameters& parameters_,
|
||||
const Tileset& tileset_,
|
||||
TileObserver* observer_)
|
||||
: VectorTile(id_, std::move(sourceID_), parameters_, tileset_, observer_) {}
|
||||
|
||||
void VectorMLTTile::setData(const std::shared_ptr<const std::string>& data_) {
|
||||
if (!obsolete) {
|
||||
GeometryTile::setData(data_ ? std::make_unique<VectorMLTTileData>(data_) : nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace mbgl
|
||||
23
src/mbgl/tile/vector_mlt_tile.hpp
Normal file
23
src/mbgl/tile/vector_mlt_tile.hpp
Normal file
@@ -0,0 +1,23 @@
|
||||
#pragma once
|
||||
|
||||
#include <mbgl/tile/geometry_tile.hpp>
|
||||
#include <mbgl/tile/tile_loader.hpp>
|
||||
#include <mbgl/tile/vector_tile.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
class Tileset;
|
||||
class TileParameters;
|
||||
|
||||
class VectorMLTTile : public VectorTile {
|
||||
public:
|
||||
VectorMLTTile(const OverscaledTileID&,
|
||||
std::string sourceID,
|
||||
const TileParameters&,
|
||||
const Tileset&,
|
||||
TileObserver* observer = nullptr);
|
||||
|
||||
void setData(const std::shared_ptr<const std::string>& data) override;
|
||||
};
|
||||
|
||||
} // namespace mbgl
|
||||
220
src/mbgl/tile/vector_mlt_tile_data.cpp
Normal file
220
src/mbgl/tile/vector_mlt_tile_data.cpp
Normal file
@@ -0,0 +1,220 @@
|
||||
#include <mapbox/feature.hpp>
|
||||
#include <mbgl/tile/vector_mlt_tile_data.hpp>
|
||||
|
||||
#include <mbgl/util/constants.hpp>
|
||||
#include <mbgl/util/instrumentation.hpp>
|
||||
#include <mbgl/util/logging.hpp>
|
||||
|
||||
#include <mlt/decoder.hpp>
|
||||
#include <mlt/layer.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
using GeometryType = mlt::metadata::tileset::GeometryType;
|
||||
|
||||
VectorMLTTileFeature::VectorMLTTileFeature(std::shared_ptr<const MapLibreTile> tile_,
|
||||
const mlt::Layer& layer_,
|
||||
const mlt::Feature& feature_,
|
||||
std::uint32_t extent_)
|
||||
: tile(std::move(tile_)),
|
||||
layer(layer_),
|
||||
feature(feature_),
|
||||
extent(extent_) {}
|
||||
|
||||
FeatureType VectorMLTTileFeature::getType() const {
|
||||
switch (feature.getGeometry().type) {
|
||||
case GeometryType::POINT:
|
||||
return FeatureType::Point;
|
||||
case GeometryType::MULTIPOINT:
|
||||
case GeometryType::MULTILINESTRING:
|
||||
case GeometryType::LINESTRING:
|
||||
return FeatureType::LineString;
|
||||
case GeometryType::POLYGON:
|
||||
case GeometryType::MULTIPOLYGON:
|
||||
return FeatureType::Polygon;
|
||||
default:
|
||||
return FeatureType::Unknown;
|
||||
}
|
||||
}
|
||||
|
||||
namespace {
|
||||
struct PropertyVisitor {
|
||||
Value operator()(std::nullptr_t) const { return mapbox::feature::null_value; }
|
||||
Value operator()(bool value) const { return value; }
|
||||
Value operator()(std::uint32_t value) const { return value; }
|
||||
Value operator()(std::uint64_t value) const { return value; }
|
||||
Value operator()(float value) const { return value; }
|
||||
Value operator()(double value) const { return value; }
|
||||
Value operator()(std::string_view value) const { return std::string(value); }
|
||||
|
||||
template <typename T>
|
||||
Value operator()(std::optional<T> value) const {
|
||||
return value ? operator()(*value) : NullValue();
|
||||
}
|
||||
};
|
||||
} // namespace
|
||||
|
||||
std::optional<Value> VectorMLTTileFeature::getValue(const std::string& key) const {
|
||||
if (auto prop = feature.getProperty(key, layer)) {
|
||||
return std::visit(PropertyVisitor(), *prop);
|
||||
}
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
const PropertyMap& VectorMLTTileFeature::getProperties() const {
|
||||
if (!properties) {
|
||||
const PropertyVisitor visitor;
|
||||
properties.emplace();
|
||||
properties->reserve(layer.getProperties().size());
|
||||
for (const auto& [key, props] : layer.getProperties()) {
|
||||
auto value = props.getProperty(feature.getIndex());
|
||||
auto prop = value ? std::visit(visitor, std::move(*value)) : mapbox::feature::null_value;
|
||||
properties->emplace(key, std::move(prop));
|
||||
}
|
||||
}
|
||||
return *properties;
|
||||
}
|
||||
|
||||
FeatureIdentifier VectorMLTTileFeature::getID() const {
|
||||
return feature.getID();
|
||||
}
|
||||
|
||||
namespace {
|
||||
struct PointConverter {
|
||||
double scale;
|
||||
inline constexpr static GeometryCoordinate convert(double scale, const mlt::Coordinate& coord) {
|
||||
return {static_cast<std::int16_t>(std::round(coord.x * scale)),
|
||||
static_cast<std::int16_t>(std::round(coord.y * scale))};
|
||||
}
|
||||
GeometryCoordinate operator()(const mlt::Coordinate& coord) const { return convert(scale, coord); }
|
||||
GeometryCoordinates operator()(const mlt::CoordVec& coords) const {
|
||||
GeometryCoordinates result(coords.size());
|
||||
std::ranges::transform(coords, result.begin(), *this);
|
||||
return result;
|
||||
}
|
||||
};
|
||||
} // namespace
|
||||
|
||||
const GeometryCollection& VectorMLTTileFeature::getGeometries() const {
|
||||
MLN_TRACE_FUNC();
|
||||
|
||||
if (!lines) {
|
||||
const auto scale = static_cast<double>(util::EXTENT) / extent;
|
||||
const auto& geometry = feature.getGeometry();
|
||||
const PointConverter convert{scale};
|
||||
switch (geometry.type) {
|
||||
case GeometryType::POINT: {
|
||||
const auto& geom = static_cast<const mlt::geometry::Point&>(geometry);
|
||||
lines = GeometryCollection{{convert(geom.getCoordinate())}};
|
||||
break;
|
||||
}
|
||||
case GeometryType::MULTIPOINT:
|
||||
case GeometryType::LINESTRING: {
|
||||
const auto& geom = static_cast<const mlt::geometry::MultiPoint&>(geometry);
|
||||
lines = GeometryCollection{convert(geom.getCoordinates())};
|
||||
break;
|
||||
}
|
||||
case GeometryType::POLYGON: {
|
||||
const auto& geom = static_cast<const mlt::geometry::Polygon&>(geometry);
|
||||
lines.emplace(geom.getRings().size());
|
||||
std::ranges::transform(geom.getRings(), lines->begin(), convert);
|
||||
if (!geometry.getTriangles().empty()) {
|
||||
lines->setTriangles(tile, geometry.getTriangles());
|
||||
}
|
||||
break;
|
||||
}
|
||||
case GeometryType::MULTILINESTRING: {
|
||||
const auto& geom = static_cast<const mlt::geometry::MultiLineString&>(geometry);
|
||||
lines.emplace(geom.getLineStrings().size());
|
||||
std::ranges::transform(geom.getLineStrings(), lines->begin(), convert);
|
||||
break;
|
||||
}
|
||||
case GeometryType::MULTIPOLYGON: {
|
||||
const auto& geom = static_cast<const mlt::geometry::MultiPolygon&>(geometry);
|
||||
const auto& polygons = geom.getPolygons();
|
||||
using RingVec = mlt::geometry::MultiPolygon::RingVec;
|
||||
lines.emplace(std::accumulate(
|
||||
polygons.begin(), polygons.end(), static_cast<std::size_t>(0), [](std::size_t a, const RingVec& b) {
|
||||
return a + b.size();
|
||||
}));
|
||||
for (const auto& poly : polygons) {
|
||||
std::ranges::transform(poly, std::back_inserter(*lines), convert);
|
||||
}
|
||||
if (!geometry.getTriangles().empty()) {
|
||||
lines->setTriangles(tile, geometry.getTriangles());
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
lines.emplace();
|
||||
break;
|
||||
}
|
||||
}
|
||||
return *lines;
|
||||
}
|
||||
|
||||
VectorMLTTileLayer::VectorMLTTileLayer(std::shared_ptr<const MapLibreTile> tile_, const mlt::Layer& layer_)
|
||||
: tile(std::move(tile_)),
|
||||
layer(layer_) {}
|
||||
|
||||
std::size_t VectorMLTTileLayer::featureCount() const {
|
||||
return layer.getFeatures().size();
|
||||
}
|
||||
|
||||
std::unique_ptr<GeometryTileFeature> VectorMLTTileLayer::getFeature(std::size_t index) const {
|
||||
const auto& features = layer.getFeatures();
|
||||
const mlt::Feature* targetFeature = nullptr;
|
||||
targetFeature = &features[index];
|
||||
return std::make_unique<VectorMLTTileFeature>(tile, layer, *targetFeature, layer.getExtent());
|
||||
}
|
||||
|
||||
std::string VectorMLTTileLayer::getName() const {
|
||||
return layer.getName();
|
||||
}
|
||||
|
||||
VectorMLTTileData::VectorMLTTileData(std::shared_ptr<const std::string> data_)
|
||||
: data(std::move(data_)) {}
|
||||
|
||||
VectorMLTTileData::VectorMLTTileData(const VectorMLTTileData& other)
|
||||
: data(other.data),
|
||||
tile(other.tile) {}
|
||||
|
||||
std::unique_ptr<GeometryTileData> VectorMLTTileData::clone() const {
|
||||
return std::make_unique<VectorMLTTileData>(*this);
|
||||
}
|
||||
|
||||
std::unique_ptr<GeometryTileLayer> VectorMLTTileData::getLayer(const std::string& name) const {
|
||||
MLN_TRACE_FUNC();
|
||||
|
||||
if (data && !tile) {
|
||||
try {
|
||||
mlt::DataView tileData{data->data(), data->size()};
|
||||
tile = std::make_shared<MapLibreTile>(mlt::Decoder().decode(tileData));
|
||||
} catch (const std::exception& ex) {
|
||||
Log::Warning(Event::ParseTile, "MLT parse failed: " + std::string(ex.what()));
|
||||
}
|
||||
// We don't need the raw data anymore
|
||||
data.reset();
|
||||
}
|
||||
|
||||
if (tile) {
|
||||
if (const auto* layer = tile->getLayer(name)) {
|
||||
return std::make_unique<VectorMLTTileLayer>(tile, *layer);
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::vector<std::string> VectorMLTTileData::layerNames() const {
|
||||
if (data && !data->empty() && !tile) {
|
||||
getLayer({});
|
||||
}
|
||||
if (tile) {
|
||||
std::vector<std::string> result(tile->getLayers().size());
|
||||
std::ranges::transform(tile->getLayers(), result.begin(), [](const auto& layer) { return layer.getName(); });
|
||||
return result;
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
} // namespace mbgl
|
||||
85
src/mbgl/tile/vector_mlt_tile_data.hpp
Normal file
85
src/mbgl/tile/vector_mlt_tile_data.hpp
Normal file
@@ -0,0 +1,85 @@
|
||||
#pragma once
|
||||
|
||||
#include <mbgl/tile/geometry_tile_data.hpp>
|
||||
#include <mbgl/util/containers.hpp>
|
||||
|
||||
#include <unordered_map>
|
||||
#include <functional>
|
||||
#include <utility>
|
||||
|
||||
namespace mlt {
|
||||
class MapLibreTile;
|
||||
class Feature;
|
||||
class Layer;
|
||||
} // namespace mlt
|
||||
|
||||
namespace mbgl {
|
||||
using MapLibreTile = mlt::MapLibreTile;
|
||||
|
||||
class VectorMLTTileFeature : public GeometryTileFeature {
|
||||
public:
|
||||
VectorMLTTileFeature(std::shared_ptr<const MapLibreTile>,
|
||||
const mlt::Layer& layer_,
|
||||
const mlt::Feature&,
|
||||
std::uint32_t extent);
|
||||
VectorMLTTileFeature(const VectorMLTTileFeature&) = delete;
|
||||
VectorMLTTileFeature(VectorMLTTileFeature&& other)
|
||||
: tile(std::move(other.tile)),
|
||||
layer(other.layer),
|
||||
feature(other.feature),
|
||||
extent(other.extent),
|
||||
version(other.version),
|
||||
lines(std::move(other.lines)),
|
||||
properties(std::move(other.properties)) {}
|
||||
|
||||
VectorMLTTileFeature& operator=(VectorMLTTileFeature&&) = delete;
|
||||
VectorMLTTileFeature& operator=(const VectorMLTTileFeature&) = delete;
|
||||
|
||||
FeatureType getType() const override;
|
||||
std::optional<Value> getValue(const std::string& key) const override;
|
||||
const PropertyMap& getProperties() const override;
|
||||
FeatureIdentifier getID() const override;
|
||||
const GeometryCollection& getGeometries() const override;
|
||||
|
||||
private:
|
||||
std::shared_ptr<const MapLibreTile> tile;
|
||||
const mlt::Layer& layer;
|
||||
mlt::Feature const& feature;
|
||||
std::uint32_t extent;
|
||||
int version;
|
||||
|
||||
// lazy init
|
||||
mutable std::optional<GeometryCollection> lines;
|
||||
mutable std::optional<PropertyMap> properties;
|
||||
};
|
||||
|
||||
class VectorMLTTileLayer : public GeometryTileLayer {
|
||||
public:
|
||||
VectorMLTTileLayer(std::shared_ptr<const MapLibreTile>, const mlt::Layer&);
|
||||
|
||||
std::size_t featureCount() const override;
|
||||
std::unique_ptr<GeometryTileFeature> getFeature(std::size_t i) const override;
|
||||
std::string getName() const override;
|
||||
|
||||
private:
|
||||
const std::shared_ptr<const MapLibreTile> tile;
|
||||
const mlt::Layer& layer;
|
||||
};
|
||||
|
||||
class VectorMLTTileData : public GeometryTileData {
|
||||
public:
|
||||
VectorMLTTileData(std::shared_ptr<const std::string> data);
|
||||
VectorMLTTileData(const VectorMLTTileData&);
|
||||
VectorMLTTileData(VectorMLTTileData&&) = default;
|
||||
|
||||
std::unique_ptr<GeometryTileData> clone() const override;
|
||||
std::unique_ptr<GeometryTileLayer> getLayer(const std::string& name) const override;
|
||||
|
||||
std::vector<std::string> layerNames() const;
|
||||
|
||||
private:
|
||||
mutable std::shared_ptr<const std::string> data;
|
||||
mutable std::shared_ptr<const MapLibreTile> tile;
|
||||
};
|
||||
|
||||
} // namespace mbgl
|
||||
24
src/mbgl/tile/vector_mvt_tile.cpp
Normal file
24
src/mbgl/tile/vector_mvt_tile.cpp
Normal file
@@ -0,0 +1,24 @@
|
||||
#include <mbgl/tile/vector_mvt_tile.hpp>
|
||||
|
||||
#include <mbgl/renderer/tile_parameters.hpp>
|
||||
#include <mbgl/tile/tile_loader_impl.hpp>
|
||||
#include <mbgl/tile/vector_mvt_tile_data.hpp>
|
||||
|
||||
#include <utility>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
VectorMVTTile::VectorMVTTile(const OverscaledTileID& id_,
|
||||
std::string sourceID_,
|
||||
const TileParameters& parameters_,
|
||||
const Tileset& tileset_,
|
||||
TileObserver* observer_)
|
||||
: VectorTile(id_, std::move(sourceID_), parameters_, tileset_, observer_) {}
|
||||
|
||||
void VectorMVTTile::setData(const std::shared_ptr<const std::string>& data_) {
|
||||
if (!obsolete) {
|
||||
GeometryTile::setData(data_ ? std::make_unique<VectorMVTTileData>(data_) : nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace mbgl
|
||||
23
src/mbgl/tile/vector_mvt_tile.hpp
Normal file
23
src/mbgl/tile/vector_mvt_tile.hpp
Normal file
@@ -0,0 +1,23 @@
|
||||
#pragma once
|
||||
|
||||
#include <mbgl/tile/geometry_tile.hpp>
|
||||
#include <mbgl/tile/tile_loader.hpp>
|
||||
#include <mbgl/tile/vector_tile.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
class Tileset;
|
||||
class TileParameters;
|
||||
|
||||
class VectorMVTTile : public VectorTile {
|
||||
public:
|
||||
VectorMVTTile(const OverscaledTileID&,
|
||||
std::string sourceID,
|
||||
const TileParameters&,
|
||||
const Tileset&,
|
||||
TileObserver* observer = nullptr);
|
||||
|
||||
void setData(const std::shared_ptr<const std::string>& data) override;
|
||||
};
|
||||
|
||||
} // namespace mbgl
|
||||
@@ -1,14 +1,19 @@
|
||||
#include <mbgl/tile/vector_tile_data.hpp>
|
||||
#include <mbgl/tile/vector_mvt_tile_data.hpp>
|
||||
|
||||
#include <mbgl/util/constants.hpp>
|
||||
#include <mbgl/util/instrumentation.hpp>
|
||||
#include <mbgl/util/logging.hpp>
|
||||
|
||||
#if ANDROID
|
||||
#include <mlt/decoder.hpp>
|
||||
#endif
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
VectorTileFeature::VectorTileFeature(const mapbox::vector_tile::layer& layer, const protozero::data_view& view)
|
||||
VectorMVTTileFeature::VectorMVTTileFeature(const mapbox::vector_tile::layer& layer, const protozero::data_view& view)
|
||||
: feature(view, layer) {}
|
||||
|
||||
FeatureType VectorTileFeature::getType() const {
|
||||
FeatureType VectorMVTTileFeature::getType() const {
|
||||
switch (feature.getType()) {
|
||||
case mapbox::vector_tile::GeomType::POINT:
|
||||
return FeatureType::Point;
|
||||
@@ -21,23 +26,23 @@ FeatureType VectorTileFeature::getType() const {
|
||||
}
|
||||
}
|
||||
|
||||
std::optional<Value> VectorTileFeature::getValue(const std::string& key) const {
|
||||
const std::optional<Value> value(feature.getValue(key));
|
||||
return value->is<NullValue>() ? std::nullopt : value;
|
||||
std::optional<Value> VectorMVTTileFeature::getValue(const std::string& key) const {
|
||||
const auto value = feature.getValue(key);
|
||||
return value.is<NullValue>() ? std::nullopt : std::optional<Value>{std::move(value)};
|
||||
}
|
||||
|
||||
const PropertyMap& VectorTileFeature::getProperties() const {
|
||||
const PropertyMap& VectorMVTTileFeature::getProperties() const {
|
||||
if (!properties) {
|
||||
properties = feature.getProperties();
|
||||
}
|
||||
return *properties;
|
||||
}
|
||||
|
||||
FeatureIdentifier VectorTileFeature::getID() const {
|
||||
FeatureIdentifier VectorMVTTileFeature::getID() const {
|
||||
return feature.getID();
|
||||
}
|
||||
|
||||
const GeometryCollection& VectorTileFeature::getGeometries() const {
|
||||
const GeometryCollection& VectorMVTTileFeature::getGeometries() const {
|
||||
MLN_TRACE_FUNC();
|
||||
|
||||
if (!lines) {
|
||||
@@ -57,30 +62,30 @@ const GeometryCollection& VectorTileFeature::getGeometries() const {
|
||||
return *lines;
|
||||
}
|
||||
|
||||
VectorTileLayer::VectorTileLayer(std::shared_ptr<const std::string> data_, const protozero::data_view& view)
|
||||
VectorMVTTileLayer::VectorMVTTileLayer(std::shared_ptr<const std::string> data_, const protozero::data_view& view)
|
||||
: data(std::move(data_)),
|
||||
layer(view) {}
|
||||
|
||||
std::size_t VectorTileLayer::featureCount() const {
|
||||
std::size_t VectorMVTTileLayer::featureCount() const {
|
||||
return layer.featureCount();
|
||||
}
|
||||
|
||||
std::unique_ptr<GeometryTileFeature> VectorTileLayer::getFeature(std::size_t i) const {
|
||||
return std::make_unique<VectorTileFeature>(layer, layer.getFeature(i));
|
||||
std::unique_ptr<GeometryTileFeature> VectorMVTTileLayer::getFeature(std::size_t i) const {
|
||||
return std::make_unique<VectorMVTTileFeature>(layer, layer.getFeature(i));
|
||||
}
|
||||
|
||||
std::string VectorTileLayer::getName() const {
|
||||
std::string VectorMVTTileLayer::getName() const {
|
||||
return layer.getName();
|
||||
}
|
||||
|
||||
VectorTileData::VectorTileData(std::shared_ptr<const std::string> data_)
|
||||
VectorMVTTileData::VectorMVTTileData(std::shared_ptr<const std::string> data_)
|
||||
: data(std::move(data_)) {}
|
||||
|
||||
std::unique_ptr<GeometryTileData> VectorTileData::clone() const {
|
||||
return std::make_unique<VectorTileData>(data);
|
||||
std::unique_ptr<GeometryTileData> VectorMVTTileData::clone() const {
|
||||
return std::make_unique<VectorMVTTileData>(data);
|
||||
}
|
||||
|
||||
std::unique_ptr<GeometryTileLayer> VectorTileData::getLayer(const std::string& name) const {
|
||||
std::unique_ptr<GeometryTileLayer> VectorMVTTileData::getLayer(const std::string& name) const {
|
||||
MLN_TRACE_FUNC();
|
||||
|
||||
if (!parsed) {
|
||||
@@ -93,12 +98,12 @@ std::unique_ptr<GeometryTileLayer> VectorTileData::getLayer(const std::string& n
|
||||
|
||||
auto it = layers.find(name);
|
||||
if (it != layers.end()) {
|
||||
return std::make_unique<VectorTileLayer>(data, it->second);
|
||||
return std::make_unique<VectorMVTTileLayer>(data, it->second);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::vector<std::string> VectorTileData::layerNames() const {
|
||||
std::vector<std::string> VectorMVTTileData::layerNames() const {
|
||||
return mapbox::vector_tile::buffer(*data).layerNames();
|
||||
}
|
||||
|
||||
@@ -20,9 +20,9 @@
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
class VectorTileFeature : public GeometryTileFeature {
|
||||
class VectorMVTTileFeature : public GeometryTileFeature {
|
||||
public:
|
||||
VectorTileFeature(const mapbox::vector_tile::layer&, const protozero::data_view&);
|
||||
VectorMVTTileFeature(const mapbox::vector_tile::layer&, const protozero::data_view&);
|
||||
|
||||
FeatureType getType() const override;
|
||||
std::optional<Value> getValue(const std::string& key) const override;
|
||||
@@ -36,9 +36,9 @@ private:
|
||||
mutable std::optional<PropertyMap> properties;
|
||||
};
|
||||
|
||||
class VectorTileLayer : public GeometryTileLayer {
|
||||
class VectorMVTTileLayer : public GeometryTileLayer {
|
||||
public:
|
||||
VectorTileLayer(std::shared_ptr<const std::string> data, const protozero::data_view&);
|
||||
VectorMVTTileLayer(std::shared_ptr<const std::string> data, const protozero::data_view&);
|
||||
|
||||
std::size_t featureCount() const override;
|
||||
std::unique_ptr<GeometryTileFeature> getFeature(std::size_t i) const override;
|
||||
@@ -49,9 +49,9 @@ private:
|
||||
mapbox::vector_tile::layer layer;
|
||||
};
|
||||
|
||||
class VectorTileData : public GeometryTileData {
|
||||
class VectorMVTTileData : public GeometryTileData {
|
||||
public:
|
||||
VectorTileData(std::shared_ptr<const std::string> data);
|
||||
VectorMVTTileData(std::shared_ptr<const std::string> data);
|
||||
|
||||
std::unique_ptr<GeometryTileData> clone() const override;
|
||||
std::unique_ptr<GeometryTileLayer> getLayer(const std::string& name) const override;
|
||||
@@ -1,18 +1,19 @@
|
||||
#include <mbgl/tile/vector_mvt_tile.hpp>
|
||||
|
||||
#include <mbgl/renderer/tile_parameters.hpp>
|
||||
#include <mbgl/tile/tile_loader_impl.hpp>
|
||||
#include <mbgl/tile/vector_tile.hpp>
|
||||
#include <mbgl/tile/vector_tile_data.hpp>
|
||||
|
||||
#include <utility>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
VectorTile::VectorTile(const OverscaledTileID& id_,
|
||||
std::string sourceID_,
|
||||
const TileParameters& parameters,
|
||||
const TileParameters& parameters_,
|
||||
const Tileset& tileset,
|
||||
TileObserver* observer_)
|
||||
: GeometryTile(id_, std::move(sourceID_), parameters, observer_),
|
||||
loader(*this, id_, parameters, tileset) {}
|
||||
: GeometryTile(id_, std::move(sourceID_), parameters_, observer_),
|
||||
loader(*this, id_, parameters_, tileset) {}
|
||||
|
||||
VectorTile::~VectorTile() {
|
||||
// Don't rely on `~TileLoader` to close, it's not safe to call there.
|
||||
@@ -33,12 +34,4 @@ void VectorTile::setMetadata(std::optional<Timestamp> modified_, std::optional<T
|
||||
expires = std::move(expires_);
|
||||
}
|
||||
|
||||
void VectorTile::setData(const std::shared_ptr<const std::string>& data_) {
|
||||
if (obsolete) {
|
||||
return;
|
||||
}
|
||||
|
||||
GeometryTile::setData(data_ ? std::make_unique<VectorTileData>(data_) : nullptr);
|
||||
}
|
||||
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -20,7 +20,8 @@ public:
|
||||
void setNecessity(TileNecessity) final;
|
||||
void setUpdateParameters(const TileUpdateParameters&) final;
|
||||
void setMetadata(std::optional<Timestamp> modified, std::optional<Timestamp> expires);
|
||||
void setData(const std::shared_ptr<const std::string>& data);
|
||||
|
||||
virtual void setData(const std::shared_ptr<const std::string>&) = 0;
|
||||
|
||||
private:
|
||||
TileLoader<VectorTile> loader;
|
||||
|
||||
Reference in New Issue
Block a user