diff options
author | John Firebaugh <john.firebaugh@gmail.com> | 2016-07-21 16:37:18 -0700 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2016-08-23 09:55:32 -0700 |
commit | 86cccc4d24804d40ea9d15d47ee1edb975bbf2e3 (patch) | |
tree | 7613b3a6546c4fb48c3f73069bbdde47e6a03e4d /src | |
parent | 5511e9a4e85c8eb8a67a8cfc56a2b1f665a8940d (diff) | |
download | qtlocation-mapboxgl-86cccc4d24804d40ea9d15d47ee1edb975bbf2e3.tar.gz |
[core] Don't allow style mutations to be overwritten by revalidation
* Once we get a fresh style, stop revalidating.
* If the style is mutated, stop revalidating and preserve the existing mutations.
Diffstat (limited to 'src')
-rw-r--r-- | src/mbgl/map/map.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp index 15f7779f83..2e7dc06e8b 100644 --- a/src/mbgl/map/map.cpp +++ b/src/mbgl/map/map.cpp @@ -67,6 +67,7 @@ public: std::string styleURL; std::string styleJSON; + bool styleMutated = false; std::unique_ptr<AsyncRequest> styleRequest; @@ -293,10 +294,21 @@ void Map::setStyleURL(const std::string& url) { impl->styleRequest = nullptr; impl->styleURL = url; impl->styleJSON.clear(); + impl->styleMutated = false; impl->style = std::make_unique<Style>(impl->fileSource, impl->pixelRatio); impl->styleRequest = impl->fileSource.request(Resource::style(impl->styleURL), [this](Response res) { + // Once we get a fresh style, or the style is mutated, stop revalidating. + if (res.isFresh() || impl->styleMutated) { + impl->styleRequest.reset(); + } + + // Don't allow a loaded, mutated style to be overwritten with a new version. + if (impl->styleMutated && impl->style->loaded) { + return; + } + if (res.error) { if (res.error->reason == Response::Error::Reason::NotFound && util::mapbox::isMapboxURL(impl->styleURL)) { @@ -323,6 +335,8 @@ void Map::setStyleJSON(const std::string& json) { impl->styleURL.clear(); impl->styleJSON.clear(); + impl->styleMutated = false; + impl->style = std::make_unique<Style>(impl->fileSource, impl->pixelRatio); impl->loadStyleJSON(json); @@ -746,22 +760,27 @@ AnnotationIDs Map::queryPointAnnotations(const ScreenBox& box) { #pragma mark - Style API style::Source* Map::getSource(const std::string& sourceID) { + impl->styleMutated = true; return impl->style ? impl->style->getSource(sourceID) : nullptr; } void Map::addSource(std::unique_ptr<style::Source> source) { + impl->styleMutated = true; impl->style->addSource(std::move(source)); } void Map::removeSource(const std::string& sourceID) { + impl->styleMutated = true; impl->style->removeSource(sourceID); } style::Layer* Map::getLayer(const std::string& layerID) { + impl->styleMutated = true; return impl->style ? impl->style->getLayer(layerID) : nullptr; } void Map::addLayer(std::unique_ptr<Layer> layer, const optional<std::string>& before) { + impl->styleMutated = true; impl->view.activate(); impl->style->addLayer(std::move(layer), before); @@ -772,6 +791,7 @@ void Map::addLayer(std::unique_ptr<Layer> layer, const optional<std::string>& be } void Map::removeLayer(const std::string& id) { + impl->styleMutated = true; impl->view.activate(); impl->style->removeLayer(id); |