FarmMapsLib/projects/common-map/src/fm-map/components/legend/legend.component.ts

98 lines
2.6 KiB
TypeScript
Raw Normal View History

2019-11-29 11:24:34 +00:00
import { Component, OnInit, Input,AfterViewInit } from '@angular/core';
2019-11-29 11:52:18 +00:00
import { IColorMap, IColor, IColorEntry,ILayer, IRenderer } from '../../models/color.map';
2019-11-29 11:24:34 +00:00
@Component({
selector: 'fm-map-layer-legend',
templateUrl: './legend.component.html',
styleUrls: ['./legend.component.scss']
})
export class LegendComponent implements OnInit,AfterViewInit {
constructor() {
}
ngOnInit() {
}
ngAfterViewInit() {
}
@Input()
layer: ILayer;
@Input()
legend: string;
@Input()
histogram: string;
@Input()
2023-03-06 13:04:14 +00:00
showTitle = true;
2019-11-29 11:24:34 +00:00
@Input()
histogramenabled: boolean;
@Input()
legendunit: string;
@Input()
histogramunit: string;
2023-03-06 13:04:14 +00:00
public hideHistogramDetails = true;
2019-11-29 11:24:34 +00:00
onClickHistoGram(): void {
this.histogramenabled = !this.histogramenabled;
}
2019-11-29 11:52:18 +00:00
public getHex(color: IColor): string {
2019-11-29 11:24:34 +00:00
return '#' + this.componentToHex(color.red) + this.componentToHex(color.green) + this.componentToHex(color.blue);
}
2020-09-16 12:40:03 +00:00
public getAlphaHex(color: IColor): string {
return '#' + this.componentToHex(color.red) + this.componentToHex(color.green) + this.componentToHex(color.blue)+ this.componentToHex(color.alpha);
}
2019-11-29 11:24:34 +00:00
private componentToHex(c: number): string {
const hex = c.toString(16);
return hex.length === 1 ? `0${hex}` : hex;
}
2019-11-29 11:52:18 +00:00
public getPart(renderer: IRenderer, index: number): string {
2023-03-06 13:04:14 +00:00
const max = renderer.band.histogram.entries.reduce((max, entry) => entry.freqency > max ? entry.freqency : max, 0);
const scale = 65 / max;
const part = (renderer.band.histogram.entries[index].freqency * scale) + "%";
2019-11-29 11:24:34 +00:00
return part;
}
2020-04-07 07:43:54 +00:00
public getScaledValue(value:number,scale:number):number {
2020-04-07 06:51:31 +00:00
let v = value;
if(scale && scale != 0) {
v=scale*value;
}
return v;
}
2021-05-26 12:59:03 +00:00
public getPercentage(renderer: IRenderer, index: number): number {
2023-03-06 13:04:14 +00:00
const scale = 100 / renderer.band.histogram.entries.reduce((sum, entry) => sum + entry.freqency, 0);
const percent = renderer.band.histogram.entries[index].freqency * scale;
return percent < 0.1 ? null : percent;
2019-11-29 11:24:34 +00:00
}
2019-12-18 09:21:25 +00:00
showLegend(): boolean {
return this.layer && this.layer.renderer && this.layer.renderer.renderType != "MULTIBAND_COLOR";
}
2019-11-29 11:24:34 +00:00
showHistogram(): boolean {
2021-08-18 12:34:45 +00:00
return this.histogramenabled && this.layer.renderer.band.histogram.entries && this.layer.renderer.band.histogram.entries.length > 0 && this.layer.renderer.band.histogram.entries.length == this.layer.renderer.colorMap.entries.length;
2019-11-29 11:24:34 +00:00
}
2020-05-26 15:19:07 +00:00
2020-07-28 18:02:23 +00:00
bandContainsStatistics(): boolean {
return this.layer.renderer.band.statistics != null;
2020-05-26 15:19:07 +00:00
}
2021-05-26 14:11:21 +00:00
}