This commit is contained in:
Vladyslav_Prykhodko 2020-05-28 18:58:03 +03:00
commit a955df3923
5 changed files with 71 additions and 66 deletions

View File

@ -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;
@ -177,8 +178,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;

View File

@ -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)
}; };
} }

View File

@ -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);
@ -86,7 +87,7 @@ export class ImageMap extends LeafletMap {
} }
} }
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, {

View File

@ -644,7 +644,10 @@ export const markerClusteringSettingsSchema =
required: [] required: []
}, },
form: [ form: [
'useClusterMarkers', {
key: 'useClusterMarkers',
condition: 'model.provider !== "image-map"'
},
] ]
}; };
@ -844,7 +847,7 @@ 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',
@ -894,7 +897,7 @@ export const pointSchema =
}, },
'pointTooltipOnRightPanel', 'pointTooltipOnRightPanel',
] ]
}; };
export const mapProviderSchema = export const mapProviderSchema =
{ {

View File

@ -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;