Fix zoom to extent

This commit is contained in:
Willem Dantuma
2020-04-21 13:22:54 +02:00
parent 4e83bc6158
commit e41c728fb2
2 changed files with 24 additions and 15 deletions

View File

@@ -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<Action> = this.actions$.pipe(
zoomToExtent$: Observable<Action> = 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<Action> = this.actions$.pipe(
ofType(mapActions.STARTSEARCHSUCCESS),
mergeMap((action: mapActions.StartSearchSuccess) => {
return [new commonActions.SetMenuVisible(false)];
return of(new commonActions.SetMenuVisible(false));
}));
@Effect()