From 6b729ccb4680e41fd6346aeb5a5e55027ca49052 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20K=C3=A4fer?= Date: Thu, 19 May 2016 17:19:45 +0200 Subject: [core] store Resource instead of dependents to build URL --- src/mbgl/style/source.cpp | 19 +++++++++++++------ src/mbgl/tile/raster_tile_source.cpp | 12 +++--------- src/mbgl/tile/raster_tile_source.hpp | 10 +++------- src/mbgl/tile/vector_tile_source.cpp | 12 +++--------- src/mbgl/tile/vector_tile_source.hpp | 13 +++++-------- 5 files changed, 27 insertions(+), 39 deletions(-) (limited to 'src/mbgl') 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 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 monitor; - monitor = std::make_unique(overscaledTileID, parameters.pixelRatio, tileset->tiles.at(0), parameters.fileSource); - - data = std::make_unique(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(resource, parameters.fileSource); + data = + std::make_unique(overscaledTileID, std::move(monitor), + parameters.texturePool, parameters.worker, callback); } else { std::unique_ptr monitor; if (type == SourceType::Vector) { - monitor = std::make_unique(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(resource, parameters.fileSource); } else if (type == SourceType::Annotations) { monitor = std::make_unique(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 -RasterTileSource::monitorTile(const Callback& callback) { - const Resource resource = Resource::tile(urlTemplate, pixelRatio, tileID.canonical.x, - tileID.canonical.y, tileID.canonical.z); +std::unique_ptr 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 #include +#include 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 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 -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 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 #include +#include 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 monitorTile(const GeometryTileSource::Callback&) override; + std::unique_ptr monitorTile(const Callback&) override; private: - OverscaledTileID tileID; - float pixelRatio; - std::string urlTemplate; + const Resource resource; FileSource& fileSource; }; -- cgit v1.2.1