diff options
author | John Firebaugh <john.firebaugh@gmail.com> | 2016-01-22 19:18:25 -0800 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2016-01-29 14:50:15 -0800 |
commit | 849e8b32b4b2febc63ad3df8539b483ccc67ac63 (patch) | |
tree | 46909ab1caca2baab375ad2ac4bbec6faeda04dd | |
parent | 4dc7ec02020e0c9856eb60ff06b2a70372e44324 (diff) | |
download | qtlocation-mapboxgl-849e8b32b4b2febc63ad3df8539b483ccc67ac63.tar.gz |
[core] Ensure that FileSource has access to tile URL, pixelRatio, x, y, z
-rw-r--r-- | include/mbgl/storage/resource.hpp | 12 | ||||
-rw-r--r-- | src/mbgl/map/raster_tile_data.cpp | 32 | ||||
-rw-r--r-- | src/mbgl/map/raster_tile_data.hpp | 15 | ||||
-rw-r--r-- | src/mbgl/map/source.cpp | 11 | ||||
-rw-r--r-- | src/mbgl/map/vector_tile.cpp | 22 | ||||
-rw-r--r-- | src/mbgl/map/vector_tile.hpp | 3 |
6 files changed, 66 insertions, 29 deletions
diff --git a/include/mbgl/storage/resource.hpp b/include/mbgl/storage/resource.hpp index 8a61702183..532feff14a 100644 --- a/include/mbgl/storage/resource.hpp +++ b/include/mbgl/storage/resource.hpp @@ -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 diff --git a/src/mbgl/map/raster_tile_data.cpp b/src/mbgl/map/raster_tile_data.cpp index 92ffb451b0..fa0bd298b1 100644 --- a/src/mbgl/map/raster_tile_data.cpp +++ b/src/mbgl/map/raster_tile_data.cpp @@ -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_) { -} + state = State::loading; -RasterTileData::~RasterTileData() { - cancel(); -} + Resource resource { + Resource::Kind::Tile, + util::templateTileURL(urlTemplate, id, pixelRatio) + }; -void RasterTileData::request(const std::string& url, - const RasterTileData::Callback& callback) { - state = State::loading; + resource.tileData = Resource::TileData { + urlTemplate, + pixelRatio, + id.x, + id.y, + id.z + }; - FileSource* fs = util::ThreadContext::getFileSource(); - req = fs->request({ Resource::Kind::Tile, url }, [url, callback, this](Response res) { + 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(); } diff --git a/src/mbgl/map/raster_tile_data.hpp b/src/mbgl/map/raster_tile_data.hpp index e8efde48e4..e68fbc94c5 100644 --- a/src/mbgl/map/raster_tile_data.hpp +++ b/src/mbgl/map/raster_tile_data.hpp @@ -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; }; diff --git a/src/mbgl/map/source.cpp b/src/mbgl/map/source.cpp index 8a89fecb87..fbe276f324 100644 --- a/src/mbgl/map/source.cpp +++ b/src/mbgl/map/source.cpp @@ -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) { diff --git a/src/mbgl/map/vector_tile.cpp b/src/mbgl/map/vector_tile.cpp index 8faaae395e..cfe78d228d 100644 --- a/src/mbgl/map/vector_tile.cpp +++ b/src/mbgl/map/vector_tile.cpp @@ -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; diff --git a/src/mbgl/map/vector_tile.hpp b/src/mbgl/map/vector_tile.hpp index 1557db784f..a53c0bc44f 100644 --- a/src/mbgl/map/vector_tile.hpp +++ b/src/mbgl/map/vector_tile.hpp @@ -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; }; |