From 3db09c1e2ae5b8979610f8b7ab73bf990e895865 Mon Sep 17 00:00:00 2001 From: Willem Dantuma Date: Wed, 28 Sep 2022 12:01:59 +0200 Subject: [PATCH] Fix slide for temporal layer --- .../aol/item-layers/item-layers.component.ts | 47 ++++++++++--------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/projects/common-map/src/fm-map/components/aol/item-layers/item-layers.component.ts b/projects/common-map/src/fm-map/components/aol/item-layers/item-layers.component.ts index ee09d8e..bec746f 100644 --- a/projects/common-map/src/fm-map/components/aol/item-layers/item-layers.component.ts +++ b/projects/common-map/src/fm-map/components/aol/item-layers/item-layers.component.ts @@ -364,16 +364,12 @@ export class ItemLayersComponent extends LayerGroupComponent implements OnChange } } - installTopLayerPrerenderEventhandler() { - if(!this.topLayerPrerenderEventhandlerInstalled && this.onPrerender.observers.length > 0 ) { + installTopLayerPrerenderEventhandler(olLayer : Layer) { + if(!this.topLayerPrerenderEventhandlerInstalled && this.onPrerender.observers.length > 0 && olLayer) { if(this.instance.getVisible()) { - var olLayers = this.instance.getLayers().getArray().filter(l=> l.getVisible()); - if(olLayers.length >0) { - var topLayer = olLayers[0] as any; - topLayer.on('prerender',this.topLayerPrerenderEventhandler); - topLayer.on('postrender',this.topLayerPostrenderEventhandler); - this.topLayerPrerenderEventhandlerInstalled = true; - } + olLayer.on('prerender',this.topLayerPrerenderEventhandler); + olLayer.on('postrender',this.topLayerPostrenderEventhandler); + this.topLayerPrerenderEventhandlerInstalled = true; } } } @@ -382,13 +378,11 @@ export class ItemLayersComponent extends LayerGroupComponent implements OnChange if(this.topLayerPrerenderEventhandlerInstalled && this.onPrerender.observers.length > 0 ) { if(this.instance.getVisible()) { - var olLayers = this.instance.getLayers().getArray().filter(l=> l.getVisible()); - if(olLayers.length >0) { - var topLayer = olLayers[0] as any; - topLayer.un('prerender',this.topLayerPrerenderEventhandler); - topLayer.un('postrender',this.topLayerPostrenderEventhandler); - this.topLayerPrerenderEventhandlerInstalled = false; - } + var olLayers = this.instance.getLayers().getArray().forEach((l:any) => { + l.un('prerender',this.topLayerPrerenderEventhandler); + l.un('postrender',this.topLayerPostrenderEventhandler); + }); + this.topLayerPrerenderEventhandlerInstalled = false; } } } @@ -418,11 +412,19 @@ export class ItemLayersComponent extends LayerGroupComponent implements OnChange return layer; } - updateLayers(itemLayers: IItemLayer[]) { + updateLayers(itemLayers: IItemLayer[] | IItemLayer) { this.unInstallTopLayerPrerenderEventhandler(); + let dataLayer = false; + var ils:IItemLayer[] = []; + if(Array.isArray(itemLayers)) { + ils = itemLayers; + } else { + dataLayer=true; + ils=[itemLayers]; + } let newLayers: Layer[] = []; - if (itemLayers) { - itemLayers.forEach((itemLayer, index) => { + if (ils) { + ils.forEach((itemLayer, index) => { if(itemLayer.item.itemType == 'vnd.farmmaps.itemtype.temporal') { let il = itemLayer as ITemporalItemLayer; let previousLayer = this.addOrUpdateOlLayer(il.previousItemLayer,newLayers.length); @@ -431,9 +433,11 @@ export class ItemLayersComponent extends LayerGroupComponent implements OnChange if(selectedLayer) newLayers.push(selectedLayer); let nextLayer = this.addOrUpdateOlLayer(il.nextItemLayer,newLayers.length); if(nextLayer) newLayers.push(nextLayer); + this.installTopLayerPrerenderEventhandler(selectedLayer); } else { let layer = this.addOrUpdateOlLayer(itemLayer,newLayers.length); - if(layer) newLayers.push(layer); + if(layer) newLayers.push(layer); + this.installTopLayerPrerenderEventhandler(layer); } }); // Remove the layers that have disapeared from childrenLayers @@ -442,12 +446,11 @@ export class ItemLayersComponent extends LayerGroupComponent implements OnChange olLayers.removeAt(newLayers.length); } this.selectionLayer=null; - if(this.mapEventHandlerInstalled && itemLayers.length==1 && this.getItemlayer(itemLayers[0]).item.itemType == 'vnd.farmmaps.itemtype.shape.processed') { + if(this.mapEventHandlerInstalled && ils.length==1 && this.getItemlayer(itemLayers[0]).item.itemType == 'vnd.farmmaps.itemtype.shape.processed') { this.selectionLayer = this.createSelectionLayer(this.getItemlayer(itemLayers[0])); if(this.selectionLayer) olLayers.push(this.selectionLayer) } } - this.installTopLayerPrerenderEventhandler(); } topLayerPrerenderEventhandler = (event) => {