diff --git a/projects/common-map/src/fm-map/actions/map.actions.ts b/projects/common-map/src/fm-map/actions/map.actions.ts index 3cd9b05..e025855 100644 --- a/projects/common-map/src/fm-map/actions/map.actions.ts +++ b/projects/common-map/src/fm-map/actions/map.actions.ts @@ -88,7 +88,7 @@ export class StartSearch implements Action { export class StartSearchSuccess implements Action { readonly type = STARTSEARCHSUCCESS; - constructor(public features: Array, public query:IQueryState) { } + constructor(public features: Array, public query:IQueryState,public setStateCount:number) { } } export class SelectFeature implements Action { diff --git a/projects/common-map/src/fm-map/effects/map.effects.ts b/projects/common-map/src/fm-map/effects/map.effects.ts index 3a9a501..f4a1691 100644 --- a/projects/common-map/src/fm-map/effects/map.effects.ts +++ b/projects/common-map/src/fm-map/effects/map.effects.ts @@ -3,8 +3,8 @@ import { Injectable } from '@angular/core'; import { Store, Action } from '@ngrx/store'; import { Effect, Actions,ofType } from '@ngrx/effects'; -import { Observable , of } from 'rxjs'; -import { withLatestFrom, switchMap, map, catchError, mergeMap,delay } from 'rxjs/operators'; +import { Observable , of, interval } from 'rxjs'; +import { withLatestFrom, switchMap, map, catchError, mergeMap,delayWhen } from 'rxjs/operators'; import {GeoJSON,WKT} from 'ol/format'; import {Feature} from 'ol'; @@ -113,19 +113,21 @@ export class MapEffects { @Effect() startSearch$: Observable = this.actions$.pipe( ofType(mapActions.STARTSEARCH), - switchMap((action: mapActions.StartSearch) => { - var startDate = action.queryState.startDate; - var endDate = action.queryState.endDate; + withLatestFrom(this.store$.select(mapReducers.selectgetSetStateCount)), + switchMap(([action,setStateCount]) => { + let a = action as mapActions.StartSearch; + var startDate = a.queryState.startDate; + var endDate = a.queryState.endDate; var newAction:Observable; - if (action.queryState.itemCode || action.queryState.parentCode || action.queryState.itemType || action.queryState.query || action.queryState.tags) { - newAction= this.itemService$.getFeatures(action.queryState.bbox, "EPSG:3857", action.queryState.query, action.queryState.tags, startDate, endDate, action.queryState.itemType, action.queryState.parentCode).pipe( + if (a.queryState.itemCode || a.queryState.parentCode || a.queryState.itemType || a.queryState.query || a.queryState.tags) { + newAction= this.itemService$.getFeatures(a.queryState.bbox, "EPSG:3857", a.queryState.query, a.queryState.tags, startDate, endDate, a.queryState.itemType, a.queryState.parentCode).pipe( switchMap((features: any) => { for (let f of features.features) { if (f.properties && f.properties["code"]) { f.id = f.properties["code"]; } } - return of(new mapActions.StartSearchSuccess(this._geojsonFormat.readFeatures(features), action.queryState)); + return of(new mapActions.StartSearchSuccess(this._geojsonFormat.readFeatures(features), a.queryState,setStateCount)); } ), catchError(error => of(new commonActions.Fail(error)))); @@ -139,7 +141,7 @@ export class MapEffects { @Effect() zoomToExtent$: Observable = this.actions$.pipe( ofType(mapActions.STARTSEARCHSUCCESS), - delay(500), + delayWhen(action => (action as mapActions.StartSearchSuccess).setStateCount == 1 ? interval(500):interval(0)), mergeMap((action: mapActions.StartSearchSuccess) => { let actions =[]; actions.push(new commonActions.SetMenuVisible(false)); 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 c19a4d5..27291d8 100644 --- a/projects/common-map/src/fm-map/reducers/map.reducer.ts +++ b/projects/common-map/src/fm-map/reducers/map.reducer.ts @@ -273,7 +273,6 @@ export function reducer(state = initialState, action: mapActions.Actions | commo case mapActions.DOQUERY: { let a = action as mapActions.DoQuery; return tassign(state, { - setStateCount:state.setStateCount+1, query: tassign(a.query, { bbox: a.query.bboxFilter ? state.viewExtent : [] })}); } case mapActions.ADDFEATURESUCCESS: { @@ -463,6 +462,9 @@ export function reducer(state = initialState, action: mapActions.Actions | commo let a= action as mapActions.SetReplaceUrl; return tassign(state,{replaceUrl:a.replaceUrl}); } + case mapActions.CLEAR: { + return tassign(state,{setStateCount:0}); + } default: { return state; }