AW-4860
FarmMaps.Develop/FarmMapsLib/pipeline/head This commit looks good Details
FarmMaps/FarmMapsLib/pipeline/head This commit looks good Details

master 2023.03
Willem Dantuma 2023-03-15 12:18:23 +01:00
parent 3c7adf012f
commit f2e265391c
5 changed files with 196 additions and 187 deletions

View File

@ -1,6 +1,6 @@
{
"name": "farmmaps-lib-app",
"version": "3.0.1",
"version": "3.0.2",
"scripts": {
"ng": "ng",
"start": "ng serve",

View File

@ -7,7 +7,7 @@
<li class="border-top pt-1 pb-1 value" *ngFor="let layerValue of layers">
<div>{{layerValue.layerName}}</div>
<div>{{layerValue.date|date}}</div>
<div><span *ngIf="layerValue.quantity"><span class="me-1">{{layerValue.quantity}}</span> </span><span class="me-1 font-weight-bold">{{layerValue.value}}</span><span>{{layerValue.unit}}</span></div>
<div><span *ngIf="layerValue.quantity"><span class="me-1">{{layerValue.quantity}}</span> </span><span class="me-1 font-weight-bold">{{getScaledValue(layerValue)}}</span><span>{{layerValue.unit}}</span></div>
</li>
</ul>
<ng-template #no_data>
@ -15,4 +15,4 @@
</ng-template>
</div>
</div>
</div>>
</div>

View File

@ -1,16 +1,16 @@
import { Component, OnInit,Input,ViewChild,ElementRef,AfterViewInit } from '@angular/core';
import {IItemLayer} from '../../../models/item.layer';
import { Component, OnInit, Input, ViewChild, ElementRef, AfterViewInit } from '@angular/core';
import { IItemLayer } from '../../../models/item.layer';
import { Store } from '@ngrx/store';
import * as mapReducers from '../../../reducers/map.reducer';
import * as mapActions from '../../../actions/map.actions';
import { MapComponent } from 'ngx-openlayers';
import { ILayervalue } from '../../../models/layer.value';
import { Observable,interval,Subject } from 'rxjs';
import { Observable, interval, Subject } from 'rxjs';
import { debounce, throttle } from 'rxjs/operators';
import { toLonLat } from 'ol/proj';
import { toStringHDMS } from 'ol/coordinate';
import { ClipboardService } from 'ngx-clipboard'
import {GeoJSON,WKT} from 'ol/format';
import { GeoJSON, WKT } from 'ol/format';
import { Point } from 'ol/geom';
@Component({
@ -18,19 +18,19 @@ import { Point } from 'ol/geom';
templateUrl: './layer-values.component.html',
styleUrls: ['./layer-values.component.scss']
})
export class LayerValuesComponent implements OnInit,AfterViewInit {
export class LayerValuesComponent implements OnInit, AfterViewInit {
@ViewChild('layerValues') containerRef:ElementRef;
offsetX$ =0;
offsetY$ =0;
lonlat$="";
wkt$= "";
layerValues$:Observable<Array<ILayervalue>> = this.store.select(mapReducers.selectGetLayerValues);
enabled$:Observable<boolean> = this.store.select(mapReducers.selectGetLayerValuesEnabled);
wktFormat$:WKT;
@ViewChild('layerValues') containerRef: ElementRef;
offsetX$ = 0;
offsetY$ = 0;
lonlat$ = "";
wkt$ = "";
layerValues$: Observable<Array<ILayervalue>> = this.store.select(mapReducers.selectGetLayerValues);
enabled$: Observable<boolean> = this.store.select(mapReducers.selectGetLayerValuesEnabled);
wktFormat$: WKT;
constructor( private store: Store<mapReducers.State>,private map: MapComponent,private clipboardService$:ClipboardService) {
this.wktFormat$=new WKT();
constructor(private store: Store<mapReducers.State>, private map: MapComponent, private clipboardService$: ClipboardService) {
this.wktFormat$ = new WKT();
}
ngOnInit(): void {
@ -39,7 +39,7 @@ export class LayerValuesComponent implements OnInit,AfterViewInit {
moveEndSubject = new Subject<any>();
ngAfterViewInit():void {
ngAfterViewInit(): void {
this.offsetY$ = this.containerRef.nativeElement.offsetTop;
this.offsetX$ = this.containerRef.nativeElement.offsetLeft;
this.map.instance.on('moveend', () => {
@ -49,14 +49,22 @@ export class LayerValuesComponent implements OnInit,AfterViewInit {
}
updateValuesLocation() {
const xy = this.map.instance.getCoordinateFromPixel([this.offsetX$,this.offsetY$])
const xy = this.map.instance.getCoordinateFromPixel([this.offsetX$, this.offsetY$])
const lonlat = toLonLat(xy);
this.wkt$ = this.wktFormat$.writeGeometry(new Point(lonlat))
this.lonlat$ = toStringHDMS(lonlat);
this.store.dispatch(new mapActions.SetLayerValuesLocation(xy[0],xy[1]));
this.store.dispatch(new mapActions.SetLayerValuesLocation(xy[0], xy[1]));
}
copyToClipboard() {
this.clipboardService$.copy(this.wkt$);
}
public getScaledValue(layerValue: ILayervalue): number {
let v = layerValue.value;
if (layerValue.scale && layerValue.scale != 0) {
v = layerValue.scale * layerValue.value;
}
return v;
}
}

View File

@ -1,34 +1,34 @@
import { Injectable } from '@angular/core';
import { Store, Action,createFeatureSelector } from '@ngrx/store';
import { Store, Action, createFeatureSelector } from '@ngrx/store';
import { ROUTER_NAVIGATED, RouterReducerState } from '@ngrx/router-store';
import * as fromRouter from '@ngrx/router-store';
import { createEffect, Actions,ofType } from '@ngrx/effects';
import { createEffect, Actions, ofType } from '@ngrx/effects';
import { EMPTY, Observable , of} from 'rxjs';
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';
import { getCenter,createEmpty,extend } from 'ol/extent';
import {Point,Geometry} from 'ol/geom'
import { GeoJSON, WKT } from 'ol/format';
import { Feature } from 'ol';
import { getCenter, createEmpty, extend } from 'ol/extent';
import { Point, Geometry } from 'ol/geom'
import * as mapActions from '../actions/map.actions';
import * as mapReducers from '../reducers/map.reducer';
import {commonReducers} from '@farmmaps/common';
import { commonReducers } from '@farmmaps/common';
import {commonActions} from '@farmmaps/common';
import { commonActions } from '@farmmaps/common';
import { IItem } from '@farmmaps/common';
import { FolderService, ItemService } from '@farmmaps/common';
import { tassign } from 'tassign';
import {FeatureIconService} from '../services/feature-icon.service';
import { FeatureIconService } from '../services/feature-icon.service';
import * as style from 'ol/style';
import { ItemTypeService,IQueryState } from '@farmmaps/common';
import { ItemTypeService, IQueryState } from '@farmmaps/common';
import { TemporalItemLayer } from '../models/item.layer'
export const getRouterState = createFeatureSelector<RouterReducerState>('router');
@ -50,9 +50,9 @@ export class MapEffects {
private _wktFormat: WKT;
private overrideSelectedItemLayer = false;
private updateFeatureGeometry(feature:Feature<Geometry>, updateEvent:commonActions.DeviceUpdateEvent): Feature<Geometry> {
private updateFeatureGeometry(feature: Feature<Geometry>, updateEvent: commonActions.DeviceUpdateEvent): Feature<Geometry> {
const newFeature = feature.clone();
const f = this._wktFormat.readFeature(updateEvent.attributes["geometry"],{
const f = this._wktFormat.readFeature(updateEvent.attributes["geometry"], {
dataProjection: 'EPSG:4326',
featureProjection: 'EPSG:3857'
});
@ -66,12 +66,12 @@ export class MapEffects {
ofType(mapActions.INIT),
withLatestFrom(this.store$.select(commonReducers.selectGetRootItems)),
switchMap(([action, rootItems]) => {
const actions=[];
const actions = [];
for (const rootItem of rootItems) {
if (rootItem.itemType == "UPLOADS_FOLDER") actions.push(new mapActions.SetParent(rootItem.code));
}
// initialize default feature styles
actions.push(new mapActions.SetStyle('file',new style.Style({
actions.push(new mapActions.SetStyle('file', new style.Style({
image: new style.Icon({
anchor: [0.5, 1],
scale: 0.05,
@ -85,7 +85,7 @@ export class MapEffects {
color: 'rgba(0, 0, 0,0)'
})
})));
actions.push(new mapActions.SetStyle('selected',new style.Style({
actions.push(new mapActions.SetStyle('selected', new style.Style({
image: new style.Icon({
anchor: [0.5, 1],
scale: 0.08,
@ -124,9 +124,9 @@ export class MapEffects {
const a = action as mapActions.StartSearch;
const startDate = a.queryState.startDate;
const endDate = a.queryState.endDate;
let newAction:Observable<Action>;
let newAction: Observable<Action>;
if (a.queryState.itemCode || a.queryState.parentCode || a.queryState.itemType || a.queryState.query || a.queryState.tags) {
newAction= this.itemService$.getFeatures(a.queryState.bbox, "EPSG:3857", a.queryState.query, a.queryState.tags, startDate, endDate, a.queryState.itemType, a.queryState.parentCode, a.queryState.dataFilter, a.queryState.level).pipe(
newAction = this.itemService$.getFeatures(a.queryState.bbox, "EPSG:3857", a.queryState.query, a.queryState.tags, startDate, endDate, a.queryState.itemType, a.queryState.parentCode, a.queryState.dataFilter, a.queryState.level).pipe(
switchMap((features: any) => {
for (const f of features.features) {
if (f.properties && f.properties["code"]) {
@ -147,7 +147,7 @@ export class MapEffects {
zoomToExtent$ = createEffect(() => this.actions$.pipe(
ofType(mapActions.STARTSEARCHSUCCESS),
mergeMap((action: mapActions.StartSearchSuccess) => {
const actions =[];
const actions = [];
actions.push(new commonActions.SetMenuVisible(false));
const extent = createEmpty();
if (!action.query.bboxFilter) {
@ -155,7 +155,7 @@ export class MapEffects {
for (const f of action.features) {
extend(extent, (f as Feature<Geometry>).getGeometry().getExtent());
}
if(action.features && action.features.length >0) {
if (action.features && action.features.length > 0) {
actions.push(new mapActions.SetExtent(extent));
}
}
@ -171,7 +171,7 @@ export class MapEffects {
for (const f of action.features) {
extend(extent, (f as Feature<Geometry>).getGeometry().getExtent());
}
if(action.features.length>0) return of(new mapActions.SetExtent(extent));
if (action.features.length > 0) return of(new mapActions.SetExtent(extent));
}
return EMPTY;
})));
@ -193,8 +193,8 @@ export class MapEffects {
switchMap(child => {
return this.itemService$.getItem(child.parentCode)
.pipe(map(parent => {
return {child, parent};
}),catchError(() => { const parent:IItem = null;return of({child,parent})})
return { child, parent };
}), catchError(() => { const parent: IItem = null; return of({ child, parent }) })
);
}),
map(data => new mapActions.SelectItemSuccess(data.child, data.parent)),
@ -207,20 +207,20 @@ export class MapEffects {
selectItemSuccessSetLayer$ = createEffect(() => this.actions$.pipe(
ofType(mapActions.SELECTITEMSUCCESS),
map((action:mapActions.SelectItemSuccess) =>
map((action: mapActions.SelectItemSuccess) =>
new mapActions.SetSelectedItemLayer(action.item)
)
));
selectItemSuccess$ = createEffect(() => this.actions$.pipe(
ofType(mapActions.SELECTITEMSUCCESS),
switchMap((action:mapActions.SelectItemSuccess) => {
if(!this.overrideSelectedItemLayer) {
switchMap((action: mapActions.SelectItemSuccess) => {
if (!this.overrideSelectedItemLayer) {
return this.itemService$.getFeature(action.item.code, "EPSG:3857").pipe(
map((feature: any) => {
const f = this._geojsonFormat.readFeature(feature);
f.setId(action.item.code);
return new mapActions.AddFeatureSuccess(f );
return new mapActions.AddFeatureSuccess(f);
}),
catchError(error => of(new commonActions.Fail(error))));
} else {
@ -231,9 +231,9 @@ export class MapEffects {
selectItemSuccessTemporal$ = createEffect(() => this.actions$.pipe(
ofType(mapActions.SELECTITEMSUCCESS),
switchMap((action:mapActions.SelectItemSuccess) => {
if(action.item.itemType == "vnd.farmmaps.itemtype.temporal") {
return this.itemService$.getChildItemList(action.item.code,null).pipe(
switchMap((action: mapActions.SelectItemSuccess) => {
if (action.item.itemType == "vnd.farmmaps.itemtype.temporal") {
return this.itemService$.getChildItemList(action.item.code, null).pipe(
map(items => new mapActions.SelectTemporalItemsSuccess(
items.sort((a, b) =>
-(Date.parse(b.dataDate) - Date.parse(a.dataDate))
@ -248,7 +248,7 @@ export class MapEffects {
uploadedItemClick$ = createEffect(() => this.actions$.pipe(
ofType(commonActions.UPLOADEDFILECLICK),
switchMap((action: commonActions.UploadedFileClick) => of(new mapActions.DoQuery(tassign(mapReducers.initialState.query.querystate, {itemCode:action.itemCode})))
switchMap((action: commonActions.UploadedFileClick) => of(new mapActions.DoQuery(tassign(mapReducers.initialState.query.querystate, { itemCode: action.itemCode })))
)));
featureUpdate$ = createEffect(() => this.actions$.pipe(
@ -264,7 +264,7 @@ export class MapEffects {
}
}
if (feature) {
return of(new mapActions.UpdateFeatureSuccess(this.updateFeatureGeometry(feature,deviceUpdateEventAction)));
return of(new mapActions.UpdateFeatureSuccess(this.updateFeatureGeometry(feature, deviceUpdateEventAction)));
} else {
return [];
}
@ -280,7 +280,7 @@ export class MapEffects {
switchMap(child => {
return this.itemService$.getItem(child.parentCode)
.pipe(map(parent => {
return {child, parent};
return { child, parent };
})
);
}),
@ -291,13 +291,13 @@ export class MapEffects {
}
})));
getActionFromQueryState(queryState:IQueryState, inSearch:boolean):Observable<Action>|[] {
if(!inSearch && (queryState.itemType || queryState.parentCode || queryState.itemCode || queryState.query || queryState.tags)) {
var newAction:Action;
getActionFromQueryState(queryState: IQueryState, inSearch: boolean): Observable<Action> | [] {
if (!inSearch && (queryState.itemType || queryState.parentCode || queryState.itemCode || queryState.query || queryState.tags)) {
var newAction: Action;
if (queryState.itemCode && queryState.itemCode != "") {
newAction= new mapActions.SelectItem(queryState.itemCode);
newAction = new mapActions.SelectItem(queryState.itemCode);
} else {
newAction= new mapActions.StartSearch(queryState);
newAction = new mapActions.StartSearch(queryState);
}
} else {
@ -308,23 +308,23 @@ export class MapEffects {
getLayerValue$ = createEffect(() => this.actions$.pipe(
ofType(mapActions.GETLAYERVALUE),
mergeMap((action:mapActions.GetLayerValue) => {
mergeMap((action: mapActions.GetLayerValue) => {
const l = action.itemLayer.item.data["layers"][action.itemLayer.layerIndex];
const scale = l.scale?l.scale:1;
return this.itemService$.getLayerValue(action.itemLayer.item.code,action.itemLayer.layerIndex,action.x,action.y).pipe(
const scale = l.scale ? l.scale : 1;
return this.itemService$.getLayerValue(action.itemLayer.item.code, action.itemLayer.layerIndex, action.x, action.y).pipe(
mergeMap((v: number) => {
const a=[];
if(v !== null) {
if(l.renderer && l.renderer.colorMap && l.renderer.colorMap.colormapType == "manual") {
const a = [];
if (v !== null) {
if (l.renderer && l.renderer.colorMap && l.renderer.colorMap.colormapType == "manual") {
l.renderer.colorMap.entries.forEach((e) => {
if(e.value == v && e.label) {
v=e.label;
if (e.value == v && e.label) {
v = e.label;
return;
}
});
a.push(new mapActions.GetLayerValueSuccess({date:action.itemLayer.item.dataDate,value:v,layerName:l.name,quantity:"",unit:l.unit}));
a.push(new mapActions.GetLayerValueSuccess({ date: action.itemLayer.item.dataDate, value: v, layerName: l.name, quantity: "", unit: l.unit, scale: l.scale }));
} else {
a.push(new mapActions.GetLayerValueSuccess({date:action.itemLayer.item.dataDate,value:v*scale,layerName:l.name,quantity:l.quantity,unit:l.unit}));
a.push(new mapActions.GetLayerValueSuccess({ date: action.itemLayer.item.dataDate, value: v * scale, layerName: l.name, quantity: l.quantity, unit: l.unit, scale: l.scale }));
}
}
return a;
@ -333,10 +333,10 @@ export class MapEffects {
)));
updateLayerValuesOnLayerAddedOrRemoved$ = createEffect(() => this.actions$.pipe(
ofType(mapActions.ADDLAYER,mapActions.REMOVELAYER,mapActions.SELECTITEMSUCCESS,mapActions.SELECTTEMPORALITEMSSUCCESS, mapActions.NEXTTEMPORAL,mapActions.PREVIOUSTEMPORAL,mapActions.TOGGLELAYERVALUESENABLED,mapActions.SETLAYERINDEX,mapActions.SETSELECTEDITEMLAYER),
ofType(mapActions.ADDLAYER, mapActions.REMOVELAYER, mapActions.SELECTITEMSUCCESS, mapActions.SELECTTEMPORALITEMSSUCCESS, mapActions.NEXTTEMPORAL, mapActions.PREVIOUSTEMPORAL, mapActions.TOGGLELAYERVALUESENABLED, mapActions.SETLAYERINDEX, mapActions.SETSELECTEDITEMLAYER),
withLatestFrom(this.store$.select(mapReducers.selectGetLayerValuesX)),
withLatestFrom(this.store$.select(mapReducers.selectGetLayerValuesY)),
map(([[action,x],y]) => new mapActions.SetLayerValuesLocation(x,y))
map(([[action, x], y]) => new mapActions.SetLayerValuesLocation(x, y))
));
@ -345,23 +345,23 @@ export class MapEffects {
withLatestFrom(this.store$.select(mapReducers.selectGetSelectedItemLayer)),
withLatestFrom(this.store$.select(mapReducers.selectGetLayerValuesEnabled)),
withLatestFrom(this.store$.select(mapReducers.selectGetOverlayLayers)),
mergeMap(([[[action, selected], enabled],overlayLayers]) => {
mergeMap(([[[action, selected], enabled], overlayLayers]) => {
const layers = [];
if(selected) {
if(selected && (selected as TemporalItemLayer).selectedItemLayer ) {
selected=(selected as TemporalItemLayer).selectedItemLayer;
if (selected) {
if (selected && (selected as TemporalItemLayer).selectedItemLayer) {
selected = (selected as TemporalItemLayer).selectedItemLayer;
}
layers.push(selected);
}
overlayLayers.forEach((ol) => {
if(ol!=selected) layers.push(ol);
if (ol != selected) layers.push(ol);
});
const a = action as mapActions.SetLayerValuesLocation;
const actions = [];
if(enabled) {
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));
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));
}
});
}
@ -372,16 +372,16 @@ export class MapEffects {
setState$ = createEffect(() => this.actions$.pipe(
ofType(mapActions.SETSTATE),
withLatestFrom(this.store$.select(mapReducers.selectGetInSearch)),
switchMap(([action,inSearch]) => {
switchMap(([action, inSearch]) => {
const a = action as mapActions.SetState;
return this.getActionFromQueryState(a.queryState,inSearch);
return this.getActionFromQueryState(a.queryState, inSearch);
})));
escape$ = createEffect(() => this.actions$.pipe(
ofType(commonActions.ESCAPE),
switchMap((action) => {
const a = action as commonActions.Escape;
if(a.escapeKey) {
if (a.escapeKey) {
return of(new mapActions.Clear());
} else {
return EMPTY;
@ -392,7 +392,7 @@ export class MapEffects {
ofType(ROUTER_NAVIGATED),
switchMap(() => this.store$.select(selectRouteData as any)),
switchMap((data: any) => {
if(data && data["fm-map-map"]) {
if (data && data["fm-map-map"]) {
const params = data["fm-map-map"];
this.overrideSelectedItemLayer = params["overrideSelectedItemlayer"] ? params["overrideSelectedItemlayer"] : false;
} else {
@ -402,7 +402,7 @@ export class MapEffects {
})
));
constructor(private actions$: Actions, private store$: Store<mapReducers.State>, private folderService$: FolderService, private itemService$: ItemService,private featureIconService$:FeatureIconService,private itemTypeService$:ItemTypeService) {
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();
}

View File

@ -1,7 +1,8 @@
export interface ILayervalue {
date:string;
layerName:string;
unit:string;
quantity:string;
value:number;
date: string;
layerName: string;
unit: string;
quantity: string;
value: number;
scale: number;
}