avocado-old/packages/topdown/layers-view.js
2019-04-25 02:01:35 -05:00

35 lines
803 B
JavaScript

import {Container} from '@avocado/graphics';
import {LayerView} from './layer-view';
export class LayersView extends Container {
constructor(layers, renderer) {
super();
this.layers = layers;
this.layerViews = {};
this.renderer = renderer;
this.layers.on('layerAdded', this.onLayerAdded, this);
for (const {index, layer} of layers) {
this.onLayerAdded(layer, index);
}
this.layers.on('layerRemoved', this.onLayerRemoved, this);
}
onLayerAdded(layer, index) {
const layerView = new LayerView(layer, this.renderer);
this.layerViews[index] = layerView;
this.addChild(layerView);
}
onLayerRemoved(layer, index) {
const layerView = this.layerViews[index];
if (!layerView) {
return;
}
this.removeChild(layerView);
}
}