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