Refactor map component
All checks were successful
FarmMaps.Develop/FarmMapsLib/pipeline/head This commit looks good
All checks were successful
FarmMaps.Develop/FarmMapsLib/pipeline/head This commit looks good
This commit is contained in:
@@ -3,8 +3,8 @@ import { Injectable } from '@angular/core';
|
||||
import { Store, Action } from '@ngrx/store';
|
||||
import { Effect, Actions,ofType } from '@ngrx/effects';
|
||||
|
||||
import { Observable , of, interval } from 'rxjs';
|
||||
import { withLatestFrom, switchMap, map, catchError, mergeMap,delayWhen } from 'rxjs/operators';
|
||||
import { EMPTY, Observable , of } from 'rxjs';
|
||||
import { withLatestFrom, switchMap, map, catchError, mergeMap } from 'rxjs/operators';
|
||||
|
||||
import {GeoJSON,WKT} from 'ol/format';
|
||||
import {Feature} from 'ol';
|
||||
@@ -112,8 +112,7 @@ export class MapEffects {
|
||||
@Effect()
|
||||
startSearch$: Observable<Action> = this.actions$.pipe(
|
||||
ofType(mapActions.STARTSEARCH),
|
||||
withLatestFrom(this.store$.select(mapReducers.selectgetSetStateCount)),
|
||||
switchMap(([action,setStateCount]) => {
|
||||
switchMap((action) => {
|
||||
let a = action as mapActions.StartSearch;
|
||||
var startDate = a.queryState.startDate;
|
||||
var endDate = a.queryState.endDate;
|
||||
@@ -126,7 +125,7 @@ export class MapEffects {
|
||||
f.id = f.properties["code"];
|
||||
}
|
||||
}
|
||||
return of(new mapActions.StartSearchSuccess(this._geojsonFormat.readFeatures(features), a.queryState,setStateCount));
|
||||
return of(new mapActions.StartSearchSuccess(this._geojsonFormat.readFeatures(features), a.queryState));
|
||||
}
|
||||
),
|
||||
catchError(error => of(new commonActions.Fail(error))));
|
||||
@@ -140,7 +139,6 @@ export class MapEffects {
|
||||
@Effect()
|
||||
zoomToExtent$: Observable<Action> = this.actions$.pipe(
|
||||
ofType(mapActions.STARTSEARCHSUCCESS),
|
||||
delayWhen(action => (action as mapActions.StartSearchSuccess).setStateCount == 1 ? interval(500):interval(0)),
|
||||
mergeMap((action: mapActions.StartSearchSuccess) => {
|
||||
let actions =[];
|
||||
actions.push(new commonActions.SetMenuVisible(false));
|
||||
@@ -169,11 +167,10 @@ export class MapEffects {
|
||||
selectItem$: Observable<Action> = this.actions$.pipe(
|
||||
ofType(mapActions.SELECTITEM),
|
||||
withLatestFrom(this.store$.select(mapReducers.selectGetSelectedItem)),
|
||||
withLatestFrom(this.store$.select(mapReducers.getSetStateCount)),
|
||||
switchMap(([[action, selectedItem],setStateCount]) => {
|
||||
switchMap(([action, selectedItem]) => {
|
||||
let a = action as mapActions.SelectItem;
|
||||
let itemCode = selectedItem ? selectedItem.code : "";
|
||||
if (a.itemCode != itemCode || setStateCount == 1) {
|
||||
if (a.itemCode != itemCode) {
|
||||
return this.itemService$.getItem(a.itemCode).pipe(
|
||||
switchMap(child => {
|
||||
return this.itemService$.getItem(child.parentCode)
|
||||
@@ -278,21 +275,13 @@ export class MapEffects {
|
||||
} else {
|
||||
newAction= new mapActions.StartSearch(queryState);
|
||||
}
|
||||
return of(newAction);
|
||||
|
||||
} else {
|
||||
return of(new commonActions.Escape(true,false));
|
||||
newAction = new mapActions.Clear();
|
||||
}
|
||||
return of(newAction);
|
||||
}
|
||||
|
||||
@Effect()
|
||||
setQueryState$: Observable<Action> = this.actions$.pipe(
|
||||
ofType(mapActions.SETQUERYSTATE),
|
||||
withLatestFrom(this.store$.select(mapReducers.selectGetInSearch)),
|
||||
switchMap(([action,inSearch]) => {
|
||||
let a = action as mapActions.SetQueryState;
|
||||
return this.getActionFromQueryState(a.queryState,inSearch);
|
||||
}));
|
||||
|
||||
@Effect()
|
||||
setState$: Observable<Action> = this.actions$.pipe(
|
||||
ofType(mapActions.SETSTATE),
|
||||
@@ -302,8 +291,20 @@ export class MapEffects {
|
||||
return this.getActionFromQueryState(a.queryState,inSearch);
|
||||
}));
|
||||
|
||||
@Effect()
|
||||
escape$:Observable<Action> = this.actions$.pipe(
|
||||
ofType(commonActions.ESCAPE),
|
||||
switchMap((action) => {
|
||||
let a = action as commonActions.Escape;
|
||||
if(a.escapeKey) {
|
||||
return of(new mapActions.Clear());
|
||||
} else {
|
||||
return EMPTY;
|
||||
}
|
||||
}));
|
||||
|
||||
constructor(private actions$: Actions, private store$: Store<mapReducers.State>, private folderService$: FolderService, private itemService$: ItemService,private featureIconService$:FeatureIconService,private itemTypeService$:ItemTypeService) {
|
||||
this._geojsonFormat = new GeoJSON();
|
||||
this._wktFormat = new WKT();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user