[core] Return source and layer ownership (#7014)

When a source or layer is removed transfer ownership back to the
caller so it can (optionally) take it. Preserve the behavior that 
removing a CustomLayer triggers deinitialization.  Deinitialize all 
custom layers when a style is destroyed in case those layers are not 
explicitly removed.
This commit is contained in:
Jesse Bounds
2016-11-11 14:40:04 -08:00
parent 82fcd58121
commit 96a7a4402e
6 changed files with 43 additions and 17 deletions

View File

@@ -818,11 +818,12 @@ void Map::addSource(std::unique_ptr<style::Source> source) {
}
}
void Map::removeSource(const std::string& sourceID) {
std::unique_ptr<Source> Map::removeSource(const std::string& sourceID) {
if (impl->style) {
impl->styleMutated = true;
impl->style->removeSource(sourceID);
return impl->style->removeSource(sourceID);
}
return nullptr;
}
style::Layer* Map::getLayer(const std::string& layerID) {
@@ -847,18 +848,20 @@ void Map::addLayer(std::unique_ptr<Layer> layer, const optional<std::string>& be
impl->backend.deactivate();
}
void Map::removeLayer(const std::string& id) {
std::unique_ptr<Layer> Map::removeLayer(const std::string& id) {
if (!impl->style) {
return;
return nullptr;
}
impl->styleMutated = true;
impl->backend.activate();
impl->style->removeLayer(id);
auto removedLayer = impl->style->removeLayer(id);
impl->onUpdate(Update::Classes);
impl->backend.deactivate();
return removedLayer;
}
void Map::addImage(const std::string& name, std::unique_ptr<const SpriteImage> image) {