diff options
author | John Firebaugh <john.firebaugh@gmail.com> | 2016-06-13 13:35:24 -0700 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2016-06-14 11:25:45 -0700 |
commit | 2a991c6846bc6742abd618ec750bd2f01a13b75e (patch) | |
tree | 0592f4b3ebc63aeed0aeefe5c576ae9a67bfccdc /src/mbgl/style/tile_source.cpp | |
parent | e6ba10ceed93c3b565a80591d8def5f0e7d72aac (diff) | |
download | qtlocation-mapboxgl-2a991c6846bc6742abd618ec750bd2f01a13b75e.tar.gz |
[core] Virtualize Source::load
Diffstat (limited to 'src/mbgl/style/tile_source.cpp')
-rw-r--r-- | src/mbgl/style/tile_source.cpp | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/src/mbgl/style/tile_source.cpp b/src/mbgl/style/tile_source.cpp index 22739035a9..90f4b54d96 100644 --- a/src/mbgl/style/tile_source.cpp +++ b/src/mbgl/style/tile_source.cpp @@ -1,4 +1,7 @@ #include <mbgl/style/tile_source.hpp> +#include <mbgl/style/source_observer.hpp> +#include <mbgl/style/parser.hpp> +#include <mbgl/storage/file_source.hpp> namespace mbgl { namespace style { @@ -11,5 +14,64 @@ TileSource::TileSource(SourceType type_, : Source(type_, std::move(id_), std::move(url_), tileSize_, std::move(tileset_)) { } +void TileSource::load(FileSource& fileSource) { + if (url.empty()) { + // If the URL is empty, the TileJSON was specified inline in the stylesheet. + loaded = true; + return; + } + + if (req) { + return; + } + + // URL may either be a TileJSON file, or a GeoJSON file. + req = fileSource.request(Resource::source(url), [this](Response res) { + if (res.error) { + observer->onSourceError(*this, std::make_exception_ptr(std::runtime_error(res.error->message))); + } else if (res.notModified) { + return; + } else if (res.noContent) { + observer->onSourceError(*this, std::make_exception_ptr(std::runtime_error("unexpectedly empty TileJSON"))); + } else { + std::unique_ptr<Tileset> newTileset; + + // Create a new copy of the Tileset object that holds the base values we've parsed + // from the stylesheet. Then merge in the values parsed from the TileJSON we retrieved + // via the URL. + try { + newTileset = style::parseTileJSON(*res.data, url, type, tileSize); + } catch (...) { + observer->onSourceError(*this, std::current_exception()); + return; + } + + // Check whether previous information specifies different tile + if (tileset && tileset->tiles != newTileset->tiles) { + // Tile URLs changed: force tiles to be reloaded. + invalidateTiles(); + + // Tile size changed: We need to recalculate the tiles we need to load because we + // might have to load tiles for a different zoom level + // This is done automatically when we trigger the onSourceLoaded observer below. + + // Min/Max zoom changed: We need to recalculate what tiles to load, if we have tiles + // loaded that are outside the new zoom range + // This is done automatically when we trigger the onSourceLoaded observer below. + + // Attribution changed: We need to notify the embedding application that this + // changed. See https://github.com/mapbox/mapbox-gl-native/issues/2723 + // This is not yet implemented. + + // Center/bounds changed: We're not using these values currently + } + + tileset = std::move(newTileset); + loaded = true; + observer->onSourceLoaded(*this); + } + }); +} + } // namespace style } // namespace mbgl |