typing & small fixes

This commit is contained in:
Artem Halushko 2020-05-22 16:00:46 +03:00
parent ea184ec5d1
commit 47c29f27e0
5 changed files with 18 additions and 16 deletions

View File

@ -14,7 +14,7 @@
/// limitations under the License. /// limitations under the License.
/// ///
import L, { FeatureGroup, LatLngBounds, LatLngTuple, markerClusterGroup, MarkerClusterGroupOptions } from 'leaflet'; import L, { FeatureGroup, LatLngBounds, LatLngTuple, markerClusterGroup, MarkerClusterGroupOptions, MarkerClusterGroup } from 'leaflet';
import 'leaflet-providers'; import 'leaflet-providers';
import 'leaflet.markercluster/dist/leaflet.markercluster'; import 'leaflet.markercluster/dist/leaflet.markercluster';
@ -45,9 +45,9 @@ export default abstract class LeafletMap {
options: UnitedMapSettings; options: UnitedMapSettings;
bounds: L.LatLngBounds; bounds: L.LatLngBounds;
datasources: FormattedData[]; datasources: FormattedData[];
markersCluster; markersCluster: MarkerClusterGroup;
points: FeatureGroup; points: FeatureGroup;
markersData = []; markersData: FormattedData[] = [];
protected constructor(public $container: HTMLElement, options: UnitedMapSettings) { protected constructor(public $container: HTMLElement, options: UnitedMapSettings) {
this.options = options; this.options = options;
@ -245,7 +245,7 @@ export default abstract class LeafletMap {
} }
// Markers // Markers
updateMarkers(markersData, callback?) { updateMarkers(markersData: FormattedData[], callback?) {
markersData.filter(mdata => !!this.convertPosition(mdata)).forEach(data => { markersData.filter(mdata => !!this.convertPosition(mdata)).forEach(data => {
if (data.rotationAngle || data.rotationAngle === 0) { if (data.rotationAngle || data.rotationAngle === 0) {
const currentImage = this.options.useMarkerImageFunction ? const currentImage = this.options.useMarkerImageFunction ?
@ -272,7 +272,7 @@ export default abstract class LeafletMap {
this.markersData = markersData; this.markersData = markersData;
} }
dragMarker = (e, data?) => { dragMarker = (e, data = {}) => {
if (e.type !== 'dragend') return; if (e.type !== 'dragend') return;
this.saveMarkerLocation({ ...data, ...this.convertToCustomFormat(e.target._latlng) }); this.saveMarkerLocation({ ...data, ...this.convertToCustomFormat(e.target._latlng) });
} }

View File

@ -34,7 +34,8 @@ import {
DatasourceType, DatasourceType,
JsonSettingsSchema, JsonSettingsSchema,
WidgetActionDescriptor, WidgetActionDescriptor,
widgetType widgetType,
DatasourceData
} from '@shared/models/widget.models'; } from '@shared/models/widget.models';
import { EntityId } from '@shared/models/id/entity-id'; import { EntityId } from '@shared/models/id/entity-id';
import { AttributeScope, DataKeyType, LatestTelemetry } from '@shared/models/telemetry/telemetry.models'; import { AttributeScope, DataKeyType, LatestTelemetry } from '@shared/models/telemetry/telemetry.models';
@ -83,7 +84,7 @@ export class MapWidgetController implements MapWidgetInterface {
map: LeafletMap; map: LeafletMap;
provider: MapProviders; provider: MapProviders;
schema: JsonSettingsSchema; schema: JsonSettingsSchema;
data; data: DatasourceData[];
settings: UnitedMapSettings; settings: UnitedMapSettings;
public static dataKeySettingsSchema(): object { public static dataKeySettingsSchema(): object {

View File

@ -22,8 +22,8 @@ import { isDefined } from '@core/utils';
export class Marker { export class Marker {
leafletMarker: L.Marker; leafletMarker: L.Marker;
tooltipOffset: [number, number]; tooltipOffset: L.LatLngTuple;
markerOffset: [number, number]; markerOffset: L.LatLngTuple;
tooltip: L.Popup; tooltip: L.Popup;
location: L.LatLngExpression; location: L.LatLngExpression;
data: FormattedData; data: FormattedData;

View File

@ -409,7 +409,10 @@ export const commonMapSettingsSchema =
condition: 'model.provider !== "image-map"' condition: 'model.provider !== "image-map"'
}, },
'draggableMarker', 'draggableMarker',
'disableScrollZooming', {
key: 'disableScrollZooming',
condition: 'model.provider !== "image-map"'
},
{ {
key: 'latKeyName', key: 'latKeyName',
condition: 'model.provider !== "image-map"' condition: 'model.provider !== "image-map"'

View File

@ -159,10 +159,8 @@ export class TripAnimationComponent implements OnInit, AfterViewInit {
calculateIntervals() { calculateIntervals() {
this.historicalData.forEach((dataSource, index) => { this.historicalData.forEach((dataSource, index) => {
this.minTime = dataSource[0]?.time || Infinity; this.minTime = dataSource[0]?.time || Infinity;
const minTimeFormat = this.minTime !== Infinity ? moment(this.minTime).format('YYYY-MM-DD HH:mm:ss') : '';
this.maxTime = dataSource[dataSource.length - 1]?.time || -Infinity; this.maxTime = dataSource[dataSource.length - 1]?.time || -Infinity;
const maxTimeFormat = this.maxTime !== -Infinity ? moment(this.maxTime).format('YYYY-MM-DD HH:mm:ss') : ''; this.interpolatedTimeData[index] = this.interpolateArray(dataSource);
this.interpolatedTimeData[index] = this.interpolateArray(dataSource, minTimeFormat, maxTimeFormat);
}); });
if(!this.activeTrip){ if(!this.activeTrip){
this.activeTrip = this.interpolatedTimeData.map(dataSource => dataSource[this.minTime]).filter(ds => ds)[0]; this.activeTrip = this.interpolatedTimeData.map(dataSource => dataSource[this.minTime]).filter(ds => ds)[0];
@ -194,7 +192,7 @@ export class TripAnimationComponent implements OnInit, AfterViewInit {
this.label = (parseWithTranslation.parseTemplate(labelText, data, true)); this.label = (parseWithTranslation.parseTemplate(labelText, data, true));
} }
interpolateArray(originData: FormattedData[], minTimeFormat?: string, maxTimeFormat?: string) { interpolateArray(originData: FormattedData[]) {
const result = {}; const result = {};
const latKeyName = this.settings.latKeyName; const latKeyName = this.settings.latKeyName;
const lngKeyName = this.settings.lngKeyName; const lngKeyName = this.settings.lngKeyName;
@ -203,8 +201,8 @@ export class TripAnimationComponent implements OnInit, AfterViewInit {
const normalizeTime = this.minTime + Math.ceil((currentTime - this.minTime) / this.normalizationStep) * this.normalizationStep; const normalizeTime = this.minTime + Math.ceil((currentTime - this.minTime) / this.normalizationStep) * this.normalizationStep;
result[normalizeTime] = { result[normalizeTime] = {
...data, ...data,
minTime: minTimeFormat, minTime: this.minTime !== Infinity ? moment(this.minTime).format('YYYY-MM-DD HH:mm:ss') : '',
maxTime: maxTimeFormat, maxTime: this.maxTime !== -Infinity ? moment(this.maxTime).format('YYYY-MM-DD HH:mm:ss') : '',
rotationAngle: this.settings.rotationAngle rotationAngle: this.settings.rotationAngle
}; };
} }