import {Observable} from 'rxjs'; import {Component, Injectable, Input, OnInit} from '@angular/core'; import {Store} from '@ngrx/store'; import * as mapReducers from '../../reducers/map.reducer'; import {commonReducers, IItem, IListItem, ItemService, ItemTypeService} from '@farmmaps/common'; import {ForItemType} from '../for-item/for-itemtype.decorator'; import {ForSourceTask} from '../for-item/for-sourcetask.decorator'; import {AbstractItemListItemComponent} from '../item-list-item/item-list-item.component' import {map} from "rxjs/operators"; @ForItemType("vnd.farmmaps.itemtype.geotiff.processed") @ForSourceTask("vnd.farmmaps.task.shadow") @Injectable() @Component({ selector: 'item-list-item-shadow', templateUrl: './item-list-item-shadow.component.html', styleUrls: ['./item-list-item-shadow.component.scss'] }) export class ItemListItemShadowComponent extends AbstractItemListItemComponent implements OnInit { @Input() item: IListItem; selectedItem: Observable; public sunCenter = {x: 235.9, y: 259.4}; public sunStart = {x: 0, y: 0}; public sunEndRelative = {x: 0, y: 0}; public largeArc = 0; public radius = 120; public sunColor = '#ffcc00'; constructor(store: Store, itemTypeService: ItemTypeService, private itemService$: ItemService) { super(store, itemTypeService); } ngOnInit() { this.selectedItem = this.itemService$.getItem(this.item.code) .pipe(map(item => { const shadowIndex = this.getMeanShadowValue(item); this.calculateSunValues(shadowIndex); return item; })); } calculateSunValues(shadowIndex) { const dotProduct = shadowIndex * 2 - 1; this.largeArc = dotProduct > 0 ? 1 : 0; const angle = Math.acos(dotProduct); const yRadius = this.radius * Math.sin(-angle); this.sunStart.x = this.sunCenter.x + this.radius * dotProduct; this.sunStart.y = this.sunCenter.y + yRadius; this.sunEndRelative.x = this.sunStart.x; this.sunEndRelative.y = this.sunCenter.y - yRadius; } getSunShadowPath() { return `M${this.sunStart.x} ${this.sunStart.y} A${this.radius},${this.radius} 0 ${this.largeArc},0 ${this.sunEndRelative.x} ${this.sunEndRelative.y}z`; } getMeanShadowValue(item): number { return item.data.layers[0].renderer.band.histogram.mean; } }