core: add CustomVectorSource for binary tile data delivery (#4377)
Co-authored-by: Vladyslav Odobesku <VladyslavOdobesku@intellias.com> Co-authored-by: Claude Opus 4 <noreply@anthropic.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
25e4f6acbf
commit
9ef0f1c790
63
src/mbgl/tile/custom_vector_tile.cpp
Normal file
63
src/mbgl/tile/custom_vector_tile.cpp
Normal file
@@ -0,0 +1,63 @@
|
||||
#include <mbgl/tile/custom_vector_tile.hpp>
|
||||
#include <mbgl/tile/vector_mvt_tile_data.hpp>
|
||||
#include <mbgl/renderer/tile_parameters.hpp>
|
||||
#include <mbgl/actor/scheduler.hpp>
|
||||
#include <mbgl/style/custom_vector_tile_loader.hpp>
|
||||
#include <mbgl/tile/tile_observer.hpp>
|
||||
|
||||
#include <utility>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
CustomVectorTile::CustomVectorTile(const OverscaledTileID& overscaledTileID,
|
||||
std::string sourceID_,
|
||||
const TileParameters& parameters,
|
||||
ActorRef<style::CustomVectorTileLoader> loader_,
|
||||
TileObserver* observer_)
|
||||
: GeometryTile(overscaledTileID, std::move(sourceID_), parameters, observer_),
|
||||
necessity(TileNecessity::Optional),
|
||||
loader(std::move(loader_)),
|
||||
mailbox(std::make_shared<Mailbox>(*Scheduler::GetCurrent())),
|
||||
actorRef(*this, mailbox) {}
|
||||
|
||||
CustomVectorTile::~CustomVectorTile() {
|
||||
loader.invoke(&style::CustomVectorTileLoader::removeTile, id);
|
||||
}
|
||||
|
||||
void CustomVectorTile::setTileData(const std::shared_ptr<const std::string>& data, style::TileDataFormat format) {
|
||||
if (obsolete) return;
|
||||
|
||||
switch (format) {
|
||||
case style::TileDataFormat::MVT:
|
||||
GeometryTile::setData(data ? std::make_unique<VectorMVTTileData>(data) : nullptr);
|
||||
break;
|
||||
default:
|
||||
assert(false && "Unhandled TileDataFormat");
|
||||
GeometryTile::setData(nullptr);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void CustomVectorTile::setTileError(std::exception_ptr error) {
|
||||
if (obsolete) return;
|
||||
GeometryTile::setError(std::move(error));
|
||||
}
|
||||
|
||||
void CustomVectorTile::invalidateTileData() {
|
||||
stale = true;
|
||||
observer->onTileChanged(*this);
|
||||
}
|
||||
|
||||
void CustomVectorTile::setNecessity(TileNecessity newNecessity) {
|
||||
if (newNecessity != necessity || stale) {
|
||||
necessity = newNecessity;
|
||||
if (necessity == TileNecessity::Required) {
|
||||
loader.invoke(&style::CustomVectorTileLoader::fetchTile, id, actorRef);
|
||||
stale = false;
|
||||
} else if (!isRenderable()) {
|
||||
loader.invoke(&style::CustomVectorTileLoader::cancelTile, id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace mbgl
|
||||
Reference in New Issue
Block a user