some typing
This commit is contained in:
parent
507bd43a37
commit
9c85b76069
@ -27,11 +27,12 @@ import {
|
|||||||
export type GenericFunction = (data: FormattedData, dsData: FormattedData[], dsIndex: number) => string;
|
export type GenericFunction = (data: FormattedData, dsData: FormattedData[], dsIndex: number) => string;
|
||||||
export type MarkerImageFunction = (data: FormattedData, dsData: FormattedData[], dsIndex: number) => string;
|
export type MarkerImageFunction = (data: FormattedData, dsData: FormattedData[], dsIndex: number) => string;
|
||||||
export type GetTooltip = (point: FormattedData, setTooltip?: boolean) => string;
|
export type GetTooltip = (point: FormattedData, setTooltip?: boolean) => string;
|
||||||
|
export type PosFuncton = (origXPos, origYPos) => { x, y };
|
||||||
|
|
||||||
export type MapSettings = {
|
export type MapSettings = {
|
||||||
draggableMarker: boolean;
|
draggableMarker: boolean;
|
||||||
initCallback?: () => any;
|
initCallback?: () => any;
|
||||||
posFunction: (origXPos, origYPos) => { x, y };
|
posFunction: PosFuncton;
|
||||||
defaultZoomLevel?: number;
|
defaultZoomLevel?: number;
|
||||||
disableScrollZooming?: boolean;
|
disableScrollZooming?: boolean;
|
||||||
minZoomLevel?: number;
|
minZoomLevel?: number;
|
||||||
@ -176,8 +177,8 @@ export type TripAnimationSettings = {
|
|||||||
rotationAngle: number;
|
rotationAngle: number;
|
||||||
label: string;
|
label: string;
|
||||||
tooltipPattern: string;
|
tooltipPattern: string;
|
||||||
useTooltipFunction :boolean;
|
useTooltipFunction: boolean;
|
||||||
useLabelFunction:boolean;
|
useLabelFunction: boolean;
|
||||||
pointAsAnchorFunction: GenericFunction;
|
pointAsAnchorFunction: GenericFunction;
|
||||||
tooltipFunction: GenericFunction;
|
tooltipFunction: GenericFunction;
|
||||||
labelFunction: GenericFunction;
|
labelFunction: GenericFunction;
|
||||||
|
|||||||
@ -58,14 +58,14 @@ export function getRatio(firsMoment: number, secondMoment: number, intermediateM
|
|||||||
|
|
||||||
export function interpolateOnLineSegment(
|
export function interpolateOnLineSegment(
|
||||||
pointA: FormattedData,
|
pointA: FormattedData,
|
||||||
oointB: FormattedData,
|
pointB: FormattedData,
|
||||||
latKeyName: string,
|
latKeyName: string,
|
||||||
lngKeyName: string,
|
lngKeyName: string,
|
||||||
ratio: number
|
ratio: number
|
||||||
): { [key: string]: number } {
|
): { [key: string]: number } {
|
||||||
return {
|
return {
|
||||||
[latKeyName]: (pointA[latKeyName] + (oointB[latKeyName] - pointA[latKeyName]) * ratio),
|
[latKeyName]: (pointA[latKeyName] + (pointB[latKeyName] - pointA[latKeyName]) * ratio),
|
||||||
[lngKeyName]: (pointA[lngKeyName] + (oointB[lngKeyName] - pointA[lngKeyName]) * ratio)
|
[lngKeyName]: (pointA[lngKeyName] + (pointB[lngKeyName] - pointA[lngKeyName]) * ratio)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
import L, { LatLngLiteral, LatLngBounds, LatLngTuple } from 'leaflet';
|
import L, { LatLngLiteral, LatLngBounds, LatLngTuple } from 'leaflet';
|
||||||
import LeafletMap from '../leaflet-map';
|
import LeafletMap from '../leaflet-map';
|
||||||
import { UnitedMapSettings } from '../map-models';
|
import { UnitedMapSettings, PosFuncton } from '../map-models';
|
||||||
import { Observable } from 'rxjs';
|
import { Observable } from 'rxjs';
|
||||||
import { map, filter, switchMap } from 'rxjs/operators';
|
import { map, filter, switchMap } from 'rxjs/operators';
|
||||||
import { aspectCache, calculateNewPointCoordinate, parseFunction } from '@home/components/widget/lib/maps/maps-utils';
|
import { aspectCache, calculateNewPointCoordinate, parseFunction } from '@home/components/widget/lib/maps/maps-utils';
|
||||||
@ -25,16 +25,16 @@ const maxZoom = 4;// ?
|
|||||||
|
|
||||||
export class ImageMap extends LeafletMap {
|
export class ImageMap extends LeafletMap {
|
||||||
|
|
||||||
imageOverlay;
|
imageOverlay: L.ImageOverlay;
|
||||||
aspect = 0;
|
aspect = 0;
|
||||||
width = 0;
|
width = 0;
|
||||||
height = 0;
|
height = 0;
|
||||||
imageUrl;
|
imageUrl: string;
|
||||||
posFunction;
|
posFunction: PosFuncton;
|
||||||
|
|
||||||
constructor($container: HTMLElement, options: UnitedMapSettings) {
|
constructor($container: HTMLElement, options: UnitedMapSettings) {
|
||||||
super($container, options);
|
super($container, options);
|
||||||
this.posFunction = parseFunction(options.posFunction, ['origXPos', 'origYPos']) as ((origXPos, origYPos) => { x, y });
|
this.posFunction = parseFunction(options.posFunction, ['origXPos', 'origYPos']) as PosFuncton;
|
||||||
this.imageUrl = options.mapUrl;
|
this.imageUrl = options.mapUrl;
|
||||||
aspectCache(this.imageUrl).subscribe(aspect => {
|
aspectCache(this.imageUrl).subscribe(aspect => {
|
||||||
this.aspect = aspect;
|
this.aspect = aspect;
|
||||||
@ -50,11 +50,12 @@ export class ImageMap extends LeafletMap {
|
|||||||
return aspectCache(res);
|
return aspectCache(res);
|
||||||
})).subscribe(aspect => {
|
})).subscribe(aspect => {
|
||||||
this.aspect = aspect;
|
this.aspect = aspect;
|
||||||
|
console.log("ImageMap -> setImageAlias -> aspect", aspect)
|
||||||
this.onResize(true);
|
this.onResize(true);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
updateBounds(updateImage?, lastCenterPos?) {
|
updateBounds(updateImage?: boolean, lastCenterPos?) {
|
||||||
const w = this.width;
|
const w = this.width;
|
||||||
const h = this.height;
|
const h = this.height;
|
||||||
let southWest = this.pointToLatLng(0, h);
|
let southWest = this.pointToLatLng(0, h);
|
||||||
@ -81,12 +82,12 @@ export class ImageMap extends LeafletMap {
|
|||||||
lastCenterPos.y *= h;
|
lastCenterPos.y *= h;
|
||||||
const center = this.pointToLatLng(lastCenterPos.x, lastCenterPos.y);
|
const center = this.pointToLatLng(lastCenterPos.x, lastCenterPos.y);
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
this.map.panTo(center, { animate: false });
|
this.map.panTo(center, { animate: false });
|
||||||
}, 0);
|
}, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onResize(updateImage?) {
|
onResize(updateImage?: boolean) {
|
||||||
let width = this.$container.clientWidth;
|
let width = this.$container.clientWidth;
|
||||||
if (width > 0 && this.aspect) {
|
if (width > 0 && this.aspect) {
|
||||||
let height = width / this.aspect;
|
let height = width / this.aspect;
|
||||||
@ -117,7 +118,7 @@ export class ImageMap extends LeafletMap {
|
|||||||
|
|
||||||
fitBounds(bounds: LatLngBounds, padding?: LatLngTuple) { }
|
fitBounds(bounds: LatLngBounds, padding?: LatLngTuple) { }
|
||||||
|
|
||||||
initMap(updateImage?) {
|
initMap(updateImage?: boolean) {
|
||||||
if (!this.map && this.aspect > 0) {
|
if (!this.map && this.aspect > 0) {
|
||||||
const center = this.pointToLatLng(this.width / 2, this.height / 2);
|
const center = this.pointToLatLng(this.width / 2, this.height / 2);
|
||||||
this.map = L.map(this.$container, {
|
this.map = L.map(this.$container, {
|
||||||
@ -137,8 +138,8 @@ export class ImageMap extends LeafletMap {
|
|||||||
if (isNaN(expression[this.options.xPosKeyName]) || isNaN(expression[this.options.yPosKeyName])) return null;
|
if (isNaN(expression[this.options.xPosKeyName]) || isNaN(expression[this.options.yPosKeyName])) return null;
|
||||||
Object.assign(expression, this.posFunction(expression[this.options.xPosKeyName], expression[this.options.yPosKeyName]));
|
Object.assign(expression, this.posFunction(expression[this.options.xPosKeyName], expression[this.options.yPosKeyName]));
|
||||||
return this.pointToLatLng(
|
return this.pointToLatLng(
|
||||||
expression.x * this.width,
|
expression.x * this.width,
|
||||||
expression.y * this.height);
|
expression.y * this.height);
|
||||||
}
|
}
|
||||||
|
|
||||||
pointToLatLng(x, y): L.LatLng {
|
pointToLatLng(x, y): L.LatLng {
|
||||||
|
|||||||
@ -644,7 +644,10 @@ export const markerClusteringSettingsSchema =
|
|||||||
required: []
|
required: []
|
||||||
},
|
},
|
||||||
form: [
|
form: [
|
||||||
'useClusterMarkers',
|
{
|
||||||
|
key: 'useClusterMarkers',
|
||||||
|
condition: 'model.provider !== "image-map"'
|
||||||
|
},
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -844,57 +847,57 @@ export const pathSchema =
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const pointSchema =
|
export const pointSchema =
|
||||||
{
|
{
|
||||||
schema: {
|
schema: {
|
||||||
title: 'Trip Animation Path Configuration',
|
title: 'Trip Animation Path Configuration',
|
||||||
type: 'object',
|
type: 'object',
|
||||||
properties: {
|
properties: {
|
||||||
showPoints: {
|
showPoints: {
|
||||||
title: 'Show points',
|
title: 'Show points',
|
||||||
type: 'boolean',
|
type: 'boolean',
|
||||||
default: false
|
default: false
|
||||||
|
},
|
||||||
|
pointColor: {
|
||||||
|
title: 'Point color',
|
||||||
|
type: 'string'
|
||||||
|
},
|
||||||
|
pointSize: {
|
||||||
|
title: 'Point size (px)',
|
||||||
|
type: 'number',
|
||||||
|
default: 10
|
||||||
|
},
|
||||||
|
usePointAsAnchor: {
|
||||||
|
title: 'Use point as anchor',
|
||||||
|
type: 'boolean',
|
||||||
|
default: false
|
||||||
|
},
|
||||||
|
pointAsAnchorFunction: {
|
||||||
|
title: 'Point as anchor function: f(data, dsData, dsIndex)',
|
||||||
|
type: 'string'
|
||||||
|
},
|
||||||
|
pointTooltipOnRightPanel: {
|
||||||
|
title: 'Independant point tooltip',
|
||||||
|
type: 'boolean',
|
||||||
|
default: true
|
||||||
|
},
|
||||||
},
|
},
|
||||||
pointColor: {
|
required: []
|
||||||
title: 'Point color',
|
|
||||||
type: 'string'
|
|
||||||
},
|
|
||||||
pointSize: {
|
|
||||||
title: 'Point size (px)',
|
|
||||||
type: 'number',
|
|
||||||
default: 10
|
|
||||||
},
|
|
||||||
usePointAsAnchor: {
|
|
||||||
title: 'Use point as anchor',
|
|
||||||
type: 'boolean',
|
|
||||||
default: false
|
|
||||||
},
|
|
||||||
pointAsAnchorFunction: {
|
|
||||||
title: 'Point as anchor function: f(data, dsData, dsIndex)',
|
|
||||||
type: 'string'
|
|
||||||
},
|
|
||||||
pointTooltipOnRightPanel: {
|
|
||||||
title: 'Independant point tooltip',
|
|
||||||
type: 'boolean',
|
|
||||||
default: true
|
|
||||||
},
|
|
||||||
},
|
|
||||||
required: []
|
|
||||||
},
|
},
|
||||||
form: [
|
form: [
|
||||||
'showPoints',
|
'showPoints',
|
||||||
{
|
{
|
||||||
key: 'pointColor',
|
key: 'pointColor',
|
||||||
type: 'color'
|
type: 'color'
|
||||||
},
|
},
|
||||||
'pointSize',
|
'pointSize',
|
||||||
'usePointAsAnchor',
|
'usePointAsAnchor',
|
||||||
{
|
{
|
||||||
key: 'pointAsAnchorFunction',
|
key: 'pointAsAnchorFunction',
|
||||||
type: 'javascript'
|
type: 'javascript'
|
||||||
},
|
},
|
||||||
'pointTooltipOnRightPanel',
|
'pointTooltipOnRightPanel',
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
export const mapProviderSchema =
|
export const mapProviderSchema =
|
||||||
{
|
{
|
||||||
|
|||||||
@ -61,7 +61,7 @@ export class TripAnimationComponent implements OnInit, AfterViewInit {
|
|||||||
mainTooltip = '';
|
mainTooltip = '';
|
||||||
visibleTooltip = false;
|
visibleTooltip = false;
|
||||||
activeTrip: FormattedData;
|
activeTrip: FormattedData;
|
||||||
label;
|
label: string;
|
||||||
minTime: number;
|
minTime: number;
|
||||||
maxTime: number;
|
maxTime: number;
|
||||||
anchors: number[] = [];
|
anchors: number[] = [];
|
||||||
@ -173,7 +173,7 @@ export class TripAnimationComponent implements OnInit, AfterViewInit {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
calcTooltip = (point?: FormattedData) => {
|
calcTooltip = (point?: FormattedData): string => {
|
||||||
const data = point ? point : this.activeTrip;
|
const data = point ? point : this.activeTrip;
|
||||||
const tooltipPattern: string = this.settings.useTooltipFunction ?
|
const tooltipPattern: string = this.settings.useTooltipFunction ?
|
||||||
safeExecute(this.settings.tooltipFunction, [data, this.historicalData, point.dsIndex]) : this.settings.tooltipPattern;
|
safeExecute(this.settings.tooltipFunction, [data, this.historicalData, point.dsIndex]) : this.settings.tooltipPattern;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user