Some refactoring

This commit is contained in:
Willem Dantuma 2020-02-29 11:56:19 +01:00
parent 47f77c2819
commit a151b73d03

View File

@ -261,18 +261,14 @@ export class ItemLayersComponent extends LayerGroupComponent implements OnChange
this.updateLayers(this.itemLayers); this.updateLayers(this.itemLayers);
} }
updateLayers(itemLayers: IItemLayer[]) { addOrUpdateOlLayer(itemLayer:IItemLayer,index:number):Layer {
if (itemLayers) {
var olLayers = this.instance.getLayers(); var olLayers = this.instance.getLayers();
itemLayers.forEach((itemLayer, index) => {
var layer = itemLayer.layer; var layer = itemLayer.layer;
let olIndex = olLayers.getArray().indexOf(layer); let olIndex = olLayers.getArray().indexOf(layer);
if (olIndex < 0) { if (olIndex < 0) {
// New layer: we add it to the map // New layer: we add it to the map
layer = this.createLayer(itemLayer); layer = this.createLayer(itemLayer);
if (layer) { if (layer) {
itemLayer.layer = layer;
olLayers.insertAt(index, layer); olLayers.insertAt(index, layer);
} }
} else if (index !== olIndex) { } else if (index !== olIndex) {
@ -280,7 +276,16 @@ export class ItemLayersComponent extends LayerGroupComponent implements OnChange
olLayers.removeAt(olIndex); olLayers.removeAt(olIndex);
olLayers.insertAt(index, layer); olLayers.insertAt(index, layer);
} }
return layer;
}
updateLayers(itemLayers: IItemLayer[]) {
if (itemLayers) {
var olLayers = this.instance.getLayers();
itemLayers.forEach((itemLayer, index) => {
var layer = this.addOrUpdateOlLayer(itemLayer,index);
if(layer) { if(layer) {
itemLayer.layer = layer;
layer.setOpacity(itemLayer.opacity); layer.setOpacity(itemLayer.opacity);
layer.setVisible(itemLayer.visible); layer.setVisible(itemLayer.visible);
} }