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 3c4ac09..b6e5bda 100644 --- a/projects/common-map/src/fm-map/effects/map.effects.ts +++ b/projects/common-map/src/fm-map/effects/map.effects.ts @@ -4,11 +4,11 @@ import { Store, Action } from '@ngrx/store'; import { Effect, Actions,ofType } from '@ngrx/effects'; import { Observable , of } from 'rxjs'; -import { withLatestFrom, switchMap, map, catchError, mergeMap } from 'rxjs/operators'; +import { withLatestFrom, switchMap, map, catchError, mergeMap,delay } from 'rxjs/operators'; import {GeoJSON,WKT} from 'ol/format'; import {Feature} from 'ol'; -import { getCenter } from 'ol/extent'; +import { getCenter,createEmpty,extend } from 'ol/extent'; import {Point} from 'ol/geom' @@ -137,10 +137,29 @@ export class MapEffects { @Effect() - startSearchSucces$: Observable = this.actions$.pipe( + zoomToExtent$: Observable = this.actions$.pipe( + ofType(mapActions.STARTSEARCHSUCCESS), + delay(500), + mergeMap((action: mapActions.StartSearchSuccess) => { + let actions =[]; + actions.push(new commonActions.SetMenuVisible(false)); + let extent = createEmpty(); + if (!action.query.bboxFilter) { + if (extent) { + for (let f of action.features) { + extend(extent, (f as Feature).getGeometry().getExtent()); + } + } + actions.push(new mapActions.SetExtent(extent)); + } + return actions; + })); + + @Effect() + hideMenu$: Observable = this.actions$.pipe( ofType(mapActions.STARTSEARCHSUCCESS), mergeMap((action: mapActions.StartSearchSuccess) => { - return [new commonActions.SetMenuVisible(false)]; + return of(new commonActions.SetMenuVisible(false)); })); @Effect() 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 1e0e9ce..069d498 100644 --- a/projects/common-map/src/fm-map/reducers/map.reducer.ts +++ b/projects/common-map/src/fm-map/reducers/map.reducer.ts @@ -10,7 +10,7 @@ import {commonActions} from '@farmmaps/common'; import { createSelector, createFeatureSelector } from '@ngrx/store'; import {Feature} from 'ol'; -import { createEmpty, extend} from 'ol/extent'; + import { ROUTER_NAVIGATION, RouterNavigationAction } from '@ngrx/router-store'; @@ -129,18 +129,8 @@ export function reducer(state = initialState, action: mapActions.Actions | commo } case mapActions.STARTSEARCHSUCCESS: { let a = action as mapActions.StartSearchSuccess; - let extent = state.extent; - if (!action.query.bboxFilter) { - extent = createEmpty(); - if (extent) { - for (let f of action.features) { - extend(extent, (f as Feature).getGeometry().getExtent()); - } - } - } return tassign(state, { features: a.features, - extent:extent, inSearch:false }); }