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);
|
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[]) {
|
updateLayers(itemLayers: IItemLayer[]) {
|
||||||
if (itemLayers) {
|
if (itemLayers) {
|
||||||
var olLayers = this.instance.getLayers();
|
var olLayers = this.instance.getLayers();
|
||||||
itemLayers.forEach((itemLayer, index) => {
|
itemLayers.forEach((itemLayer, index) => {
|
||||||
|
var layer = this.addOrUpdateOlLayer(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);
|
|
||||||
}
|
|
||||||
if(layer) {
|
if(layer) {
|
||||||
|
itemLayer.layer = layer;
|
||||||
layer.setOpacity(itemLayer.opacity);
|
layer.setOpacity(itemLayer.opacity);
|
||||||
layer.setVisible(itemLayer.visible);
|
layer.setVisible(itemLayer.visible);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// Remove the layers that have disapeared from childrenLayers
|
// Remove the layers that have disapeared from childrenLayers
|
||||||
if (olLayers.getLength() > itemLayers.length) {
|
if (olLayers.getLength() > itemLayers.length) {
|
||||||
|
Loading…
Reference in New Issue
Block a user