Fix calculation value in function for map widget
This commit is contained in:
parent
a0ae28f2be
commit
31d0425cd8
@ -20,7 +20,15 @@ import { Datasource, DatasourceData } from '@app/shared/models/widget.models';
|
|||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import { Observable, Observer, of } from 'rxjs';
|
import { Observable, Observer, of } from 'rxjs';
|
||||||
import { map } from 'rxjs/operators';
|
import { map } from 'rxjs/operators';
|
||||||
import { createLabelFromDatasource, hashCode, isDefinedAndNotNull, isNumber, isUndefined, padValue } from '@core/utils';
|
import {
|
||||||
|
createLabelFromDatasource,
|
||||||
|
hashCode,
|
||||||
|
isDefined,
|
||||||
|
isDefinedAndNotNull, isFunction,
|
||||||
|
isNumber,
|
||||||
|
isUndefined,
|
||||||
|
padValue
|
||||||
|
} from '@core/utils';
|
||||||
|
|
||||||
export function createTooltip(target: L.Layer,
|
export function createTooltip(target: L.Layer,
|
||||||
settings: MarkerSettings | PolylineSettings | PolygonSettings,
|
settings: MarkerSettings | PolylineSettings | PolygonSettings,
|
||||||
@ -403,6 +411,24 @@ export function safeExecute(func: (...args: any[]) => any, params = []) {
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function functionValueCalculator(useFunction: boolean, func: (...args: any[]) => any, params = [], defaultValue: any) {
|
||||||
|
let res;
|
||||||
|
if (useFunction && isDefined(func) && isFunction(func)) {
|
||||||
|
try {
|
||||||
|
res = func(...params);
|
||||||
|
if (!isDefinedAndNotNull(res) || res === '') {
|
||||||
|
res = defaultValue;
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
res = defaultValue;
|
||||||
|
console.log('error in external function:', err);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
res = defaultValue;
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
export function calculateNewPointCoordinate(coordinate: number, imageSize: number): number {
|
export function calculateNewPointCoordinate(coordinate: number, imageSize: number): number {
|
||||||
let pointCoordinate = coordinate / imageSize;
|
let pointCoordinate = coordinate / imageSize;
|
||||||
if (pointCoordinate < 0) {
|
if (pointCoordinate < 0) {
|
||||||
|
|||||||
@ -15,7 +15,7 @@
|
|||||||
///
|
///
|
||||||
|
|
||||||
import L, { LatLngExpression, LeafletMouseEvent } from 'leaflet';
|
import L, { LatLngExpression, LeafletMouseEvent } from 'leaflet';
|
||||||
import { createTooltip, parseWithTranslation, safeExecute } from './maps-utils';
|
import { createTooltip, functionValueCalculator, parseWithTranslation, safeExecute } from './maps-utils';
|
||||||
import { FormattedData, PolygonSettings } from './map-models';
|
import { FormattedData, PolygonSettings } from './map-models';
|
||||||
|
|
||||||
export class Polygon {
|
export class Polygon {
|
||||||
@ -97,10 +97,7 @@ export class Polygon {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private getPolygonColor(settings: PolygonSettings): string | null {
|
private getPolygonColor(settings: PolygonSettings): string | null {
|
||||||
if (settings.usePolygonColorFunction) {
|
return functionValueCalculator(settings.usePolygonColorFunction, settings.polygonColorFunction,
|
||||||
return safeExecute(settings.polygonColorFunction, [this.data, this.dataSources, this.data.dsIndex]);
|
[this.data, this.dataSources, this.data.dsIndex], settings.polygonColor);
|
||||||
} else {
|
|
||||||
return settings.polygonColor;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,7 +18,7 @@ import L, { PolylineDecoratorOptions } from 'leaflet';
|
|||||||
import 'leaflet-polylinedecorator';
|
import 'leaflet-polylinedecorator';
|
||||||
|
|
||||||
import { FormattedData, PolylineSettings } from './map-models';
|
import { FormattedData, PolylineSettings } from './map-models';
|
||||||
import { safeExecute } from '@home/components/widget/lib/maps/maps-utils';
|
import { functionValueCalculator, safeExecute } from '@home/components/widget/lib/maps/maps-utils';
|
||||||
|
|
||||||
export class Polyline {
|
export class Polyline {
|
||||||
|
|
||||||
@ -72,15 +72,12 @@ export class Polyline {
|
|||||||
getPolyStyle(settings: PolylineSettings): L.PolylineOptions {
|
getPolyStyle(settings: PolylineSettings): L.PolylineOptions {
|
||||||
return {
|
return {
|
||||||
interactive: false,
|
interactive: false,
|
||||||
color: settings.useColorFunction ?
|
color: functionValueCalculator(settings.useColorFunction, settings.colorFunction,
|
||||||
safeExecute(settings.colorFunction,
|
[this.data, this.dataSources, this.data.dsIndex], settings.color),
|
||||||
[this.data, this.dataSources, this.data.dsIndex]) : settings.color,
|
opacity: functionValueCalculator(settings.useStrokeOpacityFunction, settings.strokeOpacityFunction,
|
||||||
opacity: settings.useStrokeOpacityFunction ?
|
[this.data, this.dataSources, this.data.dsIndex], settings.strokeOpacity),
|
||||||
safeExecute(settings.strokeOpacityFunction,
|
weight: functionValueCalculator(settings.useStrokeWeightFunction, settings.strokeWeightFunction,
|
||||||
[this.data, this.dataSources, this.data.dsIndex]) : settings.strokeOpacity,
|
[this.data, this.dataSources, this.data.dsIndex], settings.strokeWeight)
|
||||||
weight: settings.useStrokeWeightFunction ?
|
|
||||||
safeExecute(settings.strokeWeightFunction,
|
|
||||||
[this.data, this.dataSources, this.data.dsIndex]) : settings.strokeWeight,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user