diff options
-rw-r--r-- | src/mbgl/style/source.cpp | 19 | ||||
-rw-r--r-- | src/mbgl/tile/raster_tile_source.cpp | 12 | ||||
-rw-r--r-- | src/mbgl/tile/raster_tile_source.hpp | 10 | ||||
-rw-r--r-- | src/mbgl/tile/vector_tile_source.cpp | 12 | ||||
-rw-r--r-- | src/mbgl/tile/vector_tile_source.hpp | 13 |
5 files changed, 27 insertions, 39 deletions
diff --git a/src/mbgl/style/source.cpp b/src/mbgl/style/source.cpp index 5fec392ef8..1b5ae05f50 100644 --- a/src/mbgl/style/source.cpp +++ b/src/mbgl/style/source.cpp @@ -203,16 +203,23 @@ std::unique_ptr<TileData> Source::createTile(const OverscaledTileID& overscaledT // If we don't find working tile data, we're just going to load it. if (type == SourceType::Raster) { - std::unique_ptr<RasterTileSource> monitor; - monitor = std::make_unique<RasterTileSource>(overscaledTileID, parameters.pixelRatio, tileset->tiles.at(0), parameters.fileSource); - - data = std::make_unique<RasterTileData>(overscaledTileID, std::move(monitor), - parameters.texturePool, parameters.worker, callback); + assert(!tileset->tiles.empty()); + const auto resource = Resource::tile( + tileset->tiles.at(0), parameters.pixelRatio, overscaledTileID.canonical.x, + overscaledTileID.canonical.y, overscaledTileID.canonical.z); + auto monitor = std::make_unique<RasterTileSource>(resource, parameters.fileSource); + data = + std::make_unique<RasterTileData>(overscaledTileID, std::move(monitor), + parameters.texturePool, parameters.worker, callback); } else { std::unique_ptr<GeometryTileSource> monitor; if (type == SourceType::Vector) { - monitor = std::make_unique<VectorTileSource>(overscaledTileID, parameters.pixelRatio, tileset->tiles.at(0), parameters.fileSource); + assert(!tileset->tiles.empty()); + const auto resource = Resource::tile( + tileset->tiles.at(0), parameters.pixelRatio, overscaledTileID.canonical.x, + overscaledTileID.canonical.y, overscaledTileID.canonical.z); + monitor = std::make_unique<VectorTileSource>(resource, parameters.fileSource); } else if (type == SourceType::Annotations) { monitor = std::make_unique<AnnotationTileSource>(overscaledTileID, parameters.annotationManager); } else if (type == SourceType::GeoJSON) { diff --git a/src/mbgl/tile/raster_tile_source.cpp b/src/mbgl/tile/raster_tile_source.cpp index 7220ce214e..8d07bad07a 100644 --- a/src/mbgl/tile/raster_tile_source.cpp +++ b/src/mbgl/tile/raster_tile_source.cpp @@ -3,17 +3,11 @@ namespace mbgl { -RasterTileSource::RasterTileSource(const OverscaledTileID& tileID_, - float pixelRatio_, - const std::string& urlTemplate_, - FileSource& fileSource_) - : tileID(tileID_), pixelRatio(pixelRatio_), urlTemplate(urlTemplate_), fileSource(fileSource_) { +RasterTileSource::RasterTileSource(const Resource& resource_, FileSource& fileSource_) + : resource(resource_), fileSource(fileSource_) { } -std::unique_ptr<AsyncRequest> -RasterTileSource::monitorTile(const Callback& callback) { - const Resource resource = Resource::tile(urlTemplate, pixelRatio, tileID.canonical.x, - tileID.canonical.y, tileID.canonical.z); +std::unique_ptr<AsyncRequest> RasterTileSource::monitorTile(const Callback& callback) { return fileSource.request(resource, [callback, this](Response res) { if (res.error) { callback(std::make_exception_ptr(std::runtime_error(res.error->message)), nullptr, diff --git a/src/mbgl/tile/raster_tile_source.hpp b/src/mbgl/tile/raster_tile_source.hpp index fc7a18d1a7..800f31fefb 100644 --- a/src/mbgl/tile/raster_tile_source.hpp +++ b/src/mbgl/tile/raster_tile_source.hpp @@ -2,6 +2,7 @@ #include <mbgl/tile/tile_source.hpp> #include <mbgl/tile/tile_id.hpp> +#include <mbgl/storage/resource.hpp> namespace mbgl { @@ -9,10 +10,7 @@ class FileSource; class RasterTileSource : public TileSource { public: - RasterTileSource(const OverscaledTileID&, - float pixelRatio, - const std::string& urlTemplate, - FileSource&); + RasterTileSource(const Resource&, FileSource&); virtual ~RasterTileSource() = default; using Callback = std::function<void(std::exception_ptr, @@ -31,9 +29,7 @@ public: std::unique_ptr<AsyncRequest> monitorTile(const Callback&); private: - OverscaledTileID tileID; - float pixelRatio; - std::string urlTemplate; + const Resource resource; FileSource& fileSource; }; diff --git a/src/mbgl/tile/vector_tile_source.cpp b/src/mbgl/tile/vector_tile_source.cpp index 9563fb7bee..cfff47f598 100644 --- a/src/mbgl/tile/vector_tile_source.cpp +++ b/src/mbgl/tile/vector_tile_source.cpp @@ -4,17 +4,11 @@ namespace mbgl { -VectorTileSource::VectorTileSource(const OverscaledTileID& tileID_, - float pixelRatio_, - const std::string& urlTemplate_, - FileSource& fileSource_) - : tileID(tileID_), pixelRatio(pixelRatio_), urlTemplate(urlTemplate_), fileSource(fileSource_) { +VectorTileSource::VectorTileSource(const Resource& resource_, FileSource& fileSource_) + : resource(resource_), fileSource(fileSource_) { } -std::unique_ptr<AsyncRequest> -VectorTileSource::monitorTile(const GeometryTileSource::Callback& callback) { - const Resource resource = Resource::tile(urlTemplate, pixelRatio, tileID.canonical.x, - tileID.canonical.y, tileID.canonical.z); +std::unique_ptr<AsyncRequest> VectorTileSource::monitorTile(const Callback& callback) { return fileSource.request(resource, [callback, this](Response res) { if (res.error) { callback(std::make_exception_ptr(std::runtime_error(res.error->message)), nullptr, diff --git a/src/mbgl/tile/vector_tile_source.hpp b/src/mbgl/tile/vector_tile_source.hpp index 03b6be6c79..32f45a1a23 100644 --- a/src/mbgl/tile/vector_tile_source.hpp +++ b/src/mbgl/tile/vector_tile_source.hpp @@ -2,6 +2,7 @@ #include <mbgl/tile/tile_source.hpp> #include <mbgl/tile/tile_id.hpp> +#include <mbgl/storage/resource.hpp> namespace mbgl { @@ -9,17 +10,13 @@ class FileSource; class VectorTileSource : public GeometryTileSource { public: - VectorTileSource(const OverscaledTileID&, - float pixelRatio, - const std::string& urlTemplate, - FileSource&); + VectorTileSource(const Resource&, FileSource&); + virtual ~VectorTileSource() = default; - std::unique_ptr<AsyncRequest> monitorTile(const GeometryTileSource::Callback&) override; + std::unique_ptr<AsyncRequest> monitorTile(const Callback&) override; private: - OverscaledTileID tileID; - float pixelRatio; - std::string urlTemplate; + const Resource resource; FileSource& fileSource; }; |