[core] Ensure that FileSource has access to tile URL, pixelRatio, x, y, z
This commit is contained in:
@@ -31,6 +31,18 @@ public:
|
||||
optional<SystemTimePoint> priorModified;
|
||||
optional<SystemTimePoint> priorExpires;
|
||||
optional<std::string> priorEtag;
|
||||
|
||||
// Includes auxiliary data if this is a tile request.
|
||||
|
||||
struct TileData {
|
||||
std::string urlTemplate;
|
||||
float pixelRatio;
|
||||
int32_t x;
|
||||
int32_t y;
|
||||
int8_t z;
|
||||
};
|
||||
|
||||
optional<TileData> tileData;
|
||||
};
|
||||
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -5,27 +5,35 @@
|
||||
#include <mbgl/storage/file_source.hpp>
|
||||
#include <mbgl/util/worker.hpp>
|
||||
#include <mbgl/util/work_request.hpp>
|
||||
#include <mbgl/util/url.hpp>
|
||||
|
||||
using namespace mbgl;
|
||||
|
||||
RasterTileData::RasterTileData(const TileID& id_,
|
||||
float pixelRatio,
|
||||
const std::string& urlTemplate,
|
||||
TexturePool &texturePool_,
|
||||
Worker& worker_)
|
||||
Worker& worker_,
|
||||
const std::function<void(std::exception_ptr)>& callback)
|
||||
: TileData(id_),
|
||||
texturePool(texturePool_),
|
||||
worker(worker_) {
|
||||
}
|
||||
|
||||
RasterTileData::~RasterTileData() {
|
||||
cancel();
|
||||
}
|
||||
|
||||
void RasterTileData::request(const std::string& url,
|
||||
const RasterTileData::Callback& callback) {
|
||||
state = State::loading;
|
||||
|
||||
FileSource* fs = util::ThreadContext::getFileSource();
|
||||
req = fs->request({ Resource::Kind::Tile, url }, [url, callback, this](Response res) {
|
||||
Resource resource {
|
||||
Resource::Kind::Tile,
|
||||
util::templateTileURL(urlTemplate, id, pixelRatio)
|
||||
};
|
||||
|
||||
resource.tileData = Resource::TileData {
|
||||
urlTemplate,
|
||||
pixelRatio,
|
||||
id.x,
|
||||
id.y,
|
||||
id.z
|
||||
};
|
||||
|
||||
req = util::ThreadContext::getFileSource()->request(resource, [callback, this](Response res) {
|
||||
if (res.error) {
|
||||
std::exception_ptr error;
|
||||
if (res.error->reason == Response::Error::Reason::NotFound) {
|
||||
@@ -76,6 +84,10 @@ void RasterTileData::request(const std::string& url,
|
||||
});
|
||||
}
|
||||
|
||||
RasterTileData::~RasterTileData() {
|
||||
cancel();
|
||||
}
|
||||
|
||||
Bucket* RasterTileData::getBucket(StyleLayer const&) {
|
||||
return bucket.get();
|
||||
}
|
||||
|
||||
@@ -13,25 +13,22 @@ class WorkRequest;
|
||||
|
||||
class RasterTileData : public TileData {
|
||||
public:
|
||||
RasterTileData(const TileID&, TexturePool&, Worker&);
|
||||
RasterTileData(const TileID&,
|
||||
float pixelRatio,
|
||||
const std::string& urlTemplate,
|
||||
TexturePool&,
|
||||
Worker&,
|
||||
const std::function<void(std::exception_ptr)>& callback);
|
||||
~RasterTileData();
|
||||
|
||||
using Callback = std::function<void(std::exception_ptr)>;
|
||||
|
||||
void request(const std::string& url,
|
||||
const Callback& callback);
|
||||
|
||||
void cancel() override;
|
||||
|
||||
Bucket* getBucket(StyleLayer const &layer_desc) override;
|
||||
|
||||
private:
|
||||
TexturePool& texturePool;
|
||||
Worker& worker;
|
||||
std::unique_ptr<FileRequest> req;
|
||||
|
||||
std::unique_ptr<Bucket> bucket;
|
||||
|
||||
std::unique_ptr<WorkRequest> workRequest;
|
||||
};
|
||||
|
||||
|
||||
@@ -267,16 +267,17 @@ TileData::State Source::addTile(const TileID& tileID, const StyleUpdateParameter
|
||||
|
||||
// If we don't find working tile data, we're just going to load it.
|
||||
if (type == SourceType::Raster) {
|
||||
auto tileData = std::make_shared<RasterTileData>(normalizedID,
|
||||
newTile->data = std::make_shared<RasterTileData>(normalizedID,
|
||||
parameters.pixelRatio,
|
||||
info->tiles.at(0),
|
||||
parameters.texturePool,
|
||||
parameters.worker);
|
||||
tileData->request(util::templateTileURL(info->tiles.at(0), normalizedID, parameters.pixelRatio), callback);
|
||||
newTile->data = tileData;
|
||||
parameters.worker,
|
||||
callback);
|
||||
} else {
|
||||
std::unique_ptr<GeometryTileMonitor> monitor;
|
||||
|
||||
if (type == SourceType::Vector) {
|
||||
monitor = std::make_unique<VectorTileMonitor>(normalizedID, info->tiles.at(0));
|
||||
monitor = std::make_unique<VectorTileMonitor>(normalizedID, parameters.pixelRatio, info->tiles.at(0));
|
||||
} else if (type == SourceType::Annotations) {
|
||||
monitor = std::make_unique<AnnotationTileMonitor>(normalizedID, parameters.data);
|
||||
} else if (type == SourceType::GeoJSON) {
|
||||
|
||||
@@ -178,13 +178,27 @@ util::ptr<const GeometryTileFeature> VectorTileLayer::getFeature(std::size_t i)
|
||||
return std::make_shared<VectorTileFeature>(features.at(i), *this);
|
||||
}
|
||||
|
||||
VectorTileMonitor::VectorTileMonitor(const TileID& tileID_, const std::string& urlTemplate_)
|
||||
: tileID(tileID_), urlTemplate(urlTemplate_) {
|
||||
VectorTileMonitor::VectorTileMonitor(const TileID& tileID_, float pixelRatio_, const std::string& urlTemplate_)
|
||||
: tileID(tileID_),
|
||||
pixelRatio(pixelRatio_),
|
||||
urlTemplate(urlTemplate_) {
|
||||
}
|
||||
|
||||
std::unique_ptr<FileRequest> VectorTileMonitor::monitorTile(const GeometryTileMonitor::Callback& callback) {
|
||||
const std::string url = util::templateTileURL(urlTemplate, tileID);
|
||||
return util::ThreadContext::getFileSource()->request({ Resource::Kind::Tile, url }, [callback, this](Response res) {
|
||||
Resource resource {
|
||||
Resource::Kind::Tile,
|
||||
util::templateTileURL(urlTemplate, tileID, pixelRatio)
|
||||
};
|
||||
|
||||
resource.tileData = Resource::TileData {
|
||||
urlTemplate,
|
||||
pixelRatio,
|
||||
tileID.x,
|
||||
tileID.y,
|
||||
tileID.z
|
||||
};
|
||||
|
||||
return util::ThreadContext::getFileSource()->request(resource, [callback, this](Response res) {
|
||||
if (res.notModified) {
|
||||
// We got the same data again. Abort early.
|
||||
return;
|
||||
|
||||
@@ -61,12 +61,13 @@ class TileID;
|
||||
|
||||
class VectorTileMonitor : public GeometryTileMonitor {
|
||||
public:
|
||||
VectorTileMonitor(const TileID&, const std::string& urlTemplate);
|
||||
VectorTileMonitor(const TileID&, float pixelRatio, const std::string& urlTemplate);
|
||||
|
||||
std::unique_ptr<FileRequest> monitorTile(const GeometryTileMonitor::Callback&) override;
|
||||
|
||||
private:
|
||||
TileID tileID;
|
||||
float pixelRatio;
|
||||
std::string urlTemplate;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user