Remove uneeded delay

This commit is contained in:
Willem Dantuma 2020-04-22 08:59:04 +02:00
parent 69751540d3
commit 7eef50eb7a
3 changed files with 15 additions and 11 deletions

View File

@ -88,7 +88,7 @@ export class StartSearch implements Action {
export class StartSearchSuccess implements Action {
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 {

View File

@ -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<Action> = 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<Action>;
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<Action> = 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));

View File

@ -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;
}