Add layer values
All checks were successful
FarmMaps.Develop/FarmMapsLib/pipeline/head This commit looks good

This commit is contained in:
Willem Dantuma
2021-03-05 17:19:30 +01:00
parent 5760c2b8ea
commit 9d5cd0fa88
13 changed files with 290 additions and 20 deletions

View File

@@ -3,8 +3,8 @@ import { Injectable } from '@angular/core';
import { Store, Action } from '@ngrx/store';
import { Effect, Actions,ofType } from '@ngrx/effects';
import { EMPTY, Observable , of } from 'rxjs';
import { withLatestFrom, switchMap, map, catchError, mergeMap } from 'rxjs/operators';
import { EMPTY, Observable , of,merge} from 'rxjs';
import { withLatestFrom, switchMap, map, catchError, mergeMap,tap } from 'rxjs/operators';
import {GeoJSON,WKT} from 'ol/format';
import {Feature} from 'ol';
@@ -297,6 +297,55 @@ export class MapEffects {
return of(newAction);
}
@Effect()
getLayerValue$: Observable<Action> = this.actions$.pipe(
ofType(mapActions.GETLAYERVALUE),
switchMap((action:mapActions.GetLayerValue) => {
var l = action.itemLayer.item.data["layers"][action.itemLayer.layerIndex];
var scale = l.scale?l.scale:1;
return this.itemService$.getLayerValue(action.itemLayer.item.code,action.itemLayer.layerIndex,action.x,action.y).pipe(
switchMap((v: number) => {
let a=[];
if(v) a.push(new mapActions.GetLayerValueSuccess({date:"",value:v*scale,layerName:l.name,quantity:l.quantity,unit:l.unit}));
return a;
}))
}
));
@Effect()
updateLayerValuesOnLayerAddedOrRemoved$: Observable<Action> = this.actions$.pipe(
ofType(mapActions.ADDLAYER,mapActions.REMOVELAYER,mapActions.SELECTITEM),
withLatestFrom(this.store$.select(mapReducers.selectGetLayerValuesX)),
withLatestFrom(this.store$.select(mapReducers.selectGetLayerValuesY)),
map(([[action,x],y]) => new mapActions.SetLayerValuesLocation(x,y))
);
@Effect()
getLayerValues$: Observable<Action> = this.actions$.pipe(
ofType(mapActions.SETLAYERVALUESLOCATION),
withLatestFrom(this.store$.select(mapReducers.selectGetSelectedItemLayer)),
withLatestFrom(this.store$.select(mapReducers.selectGetLayerValuesEnabled)),
withLatestFrom(this.store$.select(mapReducers.selectGetOverlayLayers)),
switchMap(([[[action, selected], enabled],overlayLayers]) => {
let layers = [];
if(selected) layers.push(selected);
overlayLayers.forEach((ol) => {
if(ol!=selected) layers.push(ol);
});
let a = action as mapActions.SetLayerValuesLocation;
let actions = [];
if(enabled) {
layers.forEach((ol) => {
if("vnd.farmmaps.itemtype.shape.processed,vnd.farmmaps.itemtype.geotiff.processed".indexOf(ol.item.itemType)>=0) {
actions.push(new mapActions.GetLayerValue(ol,a.x,a.y));
}
});
}
return actions;
}));
@Effect()
setState$: Observable<Action> = this.actions$.pipe(
ofType(mapActions.SETSTATE),