diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2016-05-20 16:12:22 +0200 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2016-06-10 12:42:14 +0200 |
commit | 2b6d0751cf3495c9246af27fdff6f565186bb2f8 (patch) | |
tree | 8c21aea06e2bd19c37b01156ea882038069b85dc /src/mbgl/style/source.cpp | |
parent | 6b729ccb4680e41fd6346aeb5a5e55027ca49052 (diff) | |
download | qtlocation-mapboxgl-2b6d0751cf3495c9246af27fdff6f565186bb2f8.tar.gz |
[core] restructure TileSource construction and callbacks
Diffstat (limited to 'src/mbgl/style/source.cpp')
-rw-r--r-- | src/mbgl/style/source.cpp | 46 |
1 files changed, 24 insertions, 22 deletions
diff --git a/src/mbgl/style/source.cpp b/src/mbgl/style/source.cpp index 1b5ae05f50..51e6334440 100644 --- a/src/mbgl/style/source.cpp +++ b/src/mbgl/style/source.cpp @@ -25,7 +25,7 @@ #include <mbgl/tile/vector_tile_source.hpp> #include <mbgl/tile/geojson_tile_source.hpp> #include <mbgl/tile/annotation_tile_source.hpp> -#include <mbgl/tile/raster_tile_source.hpp> +#include <mbgl/tile/image_tile_source.hpp> #include <mbgl/tile/geometry_tile_data.hpp> #include <mbgl/tile/raster_tile_data.hpp> @@ -193,8 +193,7 @@ const std::map<UnwrappedTileID, Tile>& Source::getTiles() const { std::unique_ptr<TileData> Source::createTile(const OverscaledTileID& overscaledTileID, const UpdateParameters& parameters) { - std::unique_ptr<TileData> data = cache.get(overscaledTileID); - if (data) { + if (auto data = cache.get(overscaledTileID)) { return data; } @@ -207,33 +206,40 @@ std::unique_ptr<TileData> Source::createTile(const OverscaledTileID& overscaledT 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); + auto data = std::make_unique<RasterTileData>(overscaledTileID, parameters.texturePool, + parameters.worker, callback); + data->setTileSource( + std::make_unique<ImageTileSource>(*data, resource, parameters.fileSource)); + + // Need a std::move here to create a std::unique_ptr<TileData> from + // std::unique_ptr<GeometryTileData>. + return std::move(data); } else { - std::unique_ptr<GeometryTileSource> monitor; - + auto data = std::make_unique<GeometryTileData>(overscaledTileID, id, parameters.style, + parameters.mode, callback); if (type == SourceType::Vector) { 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); + data->setTileSource( + std::make_unique<VectorTileSource>(*data, resource, parameters.fileSource)); } else if (type == SourceType::Annotations) { - monitor = std::make_unique<AnnotationTileSource>(overscaledTileID, parameters.annotationManager); + data->setTileSource(std::make_unique<AnnotationTileSource>( + *data, overscaledTileID, parameters.annotationManager)); } else if (type == SourceType::GeoJSON) { - monitor = std::make_unique<GeoJSONTileSource>(geojsonvt.get(), overscaledTileID); + data->setTileSource( + std::make_unique<GeoJSONTileSource>(*data, geojsonvt.get(), overscaledTileID)); } else { - Log::Warning(Event::Style, "Source type '%s' is not implemented", SourceTypeClass(type).c_str()); + Log::Warning(Event::Style, "Source type '%s' is not implemented", + SourceTypeClass(type).c_str()); return nullptr; } - data = std::make_unique<GeometryTileData>(overscaledTileID, std::move(monitor), id, - parameters.style, parameters.mode, callback); + // Need a std::move here to create a std::unique_ptr<TileData> from + // std::unique_ptr<GeometryTileData>. + return std::move(data); } - - return data; } TileData* Source::getTileData(const OverscaledTileID& overscaledTileID) const { @@ -322,13 +328,9 @@ bool Source::update(const UpdateParameters& parameters) { } for (auto& pair : tileDataMap) { - const auto& dataTileID = pair.first; auto tileData = pair.second.get(); if (parameters.shouldReparsePartialTiles && tileData->isIncomplete()) { - auto callback = std::bind(&Source::tileLoadingCallback, this, dataTileID, - std::placeholders::_1, false); - - if (!tileData->parsePending(callback)) { + if (!tileData->parsePending()) { allTilesUpdated = false; } } else { |