AW-1079
All checks were successful
FarmMaps.Develop/FarmMapsLib/develop This commit looks good

This commit is contained in:
Willem Dantuma 2020-03-26 15:45:57 +01:00
parent bc17f80050
commit dad8e061ea
2 changed files with 16 additions and 14 deletions

View File

@ -166,13 +166,9 @@ export class MapComponent implements OnInit, OnDestroy,AfterViewInit {
ngAfterViewInit() { ngAfterViewInit() {
this.initCustomStyles(); this.initCustomStyles();
this.paramSub = this.route.paramMap.pipe(withLatestFrom(this.setStateCount$),withLatestFrom(this.queryState$),withLatestFrom(this.mapState$)).subscribe( (state) => { this.paramSub = this.route.paramMap.pipe(withLatestFrom(this.setStateCount$),withLatestFrom(this.queryState$),withLatestFrom(this.mapState$)).subscribe( ([[[params,setStateCount],lastQueryState],lastMapState]) => {
let params: ParamMap = state[0][0][0]; var newMapState: IMapState = lastMapState;
let setStateCount:number = state[0][0][1]; var newQueryState: IQueryState = lastQueryState;
let lastQueryState:IQueryState = state[0][1];
let lastMapState:IMapState = state[1];
var newMapState: IMapState = null;
var newQueryState: IQueryState = null;
var mapStateChanged = false; var mapStateChanged = false;
var queryStateChanged = false; var queryStateChanged = false;
if (params.has("xCenter") && params.has("yCenter")) { 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 rotation = parseFloat(params.get("rotation"));
let baseLayer = params.get("baseLayer")?params.get("baseLayer"):""; let baseLayer = params.get("baseLayer")?params.get("baseLayer"):"";
newMapState = { xCenter: xCenter, yCenter: yCenter, zoom: zoom, rotation: rotation, baseLayerCode: 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)); window.localStorage.setItem("FarmMapsCommonMap_mapState",JSON.stringify(newMapState));
} }
if (params.has("queryState")) { if (params.has("queryState")) {
@ -192,13 +188,13 @@ export class MapComponent implements OnInit, OnDestroy,AfterViewInit {
newQueryState = this.serializeService.deserialize(queryState); newQueryState = this.serializeService.deserialize(queryState);
queryState = this.serializeService.serialize(newQueryState); queryState = this.serializeService.serialize(newQueryState);
} }
queryStateChanged = this.serializeService.serialize(lastQueryState) != queryState || setStateCount==0; queryStateChanged = this.serializeService.serialize(lastQueryState) != queryState;
} }
let t =0; let t =0;
if(setStateCount==0) t=600; if(setStateCount==0) t=600;
setTimeout(() => { setTimeout(() => {
this.zone.run(()=> { this.zone.run(()=> {
if ( queryStateChanged && mapStateChanged) { if ( (queryStateChanged && mapStateChanged) || setStateCount ==0) {
this.store.dispatch(new mapActions.SetState(newMapState,newQueryState)); this.store.dispatch(new mapActions.SetState(newMapState,newQueryState));
} else if(queryStateChanged) { } else if(queryStateChanged) {
this.store.dispatch(new mapActions.SetQueryState(newQueryState)); 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 mapState: IMapState = { xCenter: center[0], yCenter: center[1], zoom: zoom, rotation: rotation, baseLayerCode: null };
let state = { mapState: mapState, extent: extent }; let state = { mapState: mapState, extent: extent };
let source = from([state]); let source = from([state]);
source.pipe(withLatestFrom(this.selectedBaseLayer$)).subscribe(([state, baselayer]) => { source.pipe(withLatestFrom(this.selectedBaseLayer$),withLatestFrom(this.setStateCount$)).subscribe(([[state, baselayer],setStateCount]) => {
if (mapState && baselayer) { if (mapState && baselayer && setStateCount > 0) { // do not react on first move
let newMapState = tassign(state.mapState, { baseLayerCode: baselayer.item.code }); let newMapState = tassign(state.mapState, { baseLayerCode: baselayer.item.code });
this.store.dispatch(new mapActions.SetMapState(newMapState)); this.store.dispatch(new mapActions.SetMapState(newMapState));
this.store.dispatch(new mapActions.SetViewExtent(state.extent)); this.store.dispatch(new mapActions.SetViewExtent(state.extent));

View File

@ -316,8 +316,14 @@ export function reducer(state = initialState, action: mapActions.Actions | commo
let itemLayers = state.overlayLayers.slice(0); let itemLayers = state.overlayLayers.slice(0);
let itemLayer = new ItemLayer(a.item); let itemLayer = new ItemLayer(a.item);
itemLayer.layerIndex = a.layerIndex == -1 ? 0 : a.layerIndex; itemLayer.layerIndex = a.layerIndex == -1 ? 0 : a.layerIndex;
let existing = itemLayers.filter(il => il.item.code == itemLayer.item.code && il.layerIndex == itemLayer.layerIndex);
if(existing.length==0) {
itemLayers.push(itemLayer); itemLayers.push(itemLayer);
return tassign(state, { overlayLayers: itemLayers, selectedOverlayLayer: itemLayer }); return tassign(state, { overlayLayers: itemLayers, selectedOverlayLayer: itemLayer });
} else {
return state;
}
} }
case mapActions.REMOVELAYER: { case mapActions.REMOVELAYER: {
let a = action as mapActions.RemoveLayer; let a = action as mapActions.RemoveLayer;