diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2016-01-04 12:30:13 +0100 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2016-01-15 11:59:26 +0100 |
commit | 21e4029acf757898da8695474f94642f9858acd8 (patch) | |
tree | 567a10b18b4f1b573de5ae151018f6518244138a /src | |
parent | 957415823a003111f6efecd1a1552a30f999235a (diff) | |
download | qtlocation-mapboxgl-21e4029acf757898da8695474f94642f9858acd8.tar.gz |
[core] use stale styles
This adds support for using cached styles that are stale. They're treated like changing styles; when the refreshed style changed compared to the one we've already had, we're swapping out the entire style, which might cause a slight flicker.
Diffstat (limited to 'src')
-rw-r--r-- | src/mbgl/map/map_context.cpp | 15 | ||||
-rw-r--r-- | src/mbgl/style/style.cpp | 3 |
2 files changed, 9 insertions, 9 deletions
diff --git a/src/mbgl/map/map_context.cpp b/src/mbgl/map/map_context.cpp index 6f12e968bd..eb17e20aea 100644 --- a/src/mbgl/map/map_context.cpp +++ b/src/mbgl/map/map_context.cpp @@ -105,12 +105,6 @@ void MapContext::setStyleURL(const std::string& url) { FileSource* fs = util::ThreadContext::getFileSource(); styleRequest = fs->request({ Resource::Kind::Style, styleURL }, [this, base](Response res) { - if (res.stale) { - // Only handle fresh responses. - return; - } - styleRequest = nullptr; - if (res.error) { if (res.error->reason == Response::Error::Reason::NotFound && util::mapbox::isMapboxURL(styleURL)) { @@ -120,9 +114,11 @@ void MapContext::setStyleURL(const std::string& url) { data.loading = false; } } else { - loadStyleJSON(*res.data, base); + // We got a new stylesheet; only update when it's different from the previous one. + if (styleJSON != *res.data) { + loadStyleJSON(*res.data, base); + } } - }); } @@ -132,7 +128,7 @@ void MapContext::setStyleJSON(const std::string& json, const std::string& base) } styleURL.clear(); - styleJSON = json; + styleJSON.clear(); style = std::make_unique<Style>(data); @@ -144,6 +140,7 @@ void MapContext::loadStyleJSON(const std::string& json, const std::string& base) style->setJSON(json, base); style->setObserver(this); + styleJSON = json; // force style cascade, causing all pending transitions to complete. style->cascade(); diff --git a/src/mbgl/style/style.cpp b/src/mbgl/style/style.cpp index fbca01311b..f64bdfc921 100644 --- a/src/mbgl/style/style.cpp +++ b/src/mbgl/style/style.cpp @@ -43,6 +43,9 @@ Style::Style(MapData& data_) } void Style::setJSON(const std::string& json, const std::string&) { + sources.clear(); + layers.clear(); + rapidjson::GenericDocument<rapidjson::UTF8<>, rapidjson::CrtAllocator> doc; doc.Parse<0>((const char *const)json.c_str()); if (doc.HasParseError()) { |