Some refactoring
This commit is contained in:
parent
47f77c2819
commit
a151b73d03
@ -261,29 +261,34 @@ export class ItemLayersComponent extends LayerGroupComponent implements OnChange
|
||||
this.updateLayers(this.itemLayers);
|
||||
}
|
||||
|
||||
addOrUpdateOlLayer(itemLayer:IItemLayer,index:number):Layer {
|
||||
var olLayers = this.instance.getLayers();
|
||||
var layer = itemLayer.layer;
|
||||
let olIndex = olLayers.getArray().indexOf(layer);
|
||||
if (olIndex < 0) {
|
||||
// New layer: we add it to the map
|
||||
layer = this.createLayer(itemLayer);
|
||||
if (layer) {
|
||||
olLayers.insertAt(index, layer);
|
||||
}
|
||||
} else if (index !== olIndex) {
|
||||
// layer has moved inside the layers list
|
||||
olLayers.removeAt(olIndex);
|
||||
olLayers.insertAt(index, layer);
|
||||
}
|
||||
return layer;
|
||||
}
|
||||
|
||||
updateLayers(itemLayers: IItemLayer[]) {
|
||||
if (itemLayers) {
|
||||
var olLayers = this.instance.getLayers();
|
||||
itemLayers.forEach((itemLayer, index) => {
|
||||
|
||||
var layer = itemLayer.layer;
|
||||
let olIndex = olLayers.getArray().indexOf(layer);
|
||||
if (olIndex < 0) {
|
||||
// New layer: we add it to the map
|
||||
layer = this.createLayer(itemLayer);
|
||||
if (layer) {
|
||||
itemLayer.layer = layer;
|
||||
olLayers.insertAt(index, layer);
|
||||
}
|
||||
} else if (index !== olIndex) {
|
||||
// layer has moved inside the layers list
|
||||
olLayers.removeAt(olIndex);
|
||||
olLayers.insertAt(index, layer);
|
||||
}
|
||||
var layer = this.addOrUpdateOlLayer(itemLayer,index);
|
||||
if(layer) {
|
||||
itemLayer.layer = layer;
|
||||
layer.setOpacity(itemLayer.opacity);
|
||||
layer.setVisible(itemLayer.visible);
|
||||
}
|
||||
}
|
||||
});
|
||||
// Remove the layers that have disapeared from childrenLayers
|
||||
if (olLayers.getLength() > itemLayers.length) {
|
||||
|
Loading…
Reference in New Issue
Block a user