lint anf typed leaflet AddMarker

This commit is contained in:
Adsumus 2020-03-18 13:21:46 +02:00
parent 700a6fa1ff
commit 825d920e35
24 changed files with 3954 additions and 3905 deletions

5732
ui-ngx/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -18,7 +18,7 @@ const ruleNodeUiforwardPort = 8080;
const PROXY_CONFIG = { const PROXY_CONFIG = {
"/api": { "/api": {
"target": "http://localhost:8080", "target": "http://64.225.65.220:8080",
"secure": false, "secure": false,
}, },
"/static/rulenode": { "/static/rulenode": {
@ -26,7 +26,7 @@ const PROXY_CONFIG = {
"secure": false, "secure": false,
}, },
"/api/ws": { "/api/ws": {
"target": "ws://localhost:8080", "target": "ws://64.225.65.220:8080",
"ws": true, "ws": true,
}, },
}; };

View File

@ -18,7 +18,7 @@
export function initSchema() { export function initSchema() {
return { return {
schema: { schema: {
type: "object", type: 'object',
properties: {}, properties: {},
required: [] required: []
}, },
@ -29,8 +29,8 @@ export function initSchema() {
export function addGroupInfo(schema, title: string) { export function addGroupInfo(schema, title: string) {
schema.groupInfoes.push({ schema.groupInfoes.push({
"formIndex": schema.groupInfoes?.length || 0, formIndex: schema.groupInfoes?.length || 0,
"GroupTitle": title GroupTitle: title
}); });
} }
@ -66,7 +66,7 @@ export function addCondition(schema, condition: String) {
if (typeof element === 'string') { if (typeof element === 'string') {
return { return {
key: element, key: element,
condition: condition condition
} }
} }
if (typeof element == 'object') { if (typeof element == 'object') {

View File

@ -222,8 +222,8 @@ function scrollParents(node: Node): Node[] {
} }
function hashCode(str) { function hashCode(str) {
var hash = 0; let hash = 0;
var i, char; let i, char;
if (str.length == 0) return hash; if (str.length == 0) return hash;
for (i = 0; i < str.length; i++) { for (i = 0; i < str.length; i++) {
char = str.charCodeAt(i); char = str.charCodeAt(i);
@ -450,21 +450,22 @@ export function aspectCache(imageUrl: string): Observable<number> {
export function parseArray(input: any[]): any[] { export function parseArray(input: any[]): any[] {
let alliases: any = _(input).groupBy(el => el?.datasource?.aliasName).values().value(); const alliases: any = _(input).groupBy(el => el?.datasource?.aliasName).values().value();
return alliases.map((alliasArray, dsIndex) => return alliases.map((alliasArray, dsIndex) =>
alliasArray[0].data.map((el, i) => { alliasArray[0].data.map((el, i) => {
const obj = { const obj = {
aliasName: alliasArray[0]?.datasource?.aliasName, aliasName: alliasArray[0]?.datasource?.aliasName,
entityName: alliasArray[0]?.datasource?.entityName, entityName: alliasArray[0]?.datasource?.entityName,
$datasource: alliasArray[0]?.datasource, $datasource: alliasArray[0]?.datasource,
dsIndex: dsIndex, dsIndex,
time: el[0] time: el[0],
deviceType: null
}; };
alliasArray.forEach(el => { alliasArray.forEach(el => {
obj[el?.dataKey?.label] = el?.data[i][1]; obj[el?.dataKey?.label] = el?.data[i][1];
obj[el?.dataKey?.label + '|ts'] = el?.data[0][0]; obj[el?.dataKey?.label + '|ts'] = el?.data[0][0];
if (el?.dataKey?.label == 'type') { if (el?.dataKey?.label == 'type') {
obj['deviceType'] = el?.data[0][1]; obj.deviceType = el?.data[0][1];
} }
}); });
return obj; return obj;
@ -478,13 +479,14 @@ export function parseData(input: any[]): any[] {
aliasName: alliasArray[0]?.datasource?.aliasName, aliasName: alliasArray[0]?.datasource?.aliasName,
entityName: alliasArray[0]?.datasource?.entityName, entityName: alliasArray[0]?.datasource?.entityName,
$datasource: alliasArray[0]?.datasource, $datasource: alliasArray[0]?.datasource,
dsIndex: i dsIndex: i,
deviceType: null
}; };
alliasArray.forEach(el => { alliasArray.forEach(el => {
obj[el?.dataKey?.label] = el?.data[0][1]; obj[el?.dataKey?.label] = el?.data[0][1];
obj[el?.dataKey?.label + '|ts'] = el?.data[0][0]; obj[el?.dataKey?.label + '|ts'] = el?.data[0][0];
if (el?.dataKey?.label == 'type') { if (el?.dataKey?.label == 'type') {
obj['deviceType'] = el?.data[0][1]; obj.deviceType = el?.data[0][1];
} }
}); });
return obj; return obj;
@ -493,7 +495,7 @@ export function parseData(input: any[]): any[] {
export function safeExecute(func: Function, params = []) { export function safeExecute(func: Function, params = []) {
let res = null; let res = null;
if (func && typeof (func) == "function") { if (func && typeof (func) == 'function') {
try { try {
res = func(...params); res = func(...params);
} }
@ -523,17 +525,17 @@ export function parseTemplate(template: string, data: object) {
let res = ''; let res = '';
try { try {
let variables = ''; let variables = '';
let expressions = template const expressions = template
.match(/\{(.*?)\}/g) // find expressions .match(/\{(.*?)\}/g) // find expressions
.map(exp => exp.replace(/{|}/g, '')) // remove brackets .map(exp => exp.replace(/{|}/g, '')) // remove brackets
.map(exp => exp.split(':')) .map(exp => exp.split(':'))
.filter(arr => !!arr[1]) //filter expressions without format .filter(arr => !!arr[1]) // filter expressions without format
.reduce((res, current) => { .reduce((res, current) => {
res[current[0]] = current[1]; res[current[0]] = current[1];
return res; return res;
}, {}); }, {});
for (let key in data) { for (const key in data) {
if (!key.includes('|')) if (!key.includes('|'))
variables += `let ${key} = '${expressions[key] ? padValue(data[key], +expressions[key]) : data[key]}';`; variables += `let ${key} = '${expressions[key] ? padValue(data[key], +expressions[key]) : data[key]}';`;
} }

View File

@ -243,9 +243,9 @@ export class CanvasDigitalGauge extends BaseGauge {
options.neonColorsRange = []; options.neonColorsRange = [];
} }
for (let i = 0; i < options.levelColors.length; i++) { for (let i = 0; i < options.levelColors.length; i++) {
let levelColor: any = options.levelColors[i]; const levelColor: any = options.levelColors[i];
if (levelColor !== null) { if (levelColor !== null) {
let percentage = isColorProperty ? inc * i : CanvasDigitalGauge.normalizeValue(levelColor.value, options.minValue, options.maxValue); const percentage = isColorProperty ? inc * i : CanvasDigitalGauge.normalizeValue(levelColor.value, options.minValue, options.maxValue);
let tColor = tinycolor(isColorProperty ? levelColor : levelColor.color); let tColor = tinycolor(isColorProperty ? levelColor : levelColor.color);
options.colorsRange.push({ options.colorsRange.push({
pct: percentage, pct: percentage,
@ -274,7 +274,7 @@ export class CanvasDigitalGauge extends BaseGauge {
} }
static normalizeValue (value: number, min: number, max: number): number { static normalizeValue (value: number, min: number, max: number): number {
let normalValue = (value - min) / (max - min); const normalValue = (value - min) / (max - min);
if (normalValue <= 0) { if (normalValue <= 0) {
return 0; return 0;
} }

View File

@ -28,8 +28,8 @@ import { CanvasDigitalGauge, CanvasDigitalGaugeOptions } from '@home/components/
import { DatePipe } from '@angular/common'; import { DatePipe } from '@angular/common';
import {DataKey, Datasource, DatasourceType, JsonSettingsSchema, widgetType} from '@shared/models/widget.models'; import {DataKey, Datasource, DatasourceType, JsonSettingsSchema, widgetType} from '@shared/models/widget.models';
import GenericOptions = CanvasGauges.GenericOptions; import GenericOptions = CanvasGauges.GenericOptions;
import {IWidgetSubscription, WidgetSubscriptionOptions} from "@core/api/widget-api.models"; import {IWidgetSubscription, WidgetSubscriptionOptions} from '@core/api/widget-api.models';
import {DataKeyType} from "@shared/models/telemetry/telemetry.models"; import {DataKeyType} from '@shared/models/telemetry/telemetry.models';
const tinycolor = tinycolor_; const tinycolor = tinycolor_;
@ -202,55 +202,55 @@ export class TbCanvasDigitalGauge {
} }
settingLevelColorsSubscribe(options) { settingLevelColorsSubscribe(options) {
let levelColorsDatasource: Datasource[] = []; const levelColorsDatasource: Datasource[] = [];
let predefineLevelColors: colorLevelSetting[] = []; const predefineLevelColors: colorLevelSetting[] = [];
function setLevelColor(levelSetting, color) { function setLevelColor(levelSetting, color) {
if (levelSetting.valueSource === 'predefinedValue' && isFinite(levelSetting.value)) { if (levelSetting.valueSource === 'predefinedValue' && isFinite(levelSetting.value)) {
predefineLevelColors.push({ predefineLevelColors.push({
value: levelSetting.value, value: levelSetting.value,
color: color color
}) })
} else if (levelSetting.entityAlias && levelSetting.attribute) { } else if (levelSetting.entityAlias && levelSetting.attribute) {
let entityAliasId = this.ctx.aliasController.getEntityAliasId(levelSetting.entityAlias); const entityAliasId = this.ctx.aliasController.getEntityAliasId(levelSetting.entityAlias);
if (!entityAliasId) { if (!entityAliasId) {
return; return;
} }
let datasource = levelColorsDatasource.find((datasource) => { const datasource = levelColorsDatasource.find((datasource) => {
return datasource.entityAliasId === entityAliasId; return datasource.entityAliasId === entityAliasId;
}); });
let dataKey: DataKey = { const dataKey: DataKey = {
type: DataKeyType.attribute, type: DataKeyType.attribute,
name: levelSetting.attribute, name: levelSetting.attribute,
label: levelSetting.attribute, label: levelSetting.attribute,
settings: [{ settings: [{
color: color, color,
index: predefineLevelColors.length index: predefineLevelColors.length
}], }],
_hash: Math.random() _hash: Math.random()
}; };
if (datasource) { if (datasource) {
let findDataKey = datasource.dataKeys.find((dataKey) => { const findDataKey = datasource.dataKeys.find((dataKey) => {
return dataKey.name === levelSetting.attribute; return dataKey.name === levelSetting.attribute;
}); });
if (findDataKey) { if (findDataKey) {
findDataKey.settings.push({ findDataKey.settings.push({
color: color, color,
index: predefineLevelColors.length index: predefineLevelColors.length
}); });
} else { } else {
datasource.dataKeys.push(dataKey) datasource.dataKeys.push(dataKey)
} }
} else { } else {
let datasource: Datasource = { const datasource: Datasource = {
type: DatasourceType.entity, type: DatasourceType.entity,
name: levelSetting.entityAlias, name: levelSetting.entityAlias,
aliasName: levelSetting.entityAlias, aliasName: levelSetting.entityAlias,
entityAliasId: entityAliasId, entityAliasId,
dataKeys: [dataKey] dataKeys: [dataKey]
}; };
levelColorsDatasource.push(datasource); levelColorsDatasource.push(datasource);
@ -261,7 +261,7 @@ export class TbCanvasDigitalGauge {
} }
for (let i = 0; i < options.length; i++) { for (let i = 0; i < options.length; i++) {
let levelColor = options[i]; const levelColor = options[i];
if (levelColor.from) { if (levelColor.from) {
setLevelColor.call(this, levelColor.from, levelColor.color); setLevelColor.call(this, levelColor.from, levelColor.color);
} }
@ -282,20 +282,20 @@ export class TbCanvasDigitalGauge {
} }
subscribeLevelColorsAttributes(datasources: Datasource[]) { subscribeLevelColorsAttributes(datasources: Datasource[]) {
let TbCanvasDigitalGauge = this; const TbCanvasDigitalGauge = this;
let levelColorsSourcesSubscriptionOptions: WidgetSubscriptionOptions = { const levelColorsSourcesSubscriptionOptions: WidgetSubscriptionOptions = {
datasources: datasources, datasources,
useDashboardTimewindow: false, useDashboardTimewindow: false,
type: widgetType.latest, type: widgetType.latest,
callbacks: { callbacks: {
onDataUpdated: (subscription) => { onDataUpdated: (subscription) => {
for (let i = 0; i < subscription.data.length; i++) { for (let i = 0; i < subscription.data.length; i++) {
let keyData = subscription.data[i]; const keyData = subscription.data[i];
if (keyData && keyData.data && keyData.data[0]) { if (keyData && keyData.data && keyData.data[0]) {
let attrValue = keyData.data[0][1]; const attrValue = keyData.data[0][1];
if (isFinite(attrValue)) { if (isFinite(attrValue)) {
for (let i = 0; i < keyData.dataKey.settings.length; i++) { for (let i = 0; i < keyData.dataKey.settings.length; i++) {
let setting = keyData.dataKey.settings[i]; const setting = keyData.dataKey.settings[i];
this.localSettings.levelColors[setting.index] = { this.localSettings.levelColors[setting.index] = {
value: attrValue, value: attrValue,
color: setting.color color: setting.color

View File

@ -0,0 +1,12 @@
import * as L from 'leaflet'
declare module 'leaflet' {
namespace Control {
class AddMarker extends L.Control { }
}
namespace control {
function addMarker(options): Control.AddMarker;
}
}

View File

@ -14,7 +14,8 @@
/// limitations under the License. /// limitations under the License.
/// ///
import * as L from 'leaflet'; import L from 'leaflet';
import './add-marker';
import 'leaflet-providers'; import 'leaflet-providers';
import 'leaflet.markercluster/dist/MarkerCluster.css' import 'leaflet.markercluster/dist/MarkerCluster.css'
@ -67,34 +68,34 @@ export default abstract class LeafletMap {
addMarkerControl() { addMarkerControl() {
if (this.options.draggebleMarker) if (this.options.draggebleMarker)
L.Control['AddMarker'] = L.Control.extend({ L.Control.AddMarker = L.Control.extend({
onAdd: function (map) { onAdd (map) {
let img = L.DomUtil.create('img') as any; const img = L.DomUtil.create('img') as any;
img.src = `assets/add_location.svg`; img.src = `assets/add_location.svg`;
img.style.width = '32px'; img.style.width = '32px';
img.style.height = '32px'; img.style.height = '32px';
img.onclick = this.dragMarker; img.onclick = this.dragMarker;
return img; return img;
}, },
addHooks: function () { addHooks () {
L.DomEvent.on(window as any, 'onclick', this.enableDragMode, this); L.DomEvent.on(window as any, 'onclick', this.enableDragMode, this);
}, },
onRemove: function (map) { onRemove (map) {
}, },
dragMarker: ($event) => { dragMarker: ($event) => {
this.dragMode = !this.dragMode; this.dragMode = !this.dragMode;
} }
}); } as any);
L.control['addmarker'] = function (opts) { L.control.addMarker = function (opts) {
return new L.Control['AddMarker'](opts); return new L.Control.AddMarker(opts);
} }
L.control['addmarker']({ position: 'topright' }).addTo(this.map); L.control.addMarker({ position: 'topright' }).addTo(this.map);
} }
inited() {///!!!! /*inited() {/// !!!!
return !!this.map; return !!this.map;
} }*/
public setMap(map: L.Map) { public setMap(map: L.Map) {
this.map = map; this.map = map;
@ -158,7 +159,7 @@ export default abstract class LeafletMap {
} }
} }
//Markers // Markers
updateMarkers(markersData) { updateMarkers(markersData) {
markersData.forEach(data => { markersData.forEach(data => {
if (data.rotationAngle) { if (data.rotationAngle) {
@ -188,7 +189,7 @@ export default abstract class LeafletMap {
private updateMarker(key, data, dataSources, settings: MarkerSettings) { private updateMarker(key, data, dataSources, settings: MarkerSettings) {
const marker: Marker = this.markers.get(key); const marker: Marker = this.markers.get(key);
let location = this.convertPosition(data) const location = this.convertPosition(data)
if (!location.equals(marker.location)) { if (!location.equals(marker.location)) {
marker.updateMarkerPosition(location); marker.updateMarkerPosition(location);
} }
@ -203,12 +204,12 @@ export default abstract class LeafletMap {
} }
//polyline // polyline
updatePolylines(polyData: Array<Array<any>>) { updatePolylines(polyData: Array<Array<any>>) {
polyData.forEach(data => { polyData.forEach(data => {
if (data.length) { if (data.length) {
let dataSource = polyData.map(arr => arr[0]); const dataSource = polyData.map(arr => arr[0]);
if (this.poly) { if (this.poly) {
this.updatePolyline(data, dataSource, this.options); this.updatePolyline(data, dataSource, this.options);
} }
@ -237,7 +238,7 @@ export default abstract class LeafletMap {
}); });
} }
//polygon // polygon
updatePolygons(polyData: Array<Array<any>>) { updatePolygons(polyData: Array<Array<any>>) {
polyData.forEach((data: any) => { polyData.forEach((data: any) => {

View File

@ -14,7 +14,7 @@
/// limitations under the License. /// limitations under the License.
/// ///
import { MapProviders, MapOptions } from "./map-models"; import { MapProviders, MapOptions } from './map-models';
import LeafletMap from './leaflet-map'; import LeafletMap from './leaflet-map';
import { import {
openstreetMapSettingsSchema, openstreetMapSettingsSchema,
@ -39,12 +39,6 @@ import { AttributeService } from '@app/core/public-api';
export class MapWidgetController implements MapWidgetInterface { export class MapWidgetController implements MapWidgetInterface {
map: LeafletMap;
provider: MapProviders;
schema;
data;
settings;
constructor(public mapProvider: MapProviders, private drawRoutes, public ctx: WidgetContext, $element) { constructor(public mapProvider: MapProviders, private drawRoutes, public ctx: WidgetContext, $element) {
if (this.map) { if (this.map) {
this.map.map.remove(); this.map.map.remove();
@ -57,7 +51,7 @@ export class MapWidgetController implements MapWidgetInterface {
} }
this.settings = this.initSettings(ctx.settings); this.settings = this.initSettings(ctx.settings);
let MapClass = providerSets[this.provider]?.MapClass; const MapClass = providerSets[this.provider]?.MapClass;
if (!MapClass) { if (!MapClass) {
return; return;
} }
@ -65,13 +59,64 @@ export class MapWidgetController implements MapWidgetInterface {
this.map.saveMarkerLocation = this.setMarkerLocation; this.map.saveMarkerLocation = this.setMarkerLocation;
} }
map: LeafletMap;
provider: MapProviders;
schema;
data;
settings;
public static dataKeySettingsSchema(): Object {
return {};
}
public static getProvidersSchema() {
return mergeSchemes([mapProviderSchema,
...Object.values(providerSets)?.map(
setting => addCondition(setting?.schema, `model.provider === '${setting.name}'`))]);
}
public static settingsSchema(mapProvider, drawRoutes): Object {
const schema = initSchema();
addToSchema(schema, this.getProvidersSchema());
addGroupInfo(schema, 'Map Provider Settings');
addToSchema(schema, commonMapSettingsSchema);
addGroupInfo(schema, 'Common Map Settings');
if (drawRoutes) {
addToSchema(schema, routeMapSettingsSchema);
addGroupInfo(schema, 'Route Map Settings');
} else if (mapProvider !== 'image-map') {
const clusteringSchema = mergeSchemes([markerClusteringSettingsSchemaLeaflet, markerClusteringSettingsSchema])
addToSchema(schema, clusteringSchema);
addGroupInfo(schema, 'Markers Clustering Settings');
}
return schema;
}
public static actionSources(): Object {
return {
markerClick: {
name: 'widget-action.marker-click',
multiple: false
},
polygonClick: {
name: 'widget-action.polygon-click',
multiple: false
},
tooltipAction: {
name: 'widget-action.tooltip-tag-action',
multiple: true
}
};
}
onInit() { onInit() {
} }
setMarkerLocation = (e) => { setMarkerLocation = (e) => {
let s = this.ctx.$injector.get(AttributeService); const s = this.ctx.$injector.get(AttributeService);
console.log("MapWidgetController -> setMarkerLocation -> s", s, s.saveEntityAttributes) console.log('MapWidgetController -> setMarkerLocation -> s', s, s.saveEntityAttributes)
let attributeService = this.ctx.$scope.$injector.get(this.ctx.servicesMap.get('attributeService')); const attributeService = this.ctx.$scope.$injector.get(this.ctx.servicesMap.get('attributeService'));
forkJoin( forkJoin(
this.data.filter(data => !!e[data.dataKey.name]) this.data.filter(data => !!e[data.dataKey.name])
.map(data => { .map(data => {
@ -88,7 +133,7 @@ export class MapWidgetController implements MapWidgetInterface {
}] }]
); );
})).subscribe(res => { })).subscribe(res => {
console.log("MapWidgetController -> setMarkerLocation -> res", res) console.log('MapWidgetController -> setMarkerLocation -> res', res)
}); });
} }
@ -114,7 +159,7 @@ export class MapWidgetController implements MapWidgetInterface {
markerImageFunction: parseFunction(settings.markerImageFunction, ['data', 'images', 'dsData', 'dsIndex']), markerImageFunction: parseFunction(settings.markerImageFunction, ['data', 'images', 'dsData', 'dsIndex']),
labelColor: this.ctx.widgetConfig.color, labelColor: this.ctx.widgetConfig.color,
tooltipPattern: settings.tooltipPattern || tooltipPattern: settings.tooltipPattern ||
"<b>${entityName}</b><br/><br/><b>Latitude:</b> ${" + settings.latKeyName + ":7}<br/><b>Longitude:</b> ${" + settings.lngKeyName + ":7}", '<b>${entityName}</b><br/><br/><b>Latitude:</b> ${' + settings.latKeyName + ':7}<br/><b>Longitude:</b> ${' + settings.lngKeyName + ':7}',
defaultCenterPosition: getDefCenterPosition(settings?.defaultCenterPosition), defaultCenterPosition: getDefCenterPosition(settings?.defaultCenterPosition),
useDraggableMarker: true, useDraggableMarker: true,
currentImage: (settings.useMarkerImage && settings.markerImage?.length) ? { currentImage: (settings.useMarkerImage && settings.markerImage?.length) ? {
@ -138,7 +183,7 @@ export class MapWidgetController implements MapWidgetInterface {
} }
onResize() { onResize() {
this.map.onResize();//not work this.map.onResize();// not work
} }
resize() { resize() {
@ -146,51 +191,6 @@ export class MapWidgetController implements MapWidgetInterface {
this.map.onResize(); this.map.onResize();
} }
public static dataKeySettingsSchema(): Object {
return {};
}
public static getProvidersSchema() {
return mergeSchemes([mapProviderSchema,
...Object.values(providerSets)?.map(
setting => addCondition(setting?.schema, `model.provider === '${setting.name}'`))]);
}
public static settingsSchema(mapProvider, drawRoutes): Object {
let schema = initSchema();
addToSchema(schema, this.getProvidersSchema());
addGroupInfo(schema, "Map Provider Settings");
addToSchema(schema, commonMapSettingsSchema);
addGroupInfo(schema, "Common Map Settings");
if (drawRoutes) {
addToSchema(schema, routeMapSettingsSchema);
addGroupInfo(schema, "Route Map Settings");
} else if (mapProvider !== 'image-map') {
let clusteringSchema = mergeSchemes([markerClusteringSettingsSchemaLeaflet, markerClusteringSettingsSchema])
addToSchema(schema, clusteringSchema);
addGroupInfo(schema, "Markers Clustering Settings");
}
return schema;
}
public static actionSources(): Object {
return {
'markerClick': {
name: 'widget-action.marker-click',
multiple: false
},
'polygonClick': {
name: 'widget-action.polygon-click',
multiple: false
},
'tooltipAction': {
name: 'widget-action.tooltip-tag-action',
multiple: true
}
};
}
onDestroy() { onDestroy() {
} }
} }
@ -202,27 +202,27 @@ const providerSets = {
'openstreet-map': { 'openstreet-map': {
MapClass: OpenStreetMap, MapClass: OpenStreetMap,
schema: openstreetMapSettingsSchema, schema: openstreetMapSettingsSchema,
name: "openstreet-map", name: 'openstreet-map',
}, },
'tencent-map': { 'tencent-map': {
MapClass: TencentMap, MapClass: TencentMap,
schema: tencentMapSettingsSchema, schema: tencentMapSettingsSchema,
name: "tencent-map" name: 'tencent-map'
}, },
'google-map': { 'google-map': {
MapClass: GoogleMap, MapClass: GoogleMap,
schema: googleMapSettingsSchema, schema: googleMapSettingsSchema,
name: "google-map" name: 'google-map'
}, },
'here': { here: {
MapClass: HEREMap, MapClass: HEREMap,
schema: hereMapSettingsSchema, schema: hereMapSettingsSchema,
name: "here" name: 'here'
}, },
'image-map': { 'image-map': {
MapClass: ImageMap, MapClass: ImageMap,
schema: imageMapSettingsSchema, schema: imageMapSettingsSchema,
name: "image-map" name: 'image-map'
} }
} }
@ -235,16 +235,16 @@ const defaultSettings = {
lngKeyName: 'longitude', lngKeyName: 'longitude',
polygonKeyName: 'coordinates', polygonKeyName: 'coordinates',
showLabel: false, showLabel: false,
label: "${entityName}", label: '${entityName}',
showTooltip: false, showTooltip: false,
useDefaultCenterPosition: false, useDefaultCenterPosition: false,
showTooltipAction: "click", showTooltipAction: 'click',
autocloseTooltip: false, autocloseTooltip: false,
showPolygon: true, showPolygon: true,
labelColor: '#000000', labelColor: '#000000',
color: "#FE7569", color: '#FE7569',
polygonColor: "#0000ff", polygonColor: '#0000ff',
polygonStrokeColor: "#fe0001", polygonStrokeColor: '#fe0001',
polygonOpacity: 0.5, polygonOpacity: 0.5,
polygonStrokeOpacity: 1, polygonStrokeOpacity: 1,
polygonStrokeWeight: 1, polygonStrokeWeight: 1,

View File

@ -30,7 +30,7 @@ export class Marker {
dataSources; dataSources;
constructor(private map: L.Map, location: L.LatLngExpression, public settings: MarkerSettings, data?, dataSources?, onClickListener?, onDragendListener?) { constructor(private map: L.Map, location: L.LatLngExpression, public settings: MarkerSettings, data?, dataSources?, onClickListener?, onDragendListener?) {
//this.map = map; // this.map = map;
this.location = location; this.location = location;
this.setDataSources(data, dataSources); this.setDataSources(data, dataSources);
this.leafletMarker = L.marker(location, { this.leafletMarker = L.marker(location, {
@ -108,7 +108,7 @@ export class Marker {
return; return;
} }
let currentImage = this.settings.useMarkerImageFunction ? const currentImage = this.settings.useMarkerImageFunction ?
safeExecute(this.settings.markerImageFunction, safeExecute(this.settings.markerImageFunction,
[this.data, this.settings.markerImages, this.dataSources, this.data.dsIndex]) : this.settings.currentImage; [this.data, this.settings.markerImages, this.dataSources, this.data.dsIndex]) : this.settings.currentImage;
@ -117,8 +117,8 @@ export class Marker {
aspectCache(currentImage.url).subscribe( aspectCache(currentImage.url).subscribe(
(aspect) => { (aspect) => {
if (aspect) { if (aspect) {
var width; let width;
var height; let height;
if (aspect > 1) { if (aspect > 1) {
width = currentImage.size; width = currentImage.size;
height = currentImage.size / aspect; height = currentImage.size / aspect;
@ -126,15 +126,15 @@ export class Marker {
width = currentImage.size * aspect; width = currentImage.size * aspect;
height = currentImage.size; height = currentImage.size;
} }
var icon = L.icon({ const icon = L.icon({
iconUrl: currentImage.url, iconUrl: currentImage.url,
iconSize: [width, height], iconSize: [width, height],
iconAnchor: [width / 2, height], iconAnchor: [width / 2, height],
popupAnchor: [0, -height] popupAnchor: [0, -height]
}); });
var iconInfo = { const iconInfo = {
size: [width, height], size: [width, height],
icon: icon icon
}; };
onMarkerIconReady(iconInfo); onMarkerIconReady(iconInfo);
} else { } else {
@ -148,8 +148,8 @@ export class Marker {
} }
createDefaultMarkerIcon(color, onMarkerIconReady) { createDefaultMarkerIcon(color, onMarkerIconReady) {
var pinColor = color.substr(1); const pinColor = color.substr(1);
var icon = L.icon({ const icon = L.icon({
iconUrl: 'https://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=%E2%80%A2|' + pinColor, iconUrl: 'https://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=%E2%80%A2|' + pinColor,
iconSize: [21, 34], iconSize: [21, 34],
iconAnchor: [10, 34], iconAnchor: [10, 34],
@ -158,9 +158,9 @@ export class Marker {
shadowSize: [40, 37], shadowSize: [40, 37],
shadowAnchor: [12, 35] shadowAnchor: [12, 35]
}); });
var iconInfo = { const iconInfo = {
size: [21, 34], size: [21, 34],
icon: icon icon
}; };
onMarkerIconReady(iconInfo); onMarkerIconReady(iconInfo);
} }

View File

@ -45,10 +45,10 @@ export class Polygon {
} }
updatePolygonColor(settings, color) { updatePolygonColor(settings, color) {
let style = { const style = {
fill: true, fill: true,
fillColor: color, fillColor: color,
color: color, color,
weight: settings.polygonStrokeWeight, weight: settings.polygonStrokeWeight,
fillOpacity: settings.polygonOpacity, fillOpacity: settings.polygonOpacity,
opacity: settings.polygonStrokeOpacity opacity: settings.polygonStrokeOpacity

View File

@ -20,7 +20,7 @@ import LeafletMap from '../leaflet-map';
import { MapOptions } from '../map-models'; import { MapOptions } from '../map-models';
import 'leaflet.gridlayer.googlemutant'; import 'leaflet.gridlayer.googlemutant';
var googleLoaded = false; let googleLoaded = false;
export class GoogleMap extends LeafletMap { export class GoogleMap extends LeafletMap {
@ -29,7 +29,7 @@ export class GoogleMap extends LeafletMap {
super($container, options); super($container, options);
this.loadGoogle(() => { this.loadGoogle(() => {
const map = L.map($container).setView(options?.defaultCenterPosition, options?.defaultZoomLevel); const map = L.map($container).setView(options?.defaultCenterPosition, options?.defaultZoomLevel);
var roads = (L.gridLayer as any).googleMutant({ const roads = (L.gridLayer as any).googleMutant({
type: options?.gmDefaultMapType || 'roadmap' type: options?.gmDefaultMapType || 'roadmap'
}).addTo(map); }).addTo(map);
super.setMap(map); super.setMap(map);
@ -43,7 +43,7 @@ export class GoogleMap extends LeafletMap {
} }
else { else {
googleLoaded = true; googleLoaded = true;
let script = document.createElement('script'); const script = document.createElement('script');
script.onload = () => { script.onload = () => {
callback(); callback();
} }

View File

@ -20,15 +20,15 @@ import { MapOptions } from '../map-models';
export class HEREMap extends LeafletMap { export class HEREMap extends LeafletMap {
constructor($container, options: MapOptions) { constructor($container, options: MapOptions) {
console.log("HEREMap -> constructor -> options", options) console.log('HEREMap -> constructor -> options', options)
const defaultCredentials = const defaultCredentials =
{ {
app_id: "AhM6TzD9ThyK78CT3ptx", app_id: 'AhM6TzD9ThyK78CT3ptx',
app_code: "p6NPiITB3Vv0GMUFnkLOOg" app_code: 'p6NPiITB3Vv0GMUFnkLOOg'
} }
super($container, options); super($container, options);
const map = L.map($container).setView(options?.defaultCenterPosition, options?.defaultZoomLevel); const map = L.map($container).setView(options?.defaultCenterPosition, options?.defaultZoomLevel);
var tileLayer = (L.tileLayer as any).provider(options.mapProvider || "HERE.normalDay", options.credentials || defaultCredentials); const tileLayer = (L.tileLayer as any).provider(options.mapProvider || 'HERE.normalDay', options.credentials || defaultCredentials);
tileLayer.addTo(map); tileLayer.addTo(map);
super.setMap(map); super.setMap(map);
super.initSettings(options); super.initSettings(options);

View File

@ -19,7 +19,7 @@ import LeafletMap from '../leaflet-map';
import { MapOptions } from '../map-models'; import { MapOptions } from '../map-models';
import { aspectCache } from '@app/core/utils'; import { aspectCache } from '@app/core/utils';
const maxZoom = 4;//? const maxZoom = 4;// ?
export class ImageMap extends LeafletMap { export class ImageMap extends LeafletMap {
@ -102,12 +102,12 @@ export class ImageMap extends LeafletMap {
initMap(updateImage?) { initMap(updateImage?) {
if (!this.map && this.aspect > 0) { if (!this.map && this.aspect > 0) {
var 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, {
minZoom: 1, minZoom: 1,
maxZoom: maxZoom, maxZoom,
scrollWheelZoom: !this.options.disableScrollZooming, scrollWheelZoom: !this.options.disableScrollZooming,
center: center, center,
zoom: 1, zoom: 1,
crs: L.CRS.Simple, crs: L.CRS.Simple,
attributionControl: false attributionControl: false

View File

@ -22,7 +22,7 @@ export class OpenStreetMap extends LeafletMap {
constructor($container, options: MapOptions) { constructor($container, options: MapOptions) {
super($container, options); super($container, options);
const map = L.map($container).setView(options?.defaultCenterPosition, options?.defaultZoomLevel); const map = L.map($container).setView(options?.defaultCenterPosition, options?.defaultZoomLevel);
var tileLayer = (L.tileLayer as any).provider("OpenStreetMap.Mapnik"); const tileLayer = (L.tileLayer as any).provider('OpenStreetMap.Mapnik');
tileLayer.addTo(map); tileLayer.addTo(map);
super.setMap(map); super.setMap(map);
super.initSettings(options); super.initSettings(options);

View File

@ -16,7 +16,7 @@
import L from 'leaflet'; import L from 'leaflet';
import _ from 'lodash'; import _ from 'lodash';
import tinycolor from "tinycolor2"; import tinycolor from 'tinycolor2';
import { interpolateOnPointSegment } from 'leaflet-geometryutil'; import { interpolateOnPointSegment } from 'leaflet-geometryutil';
import { Component, OnInit, Input, ViewChild, AfterViewInit, ChangeDetectorRef, SecurityContext } from '@angular/core'; import { Component, OnInit, Input, ViewChild, AfterViewInit, ChangeDetectorRef, SecurityContext } from '@angular/core';
@ -27,6 +27,7 @@ import { initSchema, addToSchema, addGroupInfo } from '@app/core/schema-utils';
import { tripAnimationSchema } from '../lib/maps/schemes'; import { tripAnimationSchema } from '../lib/maps/schemes';
import { DomSanitizer } from '@angular/platform-browser'; import { DomSanitizer } from '@angular/platform-browser';
import { WidgetConfig } from '@app/shared/public-api'; import { WidgetConfig } from '@app/shared/public-api';
import { WidgetContext } from '@app/modules/home/models/widget-component.models';
@Component({ @Component({
@ -36,7 +37,9 @@ import { WidgetConfig } from '@app/shared/public-api';
}) })
export class TripAnimationComponent implements OnInit, AfterViewInit { export class TripAnimationComponent implements OnInit, AfterViewInit {
@Input() ctx: WidgetConfig; constructor(private cd: ChangeDetectorRef,private sanitizer: DomSanitizer) { }
@Input() ctx: WidgetContext;
@ViewChild('map') mapContainer; @ViewChild('map') mapContainer;
@ -51,7 +54,14 @@ export class TripAnimationComponent implements OnInit, AfterViewInit {
visibleTooltip = false; visibleTooltip = false;
activeTrip; activeTrip;
constructor(private cd: ChangeDetectorRef,private sanitizer: DomSanitizer) { } static getSettingsSchema() {
const schema = initSchema();
addToSchema(schema, TbMapWidgetV2.getProvidersSchema());
addGroupInfo(schema, 'Map Provider Settings');
addToSchema(schema, tripAnimationSchema);
addGroupInfo(schema, 'Trip Animation Settings');
return schema;
}
ngOnInit(): void { ngOnInit(): void {
this.widgetConfig = this.ctx.widgetConfig; this.widgetConfig = this.ctx.widgetConfig;
@ -63,7 +73,7 @@ export class TripAnimationComponent implements OnInit, AfterViewInit {
rotationAngle: 0 rotationAngle: 0
} }
this.settings = { ...settings, ...this.ctx.settings }; this.settings = { ...settings, ...this.ctx.settings };
let subscription = this.ctx.subscriptions[Object.keys(this.ctx.subscriptions)[0]]; const subscription = this.ctx.subscriptions[Object.keys(this.ctx.subscriptions)[0]];
if (subscription) subscription.callbacks.onDataUpdated = (updated) => { if (subscription) subscription.callbacks.onDataUpdated = (updated) => {
this.historicalData = parseArray(this.ctx.data); this.historicalData = parseArray(this.ctx.data);
this.activeTrip = this.historicalData[0][0]; this.activeTrip = this.historicalData[0][0];
@ -75,7 +85,7 @@ export class TripAnimationComponent implements OnInit, AfterViewInit {
} }
ngAfterViewInit() { ngAfterViewInit() {
let ctxCopy = _.cloneDeep(this.ctx); const ctxCopy: WidgetContext = _.cloneDeep(this.ctx);
ctxCopy.settings.showLabel = false; ctxCopy.settings.showLabel = false;
ctxCopy.settings.showTooltip = false; ctxCopy.settings.showTooltip = false;
this.mapWidget = new MapWidgetController(MapProviders.openstreet, false, ctxCopy, this.mapContainer.nativeElement); this.mapWidget = new MapWidgetController(MapProviders.openstreet, false, ctxCopy, this.mapContainer.nativeElement);
@ -104,7 +114,7 @@ export class TripAnimationComponent implements OnInit, AfterViewInit {
showHideTooltip() { showHideTooltip() {
console.log(this.activeTrip); console.log(this.activeTrip);
let tooltipText: string = this.settings.useTooltipFunction ? safeExecute(this.settings.tooolTipFunction) : const tooltipText: string = this.settings.useTooltipFunction ? safeExecute(this.settings.tooolTipFunction) :
// this.mainTooltip = this.sanitizer.sanitize(SecurityContext.HTML, parseTemplate(tooltipText, this.activeTrip)) // this.mainTooltip = this.sanitizer.sanitize(SecurityContext.HTML, parseTemplate(tooltipText, this.activeTrip))
this.visibleTooltip = !this.visibleTooltip; this.visibleTooltip = !this.visibleTooltip;
} }
@ -141,16 +151,6 @@ export class TripAnimationComponent implements OnInit, AfterViewInit {
j++; j++;
} }
return result; return result;
}; }}
static getSettingsSchema() {
let schema = initSchema();
addToSchema(schema, TbMapWidgetV2.getProvidersSchema());
addGroupInfo(schema, "Map Provider Settings");
addToSchema(schema, tripAnimationSchema);
addGroupInfo(schema, "Trip Animation Settings");
return schema;
}
}
export let TbTripAnimationWidget = TripAnimationComponent; export let TbTripAnimationWidget = TripAnimationComponent;

View File

@ -14,13 +14,13 @@
/// limitations under the License. /// limitations under the License.
/// ///
import {Component, Inject, OnInit} from "@angular/core"; import {Component, Inject, OnInit} from '@angular/core';
import {DialogComponent} from "@shared/components/dialog.component"; import {DialogComponent} from '@shared/components/dialog.component';
import {Store} from "@ngrx/store"; import {Store} from '@ngrx/store';
import {AppState} from "@core/core.state"; import {AppState} from '@core/core.state';
import {Router} from "@angular/router"; import {Router} from '@angular/router';
import {MAT_DIALOG_DATA, MatDialogRef} from "@angular/material/dialog"; import {MAT_DIALOG_DATA, MatDialogRef} from '@angular/material/dialog';
import {FormBuilder, FormGroup} from "@angular/forms"; import {FormBuilder, FormGroup} from '@angular/forms';
export interface JsonObjectEdittDialogData { export interface JsonObjectEdittDialogData {
jsonValue: Object; jsonValue: Object;

View File

@ -14,7 +14,7 @@
/// limitations under the License. /// limitations under the License.
/// ///
import {Directive, ElementRef, forwardRef, HostListener, Renderer2, SkipSelf} from "@angular/core"; import {Directive, ElementRef, forwardRef, HostListener, Renderer2, SkipSelf} from '@angular/core';
import { import {
ControlValueAccessor, ControlValueAccessor,
FormControl, FormGroupDirective, FormControl, FormGroupDirective,
@ -22,8 +22,8 @@ import {
NG_VALUE_ACCESSOR, NgForm, NG_VALUE_ACCESSOR, NgForm,
ValidationErrors, ValidationErrors,
Validator Validator
} from "@angular/forms"; } from '@angular/forms';
import {ErrorStateMatcher} from "@angular/material/core"; import {ErrorStateMatcher} from '@angular/material/core';
@Directive({ @Directive({
selector: '[tb-json-to-string]', selector: '[tb-json-to-string]',

View File

@ -17,12 +17,12 @@
import { Component, forwardRef, Input, OnInit, ViewChild } from '@angular/core'; import { Component, forwardRef, Input, OnInit, ViewChild } from '@angular/core';
import { ControlValueAccessor, NG_VALUE_ACCESSOR, NgForm } from '@angular/forms'; import { ControlValueAccessor, NG_VALUE_ACCESSOR, NgForm } from '@angular/forms';
import { ValueType, valueTypesMap } from '@shared/models/constants'; import { ValueType, valueTypesMap } from '@shared/models/constants';
import { isObject } from "@core/utils"; import { isObject } from '@core/utils';
import { MatDialog } from "@angular/material/dialog"; import { MatDialog } from '@angular/material/dialog';
import { import {
JsonObjectEditDialogComponent, JsonObjectEditDialogComponent,
JsonObjectEdittDialogData JsonObjectEdittDialogData
} from "@shared/components/dialog/json-object-edit-dialog.component"; } from '@shared/components/dialog/json-object-edit-dialog.component';
@Component({ @Component({
selector: 'tb-value-input', selector: 'tb-value-input',
@ -79,7 +79,7 @@ export class ValueInputComponent implements OnInit, ControlValueAccessor {
(res) => { (res) => {
if (res) { if (res) {
this.modelValue = res; this.modelValue = res;
this.inputForm.control.patchValue({'value': this.modelValue}); this.inputForm.control.patchValue({value: this.modelValue});
} }
} }
); );

View File

@ -15,7 +15,7 @@
/// ///
import {Pipe, PipeTransform} from '@angular/core'; import {Pipe, PipeTransform} from '@angular/core';
import {isObject, isNumber} from "@core/utils"; import {isObject, isNumber} from '@core/utils';
@Pipe({name: 'tbJson'}) @Pipe({name: 'tbJson'})
export class TbJsonPipe implements PipeTransform { export class TbJsonPipe implements PipeTransform {

View File

@ -20,7 +20,7 @@ import { parseTemplate } from '@app/core/utils';
@Pipe({ name: 'tbParseTemplate' }) @Pipe({ name: 'tbParseTemplate' })
export class TbTemplatePipe implements PipeTransform { export class TbTemplatePipe implements PipeTransform {
transform(template, data): string { transform(template, data): string {
console.log("TbTemplatePipe -> transform -> template, data", template, data) console.log('TbTemplatePipe -> transform -> template, data', template, data)
return parseTemplate(template, data); return parseTemplate(template, data);
} }
} }

View File

@ -104,7 +104,7 @@ import { TbErrorComponent } from '@shared/components/tb-error.component';
import { EntityTypeListComponent } from '@shared/components/entity/entity-type-list.component'; import { EntityTypeListComponent } from '@shared/components/entity/entity-type-list.component';
import { EntitySubTypeListComponent } from '@shared/components/entity/entity-subtype-list.component'; import { EntitySubTypeListComponent } from '@shared/components/entity/entity-subtype-list.component';
import { TruncatePipe } from '@shared/pipe/truncate.pipe'; import { TruncatePipe } from '@shared/pipe/truncate.pipe';
import { TbJsonPipe } from "@shared/pipe/tbJson.pipe"; import { TbJsonPipe } from '@shared/pipe/tbJson.pipe';
import { ColorPickerDialogComponent } from '@shared/components/dialog/color-picker-dialog.component'; import { ColorPickerDialogComponent } from '@shared/components/dialog/color-picker-dialog.component';
import { MatChipDraggableDirective } from '@shared/components/mat-chip-draggable.directive'; import { MatChipDraggableDirective } from '@shared/components/mat-chip-draggable.directive';
import { ColorInputComponent } from '@shared/components/color-input.component'; import { ColorInputComponent } from '@shared/components/color-input.component';
@ -125,8 +125,8 @@ import { TbCheatSheetComponent } from '@shared/components/cheatsheet.component';
import { TbHotkeysDirective } from '@shared/components/hotkeys.directive'; import { TbHotkeysDirective } from '@shared/components/hotkeys.directive';
import { NavTreeComponent } from '@shared/components/nav-tree.component'; import { NavTreeComponent } from '@shared/components/nav-tree.component';
import { LedLightComponent } from '@shared/components/led-light.component'; import { LedLightComponent } from '@shared/components/led-light.component';
import { TbJsonToStringDirective } from "@shared/components/directives/tb-json-to-string.directive"; import { TbJsonToStringDirective } from '@shared/components/directives/tb-json-to-string.directive';
import { JsonObjectEditDialogComponent } from "@shared/components/dialog/json-object-edit-dialog.component"; import { JsonObjectEditDialogComponent } from '@shared/components/dialog/json-object-edit-dialog.component';
import { HistorySelectorComponent } from './components/time/history-selector/history-selector.component'; import { HistorySelectorComponent } from './components/time/history-selector/history-selector.component';
import { TbTemplatePipe } from './pipe/public-api'; import { TbTemplatePipe } from './pipe/public-api';