summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2016-01-07 10:22:20 +0100
committerKonstantin Käfer <mail@kkaefer.com>2016-01-15 12:48:23 +0100
commit8a964fb9313e57b71c64b8c0739ec84f163dc537 (patch)
treee0415a40fd010eb5a8245b7c3e818a4678599641 /src
parent21e4029acf757898da8695474f94642f9858acd8 (diff)
downloadqtlocation-mapboxgl-8a964fb9313e57b71c64b8c0739ec84f163dc537.tar.gz
[core] use stale and refreshing TileJSON/GeoJSON data
We're now supporting using stale TileJSON and GeoJSON data. When we receive a new answer with an updated TileJSON file, we're replacing the Source's metadata with the new one and trigger updates to make sure we're loading the correct tiles. Similarly, GeoJSON data will be reparsed.
Diffstat (limited to 'src')
-rw-r--r--src/mbgl/map/source.cpp39
1 files changed, 34 insertions, 5 deletions
diff --git a/src/mbgl/map/source.cpp b/src/mbgl/map/source.cpp
index ed57ddce0b..4432b3a490 100644
--- a/src/mbgl/map/source.cpp
+++ b/src/mbgl/map/source.cpp
@@ -90,14 +90,13 @@ void Source::load() {
// URL may either be a TileJSON file, or a GeoJSON file.
FileSource* fs = util::ThreadContext::getFileSource();
req = fs->request({ Resource::Kind::Source, url }, [this](Response res) {
- if (res.stale) {
- // Only handle fresh responses.
+ if (res.error) {
+ observer->onSourceError(*this, std::make_exception_ptr(std::runtime_error(res.error->message)));
return;
}
- req = nullptr;
- if (res.error) {
- observer->onSourceError(*this, std::make_exception_ptr(std::runtime_error(res.error->message)));
+ if (res.notModified) {
+ // We got the same data back as last time. Abort early.
return;
}
@@ -111,6 +110,7 @@ void Source::load() {
return;
}
+ bool reloadTiles = false;
if (type == SourceType::Vector || type == SourceType::Raster) {
// Create a new copy of the SourceInfo object that holds the base values we've parsed
// from the stylesheet. Then merge in the values parsed from the TileJSON we retrieved
@@ -124,10 +124,39 @@ void Source::load() {
std::transform(newInfo->tiles.begin(), newInfo->tiles.end(), newInfo->tiles.begin(),
util::mapbox::normalizeRasterTileURL);
}
+
+ // Check whether previous information specifies different tile
+ if (info && info->tiles != newInfo->tiles) {
+ reloadTiles = true;
+
+ // 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
+ }
+
info = std::move(newInfo);
} else if (type == SourceType::GeoJSON) {
info = std::make_unique<SourceInfo>();
geojsonvt = StyleParser::parseGeoJSON(d);
+ reloadTiles = true;
+ }
+
+ if (reloadTiles) {
+ // Tile information changed because we got new GeoJSON data, or a new tile URL.
+ tilePtrs.clear();
+ tileDataMap.clear();
+ tiles.clear();
+ cache.clear();
}
loaded = true;