More refactoring

This commit is contained in:
Willem Dantuma 2020-03-02 08:55:11 +01:00
parent a151b73d03
commit da1c9c3fe2
3 changed files with 30 additions and 33 deletions

View File

@ -226,12 +226,6 @@ export class ItemLayersComponent extends LayerGroupComponent implements OnChange
return layer; return layer;
} }
createTemporalLayer(item:IItem,itemLayer:IItemLayer):Layer {
let i = itemLayer as ITemporalItemLayer;
return null;
}
createLayer(itemLayer: IItemLayer): Layer { createLayer(itemLayer: IItemLayer): Layer {
var layer: Layer = null; var layer: Layer = null;
var layerIndex = -1; var layerIndex = -1;
@ -241,11 +235,6 @@ export class ItemLayersComponent extends LayerGroupComponent implements OnChange
layer = this.createShapeLayer(itemLayer.item,itemLayer); layer = this.createShapeLayer(itemLayer.item,itemLayer);
} else if (itemLayer.item.itemType == 'vnd.farmmaps.itemtype.layer') { } else if (itemLayer.item.itemType == 'vnd.farmmaps.itemtype.layer') {
layer = this.createExternalLayer(itemLayer.item,itemLayer); layer = this.createExternalLayer(itemLayer.item,itemLayer);
} else if (itemLayer.item.itemType == 'vnd.farmmaps.itemtype.temporal') {
var i = itemLayer as ITemporalItemLayer;
if(i.selectedItem) {
layer = this.createLayer( new ItemLayer(i.selectedItem) );
}
} }
if (layer) { if (layer) {
let geometry = new GeoJSON().readGeometry(itemLayer.item.geometry); let geometry = new GeoJSON().readGeometry(itemLayer.item.geometry);
@ -276,23 +265,35 @@ export class ItemLayersComponent extends LayerGroupComponent implements OnChange
olLayers.removeAt(olIndex); olLayers.removeAt(olIndex);
olLayers.insertAt(index, layer); olLayers.insertAt(index, layer);
} }
if(layer) {
itemLayer.layer = layer;
layer.setOpacity(itemLayer.opacity);
layer.setVisible(itemLayer.visible);
}
return layer; return layer;
} }
updateLayers(itemLayers: IItemLayer[]) { updateLayers(itemLayers: IItemLayer[]) {
let newLayers: IItemLayer[] = [];
if (itemLayers) { if (itemLayers) {
var olLayers = this.instance.getLayers();
itemLayers.forEach((itemLayer, index) => { itemLayers.forEach((itemLayer, index) => {
var layer = this.addOrUpdateOlLayer(itemLayer,index); if(itemLayer.item.itemType == 'vnd.farmmaps.itemtype.temporal') {
if(layer) { let il = itemLayer as ITemporalItemLayer;
itemLayer.layer = layer; let previousLayer = this.addOrUpdateOlLayer(il.previousItemLayer,newLayers.length);
layer.setOpacity(itemLayer.opacity); if(previousLayer) newLayers.push(previousLayer);
layer.setVisible(itemLayer.visible); let selectedLayer = this.addOrUpdateOlLayer(il.selectedItemLayer,newLayers.length);
if(selectedLayer) newLayers.push(selectedLayer);
let nextLayer = this.addOrUpdateOlLayer(il.nextItemLayer,newLayers.length);
if(selectedLayer) newLayers.push(nextLayer);
} else {
let layer = this.addOrUpdateOlLayer(itemLayer,newLayers.length);
if(layer) newLayers.push(layer);
} }
}); });
// Remove the layers that have disapeared from childrenLayers // Remove the layers that have disapeared from childrenLayers
if (olLayers.getLength() > itemLayers.length) { var olLayers = this.instance.getLayers();
for (let i = itemLayers.length; i < olLayers.getLength(); i++) { if (olLayers.getLength() > newLayers.length) {
for (let i = newLayers.length; i < olLayers.getLength(); i++) {
olLayers.removeAt(i); olLayers.removeAt(i);
} }
} }

View File

@ -26,21 +26,17 @@ export class ItemLayer implements IItemLayer {
} }
export interface ITemporalItemLayer extends IItemLayer { export interface ITemporalItemLayer extends IItemLayer {
previousLayer: Layer previousItemLayer: IItemLayer,
nextLayer: Layer selectedItemLayer: IItemLayer,
nextItemLayer: IItemLayer,
temporalItems: IItem[], temporalItems: IItem[],
previousItem: IItem,
selectedItem: IItem,
nextItem:IItem
} }
export class TemporalItemLayer extends ItemLayer implements ITemporalItemLayer { export class TemporalItemLayer extends ItemLayer implements ITemporalItemLayer {
public previousLayer:Layer = null; public previousItemLayer:IItemLayer = null;
public nextLayer:Layer = null; public selectedItemLayer:IItemLayer =null;
public nextItemLayer:IItemLayer = null;
public temporalItems:IItem[] = []; public temporalItems:IItem[] = [];
public previousItem:IItem = null;
public selectedItem:IItem =null;
public nextItem:IItem = null;
constructor(item:IItem) { constructor(item:IItem) {
super(item) super(item)

View File

@ -181,9 +181,9 @@ export function reducer(state = initialState, action: mapActions.Actions | commo
let a = action as mapActions.SelectTemporalItemsSuccess; let a = action as mapActions.SelectTemporalItemsSuccess;
let selectedItemLayer=tassign(state.selectedItemLayer) as TemporalItemLayer; let selectedItemLayer=tassign(state.selectedItemLayer) as TemporalItemLayer;
selectedItemLayer.temporalItems = a.temporalItems; selectedItemLayer.temporalItems = a.temporalItems;
selectedItemLayer.selectedItem = a.temporalItems.length>0?a.temporalItems[a.temporalItems.length-1]:null; selectedItemLayer.selectedItemLayer = a.temporalItems.length>0?new ItemLayer(a.temporalItems[a.temporalItems.length-1]):null;
selectedItemLayer.previousItem = a.temporalItems.length>1?a.temporalItems[a.temporalItems.length-2]:null; selectedItemLayer.previousItemLayer = a.temporalItems.length>1?new ItemLayer(a.temporalItems[a.temporalItems.length-2]):null;
selectedItemLayer.nextItem = null; selectedItemLayer.nextItemLayer = null;
return tassign(state,{selectedItemLayer:tassign(state.selectedItemLayer,selectedItemLayer as ItemLayer)}); return tassign(state,{selectedItemLayer:tassign(state.selectedItemLayer,selectedItemLayer as ItemLayer)});
} }
case mapActions.STARTSEARCH: { case mapActions.STARTSEARCH: {