Fix zoom to extent
This commit is contained in:
parent
4e83bc6158
commit
e41c728fb2
@ -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()
|
||||
|
@ -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
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user