From dad8e061eab73e1f06c4bb92343a0e8666fb03e3 Mon Sep 17 00:00:00 2001 From: Willem Dantuma Date: Thu, 26 Mar 2020 15:45:57 +0100 Subject: [PATCH] AW-1079 --- .../fm-map/components/map/map.component.ts | 20 ++++++++----------- .../src/fm-map/reducers/map.reducer.ts | 10 ++++++++-- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/projects/common-map/src/fm-map/components/map/map.component.ts b/projects/common-map/src/fm-map/components/map/map.component.ts index 8f0e399..1f24e4c 100644 --- a/projects/common-map/src/fm-map/components/map/map.component.ts +++ b/projects/common-map/src/fm-map/components/map/map.component.ts @@ -166,13 +166,9 @@ export class MapComponent implements OnInit, OnDestroy,AfterViewInit { ngAfterViewInit() { this.initCustomStyles(); - this.paramSub = this.route.paramMap.pipe(withLatestFrom(this.setStateCount$),withLatestFrom(this.queryState$),withLatestFrom(this.mapState$)).subscribe( (state) => { - let params: ParamMap = state[0][0][0]; - let setStateCount:number = state[0][0][1]; - let lastQueryState:IQueryState = state[0][1]; - let lastMapState:IMapState = state[1]; - var newMapState: IMapState = null; - var newQueryState: IQueryState = null; + this.paramSub = this.route.paramMap.pipe(withLatestFrom(this.setStateCount$),withLatestFrom(this.queryState$),withLatestFrom(this.mapState$)).subscribe( ([[[params,setStateCount],lastQueryState],lastMapState]) => { + var newMapState: IMapState = lastMapState; + var newQueryState: IQueryState = lastQueryState; var mapStateChanged = false; var queryStateChanged = false; if (params.has("xCenter") && params.has("yCenter")) { @@ -182,7 +178,7 @@ export class MapComponent implements OnInit, OnDestroy,AfterViewInit { let rotation = parseFloat(params.get("rotation")); let baseLayer = params.get("baseLayer")?params.get("baseLayer"):""; newMapState = { xCenter: xCenter, yCenter: yCenter, zoom: zoom, rotation: rotation, baseLayerCode: baseLayer } - mapStateChanged = (JSON.stringify(lastMapState) != JSON.stringify(newMapState)) && setStateCount == 0 ; + mapStateChanged = (JSON.stringify(lastMapState) != JSON.stringify(newMapState)); window.localStorage.setItem("FarmMapsCommonMap_mapState",JSON.stringify(newMapState)); } if (params.has("queryState")) { @@ -192,13 +188,13 @@ export class MapComponent implements OnInit, OnDestroy,AfterViewInit { newQueryState = this.serializeService.deserialize(queryState); queryState = this.serializeService.serialize(newQueryState); } - queryStateChanged = this.serializeService.serialize(lastQueryState) != queryState || setStateCount==0; + queryStateChanged = this.serializeService.serialize(lastQueryState) != queryState; } let t =0; if(setStateCount==0) t=600; setTimeout(() => { this.zone.run(()=> { - if ( queryStateChanged && mapStateChanged) { + if ( (queryStateChanged && mapStateChanged) || setStateCount ==0) { this.store.dispatch(new mapActions.SetState(newMapState,newQueryState)); } else if(queryStateChanged) { this.store.dispatch(new mapActions.SetQueryState(newQueryState)); @@ -265,8 +261,8 @@ export class MapComponent implements OnInit, OnDestroy,AfterViewInit { let mapState: IMapState = { xCenter: center[0], yCenter: center[1], zoom: zoom, rotation: rotation, baseLayerCode: null }; let state = { mapState: mapState, extent: extent }; let source = from([state]); - source.pipe(withLatestFrom(this.selectedBaseLayer$)).subscribe(([state, baselayer]) => { - if (mapState && baselayer) { + source.pipe(withLatestFrom(this.selectedBaseLayer$),withLatestFrom(this.setStateCount$)).subscribe(([[state, baselayer],setStateCount]) => { + if (mapState && baselayer && setStateCount > 0) { // do not react on first move let newMapState = tassign(state.mapState, { baseLayerCode: baselayer.item.code }); this.store.dispatch(new mapActions.SetMapState(newMapState)); this.store.dispatch(new mapActions.SetViewExtent(state.extent)); diff --git a/projects/common-map/src/fm-map/reducers/map.reducer.ts b/projects/common-map/src/fm-map/reducers/map.reducer.ts index 57d4914..d1e22fc 100644 --- a/projects/common-map/src/fm-map/reducers/map.reducer.ts +++ b/projects/common-map/src/fm-map/reducers/map.reducer.ts @@ -316,8 +316,14 @@ export function reducer(state = initialState, action: mapActions.Actions | commo let itemLayers = state.overlayLayers.slice(0); let itemLayer = new ItemLayer(a.item); itemLayer.layerIndex = a.layerIndex == -1 ? 0 : a.layerIndex; - itemLayers.push(itemLayer); - return tassign(state, { overlayLayers: itemLayers, selectedOverlayLayer: itemLayer }); + let existing = itemLayers.filter(il => il.item.code == itemLayer.item.code && il.layerIndex == itemLayer.layerIndex); + if(existing.length==0) { + itemLayers.push(itemLayer); + return tassign(state, { overlayLayers: itemLayers, selectedOverlayLayer: itemLayer }); + } else { + return state; + } + } case mapActions.REMOVELAYER: { let a = action as mapActions.RemoveLayer;