diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2015-07-02 18:39:06 +0200 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2015-07-08 19:46:01 +0200 |
commit | b2a3314192a8a1dc06e0677e1430219dd8655cf0 (patch) | |
tree | ce6c46a70e48ec19db199b4031f9293faec8c410 | |
parent | f9601ae68595e5bd2d7951d8ecf8e11117b2162c (diff) | |
download | qtlocation-mapboxgl-b2a3314192a8a1dc06e0677e1430219dd8655cf0.tar.gz |
replace Style object immediately
this makes sure that adding custom sprite imagery will add them to the new Style object rather than
the old one in case a user adds new custom sprites immediately after changing a stylesheet
-rw-r--r-- | src/mbgl/map/map_context.cpp | 12 | ||||
-rw-r--r-- | src/mbgl/style/style.cpp | 8 | ||||
-rw-r--r-- | src/mbgl/style/style.hpp | 6 | ||||
-rw-r--r-- | test/style/resource_loading.cpp | 3 |
4 files changed, 18 insertions, 11 deletions
diff --git a/src/mbgl/map/map_context.cpp b/src/mbgl/map/map_context.cpp index a27d7301a5..5b1825bff2 100644 --- a/src/mbgl/map/map_context.cpp +++ b/src/mbgl/map/map_context.cpp @@ -99,6 +99,8 @@ void MapContext::setStyleURL(const std::string& url) { styleURL = url; styleJSON.clear(); + style = std::make_unique<Style>(data, asyncUpdate->get()->loop); + const size_t pos = styleURL.rfind('/'); std::string base = ""; if (pos != std::string::npos) { @@ -120,14 +122,15 @@ void MapContext::setStyleJSON(const std::string& json, const std::string& base) styleURL.clear(); styleJSON = json; + style = std::make_unique<Style>(data, asyncUpdate->get()->loop); + loadStyleJSON(json, base); } void MapContext::loadStyleJSON(const std::string& json, const std::string& base) { assert(util::ThreadContext::currentlyOn(util::ThreadType::Map)); - style.reset(); - style = std::make_unique<Style>(json, base, data, asyncUpdate->get()->loop); + style->setJSON(json, base); style->cascade(data.getClasses()); style->setDefaultTransitionDuration(data.getDefaultTransitionDuration()); style->setObserver(this); @@ -376,7 +379,10 @@ void MapContext::onLowMemory() { } void MapContext::setSprite(const std::string& name, std::shared_ptr<const SpriteImage> sprite) { - if (!style) return; + if (!style) { + Log::Info(Event::Sprite, "Ignoring sprite without stylesheet"); + return; + } style->spriteStore->setSprite(name, sprite); diff --git a/src/mbgl/style/style.cpp b/src/mbgl/style/style.cpp index 9b893822b8..7f8f821d1c 100644 --- a/src/mbgl/style/style.cpp +++ b/src/mbgl/style/style.cpp @@ -22,8 +22,7 @@ namespace mbgl { -Style::Style(const std::string& json, const std::string&, MapData& data_, - uv_loop_t* loop) +Style::Style(MapData& data_, uv_loop_t* loop) : data(data_), glyphStore(std::make_unique<GlyphStore>(loop)), glyphAtlas(std::make_unique<GlyphAtlas>(1024, 1024)), @@ -32,7 +31,10 @@ Style::Style(const std::string& json, const std::string&, MapData& data_, lineAtlas(std::make_unique<LineAtlas>(512, 512)), mtx(std::make_unique<uv::rwlock>()), workers(4) { + glyphStore->setObserver(this); +} +void Style::setJSON(const std::string& json, const std::string&) { rapidjson::Document doc; doc.Parse<0>((const char *const)json.c_str()); if (doc.HasParseError()) { @@ -55,8 +57,6 @@ Style::Style(const std::string& json, const std::string&, MapData& data_, source->setObserver(this); source->load(); } - - glyphStore->setObserver(this); } Style::~Style() { diff --git a/src/mbgl/style/style.hpp b/src/mbgl/style/style.hpp index 0490e93f32..e7611ced30 100644 --- a/src/mbgl/style/style.hpp +++ b/src/mbgl/style/style.hpp @@ -32,9 +32,7 @@ class Style : public GlyphStore::Observer, public Sprite::Observer, public util::noncopyable { public: - Style(const std::string& data, - const std::string& base, - MapData&, + Style(MapData&, uv_loop_t*); ~Style(); @@ -46,6 +44,8 @@ public: virtual void onResourceLoadingFailed(std::exception_ptr error) = 0; }; + void setJSON(const std::string& data, const std::string& base); + void setObserver(Observer*); bool isLoaded() const; diff --git a/test/style/resource_loading.cpp b/test/style/resource_loading.cpp index d14be28789..75adfe72b1 100644 --- a/test/style/resource_loading.cpp +++ b/test/style/resource_loading.cpp @@ -32,7 +32,8 @@ public: transform_.setLatLngZoom({0, 0}, 16); const std::string style = util::read_file("test/fixtures/resources/style.json"); - style_ = std::make_unique<Style>(style, "", data_, util::RunLoop::getLoop()); + style_ = std::make_unique<Style>(data_, util::RunLoop::getLoop()); + style_->setJSON(style, ""); style_->setObserver(this); } |