2016-03-07 19:25:11 +00:00
|
|
|
import Layer from './Layer';
|
|
|
|
import extend from 'lodash.assign';
|
|
|
|
|
|
|
|
class LayerGroup extends Layer {
|
|
|
|
constructor(options) {
|
|
|
|
var defaults = {
|
|
|
|
output: false
|
|
|
|
};
|
|
|
|
|
|
|
|
var _options = extend({}, defaults, options);
|
|
|
|
|
|
|
|
super(_options);
|
|
|
|
|
|
|
|
this._layers = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
addLayer(layer) {
|
|
|
|
this._layers.push(layer);
|
2016-08-30 15:46:04 +00:00
|
|
|
return this._world.addLayer(layer);
|
2016-03-07 19:25:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
removeLayer(layer) {
|
|
|
|
var layerIndex = this._layers.indexOf(layer);
|
|
|
|
|
|
|
|
if (layerIndex > -1) {
|
|
|
|
// Remove from this._layers
|
|
|
|
this._layers.splice(layerIndex, 1);
|
|
|
|
};
|
|
|
|
|
|
|
|
this._world.removeLayer(layer);
|
|
|
|
}
|
|
|
|
|
2016-09-16 09:08:35 +00:00
|
|
|
_onAdd(world) {
|
|
|
|
return Promise.resolve(this);
|
|
|
|
}
|
2016-03-07 19:25:11 +00:00
|
|
|
|
|
|
|
// Destroy the layers and remove them from the scene and memory
|
|
|
|
destroy() {
|
2016-03-14 22:01:28 +00:00
|
|
|
// TODO: Sometimes this is already null, find out why
|
|
|
|
if (this._layers) {
|
|
|
|
for (var i = 0; i < this._layers.length; i++) {
|
|
|
|
this._layers[i].destroy();
|
|
|
|
}
|
2016-03-07 19:25:11 +00:00
|
|
|
|
2016-03-14 22:01:28 +00:00
|
|
|
this._layers = null;
|
|
|
|
}
|
2016-03-07 19:25:11 +00:00
|
|
|
|
|
|
|
super.destroy();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default LayerGroup;
|
|
|
|
|
|
|
|
var noNew = function(options) {
|
|
|
|
return new LayerGroup(options);
|
|
|
|
};
|
|
|
|
|
|
|
|
export {noNew as layerGroup};
|