From c777ce75ad6c74b6dfef25e9979c7eef87b84519 Mon Sep 17 00:00:00 2001 From: Willem Dantuma Date: Sun, 22 Mar 2020 20:08:53 +0100 Subject: [PATCH] Fix zoom issue --- .../fm-map/components/map/map.component.ts | 47 +++++++++---------- .../src/fm-map/effects/map.effects.ts | 23 ++++++++- 2 files changed, 42 insertions(+), 28 deletions(-) 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 ab165fc..e96bd3b 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 @@ -128,29 +128,24 @@ export class MapComponent implements OnInit, OnDestroy,AfterViewInit { this.store.dispatch(new mapActions.Init()); this.selectedFeatures$.next({x:0,y:0,features:[]}); this.selectedFeatures$.next(null); - this.query$.pipe(withLatestFrom(this.mapState$),withLatestFrom(this.setStateCount$)).subscribe((state) => { - let queryState = state[0][0]; - let mapState = state[0][1]; - let urlparts=[]; - - // TODO: fix this properly move the action to a separte column in itemtypes - if(queryState.itemType && queryState.itemCode) { - let itemType = this.itemTypeService.itemTypes[queryState.itemType]; - if (itemType.viewer == "edit_in_editor" && itemType.editor) { - urlparts.push('/editor'); - urlparts.push(itemType.editor); - urlparts.push('item'); - urlparts.push(queryState.itemCode); - } - } - if(state[1]>0) { - if(urlparts.length>0) { - this.router.navigate(urlparts); - } else { - this.replaceUrl(mapState, queryState,false); - } - } - }); + this.query$.pipe(withLatestFrom(this.mapState$),withLatestFrom(this.setStateCount$)).subscribe(([[queryState,mapState],setStateCount]) =>{ + if(setStateCount>0) { + console.debug("Querystate:replace url"); + this.replaceUrl(mapState,queryState,false); + } + }); + this.mapState$.pipe(withLatestFrom(this.queryState$),withLatestFrom(this.setStateCount$)).subscribe(([[mapState,queryState],setStateCount]) =>{ + if(setStateCount>0) { + console.debug("Mapstate:replace url"); + this.replaceUrl(mapState,queryState,true); + } + }); + this.queryState$.pipe(withLatestFrom(this.mapState$),withLatestFrom(this.setStateCount$)).subscribe(([[queryState,mapState],setStateCount]) =>{ + if(setStateCount>0) { + console.debug("Querystate:replace url"); + this.replaceUrl(mapState,queryState,true); + } + }) } initCustomStyles() { @@ -278,10 +273,10 @@ export class MapComponent implements OnInit, OnDestroy,AfterViewInit { let mapState: IMapState = { xCenter: center[0], yCenter: center[1], zoom: zoom, rotation: rotation, baseLayerCode: null }; let state = { mapState: mapState, extent: extent }; let source = from([state]); - source.pipe(withLatestFrom(this.selectedBaseLayer$), withLatestFrom(this.queryState$)).subscribe(([[state, baselayer], queryState]) => { - if (mapState && baselayer && queryState) { + source.pipe(withLatestFrom(this.selectedBaseLayer$)).subscribe(([state, baselayer]) => { + if (mapState && baselayer) { let newMapState = tassign(state.mapState, { baseLayerCode: baselayer.item.code }); - this.replaceUrl(newMapState, tassign(queryState, { bbox: queryState.bboxFilter ? state.extent : queryState.bbox })); + this.store.dispatch(new mapActions.SetMapState(newMapState)); this.store.dispatch(new mapActions.SetViewExtent(state.extent)); } }); 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 e06a16a..ba77655 100644 --- a/projects/common-map/src/fm-map/effects/map.effects.ts +++ b/projects/common-map/src/fm-map/effects/map.effects.ts @@ -26,6 +26,10 @@ import {FeatureIconService} from '../services/feature-icon.service'; import * as style from 'ol/style'; +import { ItemTypeService } from '@farmmaps/common'; +import { Router } from '@angular/router'; + + @Injectable() export class MapEffects { @@ -252,7 +256,22 @@ export class MapEffects { switchMap((action: mapActions.SetQueryState) => { var newAction:Action; if (action.queryState.itemCode && action.queryState.itemCode != "") { - newAction= new mapActions.SelectItem(action.queryState.itemCode); + let urlparts=[]; + if(action.queryState.itemType && action.queryState.itemType!= "") { + let itemType = this.itemTypeService$.itemTypes[action.queryState.itemType]; + if (itemType.viewer == "edit_in_editor" && itemType.editor) { + urlparts.push('/editor'); + urlparts.push(itemType.editor); + urlparts.push('item'); + urlparts.push(action.queryState.itemCode); + } + } + if(urlparts.length==0 ) { + newAction= new mapActions.SelectItem(action.queryState.itemCode); + } else { + this.router$.navigate(urlparts); + return []; + } } else { newAction= new mapActions.StartSearch(action.queryState); } @@ -272,7 +291,7 @@ export class MapEffects { return of(newAction); })); - constructor(private actions$: Actions, private store$: Store, private folderService$: FolderService, private itemService$: ItemService,private featureIconService$:FeatureIconService) { + constructor(private actions$: Actions, private store$: Store, private folderService$: FolderService, private itemService$: ItemService,private featureIconService$:FeatureIconService,private itemTypeService$:ItemTypeService,private router$:Router) { this._geojsonFormat = new GeoJSON(); this._wktFormat = new WKT(); }