diff --git a/projects/common-map/src/fm-map/components/map/map.component.ts b/projects/common-map/src/fm-map/components/map/map.component.ts index 8f7ddb5..3527955 100644 --- a/projects/common-map/src/fm-map/components/map/map.component.ts +++ b/projects/common-map/src/fm-map/components/map/map.component.ts @@ -150,11 +150,11 @@ export class MapComponent implements OnInit, OnDestroy,AfterViewInit { this.compassHeading$ = this.deviceorientationService.getCurrentCompassHeading(); this.styles$ = this.store.select(mapReducers.selectGetStyles); - this.mapState$.pipe(withLatestFrom(this.queryState$)).subscribe((state) => { - this.replaceUrl(state[0], state[1], true); - }); + // this.mapState$.pipe(withLatestFrom(this.queryState$)).subscribe((state) => { + // this.replaceUrl(state[0], state[1], true); + // }); this.query$.pipe(withLatestFrom(this.mapState$)).subscribe((state) => { - this.replaceUrl(state[1], state[0],false); + this.replaceUrl(state[1], state[0],this.stateSetCount == 0); }); this.initCustomStyles(); } @@ -210,17 +210,27 @@ export class MapComponent implements OnInit, OnDestroy,AfterViewInit { queryStateChanged = this.lastQueryState != queryState; this.lastQueryState = queryState; } + this.zone.run(()=> { + if ( queryStateChanged) { + console.debug("Query state"); + this.store.dispatch(new mapActions.SetQueryState(newQueryState)); + } else if (mapStateChanged) { + console.debug("Map state"); + this.store.dispatch(new mapActions.SetMapState(newMapState)); + } + }) + - if (mapStateChanged && queryStateChanged) { - console.debug("Both states"); - this.store.dispatch(new mapActions.SetState(newMapState, newQueryState)); - } else if (mapStateChanged) { - console.debug("Map state"); - this.store.dispatch(new mapActions.SetMapState(newMapState)); - } else if (queryStateChanged) { - console.debug("Query state"); - this.store.dispatch(new mapActions.SetQueryState(newQueryState)); - } + // if (mapStateChanged && queryStateChanged) { + // console.debug("Both states"); + // this.store.dispatch(new mapActions.SetState(newMapState, newQueryState)); + // } else if (mapStateChanged) { + // console.debug("Map state"); + // this.store.dispatch(new mapActions.SetMapState(newMapState)); + // } else if (queryStateChanged) { + // console.debug("Query state"); + // this.store.dispatch(new mapActions.SetQueryState(newQueryState)); + // } this.stateSetCount += 1; }); setTimeout(() => { 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 1c6facf..e47c26f 100644 --- a/projects/common-map/src/fm-map/effects/map.effects.ts +++ b/projects/common-map/src/fm-map/effects/map.effects.ts @@ -139,19 +139,7 @@ export class MapEffects { startSearchSucces$: Observable = this.actions$.pipe( ofType(mapActions.STARTSEARCHSUCCESS), mergeMap((action: mapActions.StartSearchSuccess) => { - if (action.query.bboxFilter) { return [new commonActions.SetMenuVisible(false)]; - } else { - var extent = createEmpty(); - - if (extent) { - for (let f of action.features) { - extend(extent, (f as Feature).getGeometry().getExtent()); - } - } - //return []; - return [new mapActions.SetExtent(extent),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 b2e7fda..903d8e9 100644 --- a/projects/common-map/src/fm-map/reducers/map.reducer.ts +++ b/projects/common-map/src/fm-map/reducers/map.reducer.ts @@ -10,6 +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'; @@ -124,11 +125,21 @@ 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, { panelVisible: true, clearEnabled: true, searchMinified: true, - features: a.features + features: a.features, + extent:extent }); } case mapActions.SELECTFEATURE: {