Introduce the ResourceLoader
ResourceLoader will handle all the tile changes and notifications through the Source object owned by the Style. This object lives entirely on the Map thread and should be only accessed by it. The observer will receive notifications every time the tile data changes and this will probably trigger a new rendering operation. This first patch will delegate Source loading to the ResourceLoader.
This commit is contained in:
@@ -62,6 +62,7 @@ MapContext::~MapContext() {
|
||||
|
||||
// Explicit resets currently necessary because these abandon resources that need to be
|
||||
// cleaned up by env.performCleanup();
|
||||
resourceLoader.reset();
|
||||
style.reset();
|
||||
sprite.reset();
|
||||
painter.reset();
|
||||
@@ -141,6 +142,7 @@ util::ptr<Sprite> MapContext::getSprite() {
|
||||
void MapContext::loadStyleJSON(const std::string& json, const std::string& base) {
|
||||
assert(Environment::currentlyOn(ThreadType::Map));
|
||||
|
||||
resourceLoader.reset();
|
||||
sprite.reset();
|
||||
style.reset();
|
||||
|
||||
@@ -153,12 +155,10 @@ void MapContext::loadStyleJSON(const std::string& json, const std::string& base)
|
||||
const std::string glyphURL = util::mapbox::normalizeGlyphsURL(style->glyph_url, data.getAccessToken());
|
||||
glyphStore->setURL(glyphURL);
|
||||
|
||||
for (const auto& source : style->sources) {
|
||||
source->load(data.getAccessToken(), env, [this]() {
|
||||
assert(Environment::currentlyOn(ThreadType::Map));
|
||||
triggerUpdate();
|
||||
});
|
||||
}
|
||||
resourceLoader = util::make_unique<ResourceLoader>();
|
||||
resourceLoader->setAccessToken(data.getAccessToken());
|
||||
resourceLoader->setObserver(this);
|
||||
resourceLoader->setStyle(style.get());
|
||||
|
||||
triggerUpdate(Update::Zoom);
|
||||
}
|
||||
@@ -299,4 +299,9 @@ void MapContext::onLowMemory() {
|
||||
view.invalidate([this] { render(); });
|
||||
}
|
||||
|
||||
void MapContext::onTileDataChanged() {
|
||||
assert(Environment::currentlyOn(ThreadType::Map));
|
||||
triggerUpdate();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user