Showing
10 changed files
with
84 additions
and
70 deletions
... | ... | @@ -1816,8 +1816,7 @@ |
1816 | 1816 | "@types/geojson": { |
1817 | 1817 | "version": "7946.0.7", |
1818 | 1818 | "resolved": "https://registry.npmjs.org/@types/geojson/-/geojson-7946.0.7.tgz", |
1819 | - "integrity": "sha512-wE2v81i4C4Ol09RtsWFAqg3BUitWbHSpSlIo+bNdsCJijO9sjme+zm+73ZMCa/qMC8UEERxzGbvmr1cffo2SiQ==", | |
1820 | - "dev": true | |
1819 | + "integrity": "sha512-wE2v81i4C4Ol09RtsWFAqg3BUitWbHSpSlIo+bNdsCJijO9sjme+zm+73ZMCa/qMC8UEERxzGbvmr1cffo2SiQ==" | |
1821 | 1820 | }, |
1822 | 1821 | "@types/glob": { |
1823 | 1822 | "version": "7.1.1", |
... | ... | @@ -1881,11 +1880,18 @@ |
1881 | 1880 | "version": "1.5.12", |
1882 | 1881 | "resolved": "https://registry.npmjs.org/@types/leaflet/-/leaflet-1.5.12.tgz", |
1883 | 1882 | "integrity": "sha512-61HRMIng+bWvnnAIqUWLBlrd/TQZc4gU+gN1JL4K47EDtwIrcMEhWgi7PdcpbG1YmpH4F0EfOimkvV82gJIl9w==", |
1884 | - "dev": true, | |
1885 | 1883 | "requires": { |
1886 | 1884 | "@types/geojson": "*" |
1887 | 1885 | } |
1888 | 1886 | }, |
1887 | + "@types/leaflet-markercluster": { | |
1888 | + "version": "1.0.3", | |
1889 | + "resolved": "https://registry.npmjs.org/@types/leaflet-markercluster/-/leaflet-markercluster-1.0.3.tgz", | |
1890 | + "integrity": "sha1-ZBUb5FP2SQ6HUVAEgt65YQZOeCw=", | |
1891 | + "requires": { | |
1892 | + "@types/leaflet": "*" | |
1893 | + } | |
1894 | + }, | |
1889 | 1895 | "@types/leaflet-polylinedecorator": { |
1890 | 1896 | "version": "1.6.0", |
1891 | 1897 | "resolved": "https://registry.npmjs.org/@types/leaflet-polylinedecorator/-/leaflet-polylinedecorator-1.6.0.tgz", |
... | ... | @@ -7670,9 +7676,9 @@ |
7670 | 7676 | "integrity": "sha1-RGf0n5jRv9VpWb2cZwUgPdJgEnc=" |
7671 | 7677 | }, |
7672 | 7678 | "leaflet.gridlayer.googlemutant": { |
7673 | - "version": "0.9.0", | |
7674 | - "resolved": "https://registry.npmjs.org/leaflet.gridlayer.googlemutant/-/leaflet.gridlayer.googlemutant-0.9.0.tgz", | |
7675 | - "integrity": "sha512-hkLEHLcdcCaq1OKgUla5ar6fCaUK6yBYIY9HyAclPcMwhnpJTnLmYYPbVJbq3Niz0YiO75gls4A6D6jkBJXpuw==" | |
7679 | + "version": "0.8.0", | |
7680 | + "resolved": "https://registry.npmjs.org/leaflet.gridlayer.googlemutant/-/leaflet.gridlayer.googlemutant-0.8.0.tgz", | |
7681 | + "integrity": "sha512-Ain+jgDKRhlM6qNDDj2QFJa9vXUqV096N0PmpHO3DoNLS4I7EynTQCJXN+9qY4C51ZpV4Q4CI+apNv5XiP5aUA==" | |
7676 | 7682 | }, |
7677 | 7683 | "leaflet.markercluster": { |
7678 | 7684 | "version": "1.4.1", | ... | ... |
... | ... | @@ -39,6 +39,7 @@ |
39 | 39 | "@ngx-share/core": "^7.1.4", |
40 | 40 | "@ngx-translate/core": "^12.1.2", |
41 | 41 | "@ngx-translate/http-loader": "^4.0.0", |
42 | + "@types/leaflet-markercluster": "^1.0.3", | |
42 | 43 | "ace-builds": "^1.4.11", |
43 | 44 | "angular-gridster2": "^9.1.0", |
44 | 45 | "angular2-hotkeys": "^2.2.0", |
... | ... | @@ -62,7 +63,7 @@ |
62 | 63 | "leaflet-geometryutil": "^0.9.3", |
63 | 64 | "leaflet-polylinedecorator": "^1.6.0", |
64 | 65 | "leaflet-providers": "^1.9.1", |
65 | - "leaflet.gridlayer.googlemutant": "^0.9.0", | |
66 | + "leaflet.gridlayer.googlemutant": "0.8.0", | |
66 | 67 | "leaflet.markercluster": "^1.4.1", |
67 | 68 | "material-design-icons": "^3.0.1", |
68 | 69 | "messageformat": "^2.3.0", | ... | ... |
... | ... | @@ -525,7 +525,6 @@ export function parseFunction(source: any, params: string[] = ['def']): Function |
525 | 525 | |
526 | 526 | export function parseTemplate(template: string, data: object, translateFn?: (key: string) => string) { |
527 | 527 | let res = ''; |
528 | - let variables = ''; | |
529 | 528 | try { |
530 | 529 | if (template.match(/<link-act/g)) { |
531 | 530 | template = template.replace(/<link-act/g, '<a').replace(/link-act>/g, 'a>').replace(/name=(\'|")(.*?)(\'|")/g, `class='tb-custom-action' id='$2'`); |
... | ... | @@ -536,27 +535,26 @@ export function parseTemplate(template: string, data: object, translateFn?: (key |
536 | 535 | template = template.replace(match, translateFn(match.match(translateRegexp)[1])); |
537 | 536 | }); |
538 | 537 | } |
539 | - /* | |
540 | - const expressions = template.match(/\{(.*?)\}/g); | |
541 | - if (expressions) { | |
542 | - const clearMatches = template.match(/\$\{([^}]*?)\}/g); | |
543 | - for (const key in data) { | |
544 | - if (!key.includes('|')) | |
545 | - variables += `var ${key} = '${clearMatches[key] ? padValue(data[key], +clearMatches[key]) : data[key]}';`; | |
546 | - } | |
547 | - template = template.replace(/\:\d+\}/g, '}'); | |
548 | - const interpolator = new Interpolator({delimeter: ['${', '}']}); | |
549 | - interpolator.parse(template, data); | |
550 | - res = safeExecute(parseFunction(variables + ' return' + '`' + template + '`')); | |
538 | + const formatted = template.match(/\$\{([^}]*)\:\d*\}/g); | |
539 | + if (formatted) | |
540 | + formatted.forEach(value => { | |
541 | + const [variable, digits] = value.replace('${', '').replace('}', '').split(':'); | |
542 | + data[variable] = padValue(data[variable], +digits) | |
543 | + template = template.replace(value, '${' + variable + '}'); | |
544 | + }); | |
545 | + const variables = template.match(/\$\{.*?\}/g); | |
546 | + if (variables) { | |
547 | + variables.forEach(variable => { | |
548 | + variable = variable.replace('${', '').replace('}', ''); | |
549 | + if (!data[variable]) | |
550 | + data[variable] = ''; | |
551 | + }) | |
551 | 552 | } |
552 | - else res = template;*/ | |
553 | - const compiled = _.template(template, { | |
554 | - interpolate: /${([\s\S]+?)}/g | |
555 | - }); | |
556 | - res = compiled(data) | |
553 | + const compiled = _.template(template); | |
554 | + res = compiled(data); | |
557 | 555 | } |
558 | 556 | catch (ex) { |
559 | - console.log(ex, variables, template) | |
557 | + console.log(ex, template) | |
560 | 558 | } |
561 | 559 | return res; |
562 | 560 | } | ... | ... |
... | ... | @@ -14,12 +14,10 @@ |
14 | 14 | /// limitations under the License. |
15 | 15 | /// |
16 | 16 | |
17 | -import L, { LatLngTuple, LatLngBounds, Point } from 'leaflet'; | |
17 | +import L, { LatLngTuple, LatLngBounds, Point, MarkerClusterGroupOptions, markerClusterGroup} from 'leaflet'; | |
18 | 18 | |
19 | 19 | import 'leaflet-providers'; |
20 | -import 'leaflet.markercluster/dist/MarkerCluster.css'; | |
21 | -import 'leaflet.markercluster/dist/MarkerCluster.Default.css'; | |
22 | -import LM from 'leaflet.markercluster/dist/leaflet.markercluster'; | |
20 | +import 'leaflet.markercluster/dist/leaflet.markercluster'; | |
23 | 21 | |
24 | 22 | import { MapSettings, MarkerSettings, FormattedData, UnitedMapSettings, PolygonSettings, PolylineSettings } from './map-models'; |
25 | 23 | import { Marker } from './markers'; |
... | ... | @@ -43,7 +41,7 @@ export default abstract class LeafletMap { |
43 | 41 | bounds: L.LatLngBounds; |
44 | 42 | newMarker: L.Marker; |
45 | 43 | datasources: FormattedData[]; |
46 | - markersCluster: LM.markerClusterGroup; | |
44 | + markersCluster; | |
47 | 45 | |
48 | 46 | constructor(public $container: HTMLElement, options: UnitedMapSettings) { |
49 | 47 | this.options = options; |
... | ... | @@ -67,7 +65,7 @@ export default abstract class LeafletMap { |
67 | 65 | setTimeout(options.initCallback, 0); |
68 | 66 | } |
69 | 67 | if (useClusterMarkers) { |
70 | - const clusteringSettings: LM.MarkerClusterGroupOptions = { | |
68 | + const clusteringSettings: MarkerClusterGroupOptions = { | |
71 | 69 | zoomToBoundsOnClick: zoomOnClick, |
72 | 70 | showCoverageOnHover, |
73 | 71 | removeOutsideVisibleBounds, |
... | ... | @@ -80,7 +78,7 @@ export default abstract class LeafletMap { |
80 | 78 | if (maxZoom && maxZoom >= 0 && maxZoom < 19) { |
81 | 79 | clusteringSettings.disableClusteringAtZoom = Math.floor(maxZoom); |
82 | 80 | } |
83 | - this.markersCluster = LM.markerClusterGroup(clusteringSettings); | |
81 | + this.markersCluster = markerClusterGroup(clusteringSettings); | |
84 | 82 | this.ready$.subscribe(map => map.addLayer(this.markersCluster)); |
85 | 83 | } |
86 | 84 | } |
... | ... | @@ -208,7 +206,7 @@ export default abstract class LeafletMap { |
208 | 206 | }); |
209 | 207 | this.map.fitBounds(bounds, { padding: padding || [50, 50], animate: false }); |
210 | 208 | } |
211 | - this.bounds = this.bounds.extend(bounds); | |
209 | + this.bounds = bounds; | |
212 | 210 | } |
213 | 211 | } |
214 | 212 | |
... | ... | @@ -259,7 +257,9 @@ export default abstract class LeafletMap { |
259 | 257 | private createMarker(key: string, data: FormattedData, dataSources: FormattedData[], settings: MarkerSettings) { |
260 | 258 | this.ready$.subscribe(() => { |
261 | 259 | const newMarker = new Marker(this.convertPosition(data), settings, data, dataSources, this.dragMarker); |
262 | - this.fitBounds(this.bounds.extend(newMarker.leafletMarker.getLatLng()), settings.draggableMarker && this.markers.size > 2); | |
260 | + console.log(this.bounds); | |
261 | + | |
262 | + this.fitBounds(this.bounds.extend(newMarker.leafletMarker.getLatLng()), settings.draggableMarker && this.markers.size < 2); | |
263 | 263 | this.markers.set(key, newMarker); |
264 | 264 | if (this.options.useClusterMarkers) { |
265 | 265 | this.markersCluster.addLayer(newMarker.leafletMarker); | ... | ... |
... | ... | @@ -48,6 +48,7 @@ import { UtilsService } from '@core/services/utils.service'; |
48 | 48 | export class MapWidgetController implements MapWidgetInterface { |
49 | 49 | |
50 | 50 | constructor(public mapProvider: MapProviders, private drawRoutes: boolean, public ctx: WidgetContext, $element: HTMLElement) { |
51 | + console.log("MapWidgetController -> constructor -> ctx", ctx) | |
51 | 52 | if (this.map) { |
52 | 53 | this.map.map.remove(); |
53 | 54 | delete this.map; |
... | ... | @@ -83,6 +84,7 @@ export class MapWidgetController implements MapWidgetInterface { |
83 | 84 | } |
84 | 85 | |
85 | 86 | public static getProvidersSchema(mapProvider: MapProviders) { |
87 | + console.log("MapWidgetController -> getProvidersSchema -> mapProvider", mapProvider) | |
86 | 88 | mapProviderSchema.schema.properties.provider.default = mapProvider; |
87 | 89 | return mergeSchemes([mapProviderSchema, |
88 | 90 | ...Object.keys(providerSets)?.map( |
... | ... | @@ -94,8 +96,10 @@ export class MapWidgetController implements MapWidgetInterface { |
94 | 96 | addToSchema(schema, this.getProvidersSchema(mapProvider)); |
95 | 97 | if (mapProvider !== 'image-map') { |
96 | 98 | addGroupInfo(schema, 'Map Provider Settings'); |
97 | - addToSchema(schema, mergeSchemes([commonMapSettingsSchema, addCondition(mapPolygonSchema, 'model.showPolygon === true')])); | |
99 | + addToSchema(schema, commonMapSettingsSchema); | |
98 | 100 | addGroupInfo(schema, 'Common Map Settings'); |
101 | + addToSchema(schema, addCondition(mapPolygonSchema, 'model.showPolygon === true')); | |
102 | + addGroupInfo(schema, 'Polygon Settings'); | |
99 | 103 | if (drawRoutes) { |
100 | 104 | addToSchema(schema, routeMapSettingsSchema); |
101 | 105 | addGroupInfo(schema, 'Route Map Settings'); |
... | ... | @@ -127,8 +131,10 @@ export class MapWidgetController implements MapWidgetInterface { |
127 | 131 | } |
128 | 132 | |
129 | 133 | translate = (key: string, defaultTranslation?: string): string => { |
130 | - return (this.ctx.$injector.get(UtilsService).customTranslation(key, defaultTranslation || key) | |
131 | - || this.ctx.$injector.get(TranslateService).instant(key)); | |
134 | + if (key) | |
135 | + return (this.ctx.$injector.get(UtilsService).customTranslation(key, defaultTranslation || key) | |
136 | + || this.ctx.$injector.get(TranslateService).instant(key)); | |
137 | + else return ''; | |
132 | 138 | } |
133 | 139 | |
134 | 140 | getDescriptors(name: string): { [name: string]: ($event: Event) => void } { |
... | ... | @@ -156,24 +162,25 @@ export class MapWidgetController implements MapWidgetInterface { |
156 | 162 | } |
157 | 163 | |
158 | 164 | setMarkerLocation = (e) => { |
165 | + console.log("setMarkerLocation -> e", e) | |
159 | 166 | const attributeService = this.ctx.$injector.get(AttributeService); |
160 | - forkJoin( | |
161 | - this.data.filter(data => !!e[data.dataKey.name]) | |
162 | - .map(data => { | |
163 | - const entityId: EntityId = { | |
164 | - entityType: data.datasource.entityType, | |
165 | - id: data.datasource.entityId | |
166 | - }; | |
167 | - return attributeService.saveEntityAttributes( | |
168 | - entityId, | |
169 | - AttributeScope.SHARED_SCOPE, | |
170 | - [{ | |
171 | - key: data.dataKey.name, | |
172 | - value: e[data.dataKey.name] | |
173 | - }] | |
174 | - ); | |
175 | - })).subscribe(res => { | |
176 | - }); | |
167 | + | |
168 | + const entityId: EntityId = { | |
169 | + entityType: e.$datasource.entityType, | |
170 | + id: e.$datasource.entityId | |
171 | + }; | |
172 | + const keys = e.$datasource.dataKeys.map(key => { | |
173 | + return { | |
174 | + key: key.name, | |
175 | + value: e[key.name] | |
176 | + } | |
177 | + }) | |
178 | + return attributeService.saveEntityAttributes( | |
179 | + entityId, | |
180 | + AttributeScope.SHARED_SCOPE, | |
181 | + keys | |
182 | + ).subscribe(res => { | |
183 | + }); | |
177 | 184 | } |
178 | 185 | |
179 | 186 | initSettings(settings: UnitedMapSettings): UnitedMapSettings { |
... | ... | @@ -214,8 +221,7 @@ export class MapWidgetController implements MapWidgetInterface { |
214 | 221 | if (this.settings.draggableMarker) { |
215 | 222 | this.map.setDataSources(parseData(this.data)); |
216 | 223 | } |
217 | - else | |
218 | - this.map.updateMarkers(parseData(this.data)); | |
224 | + this.map.updateMarkers(parseData(this.data)); | |
219 | 225 | } |
220 | 226 | |
221 | 227 | resize() { | ... | ... |
... | ... | @@ -17,7 +17,6 @@ |
17 | 17 | import L from 'leaflet'; |
18 | 18 | import _ from 'lodash'; |
19 | 19 | import { MarkerSettings, PolylineSettings, PolygonSettings } from './map-models'; |
20 | -import { parseWithTranslation } from '@app/core/utils'; | |
21 | 20 | |
22 | 21 | export function createTooltip(target: L.Layer, |
23 | 22 | settings: MarkerSettings | PolylineSettings | PolygonSettings, | ... | ... |
... | ... | @@ -335,12 +335,7 @@ export const commonMapSettingsSchema = |
335 | 335 | colorFunction: { |
336 | 336 | title: 'Color function: f(data, dsData, dsIndex)', |
337 | 337 | type: 'string' |
338 | - }, | |
339 | - showPolygon: { | |
340 | - title: 'Show polygon', | |
341 | - type: 'boolean', | |
342 | - default: false | |
343 | - }, | |
338 | + }, | |
344 | 339 | markerImage: { |
345 | 340 | title: 'Custom marker image', |
346 | 341 | type: 'string' |
... | ... | @@ -439,8 +434,7 @@ export const commonMapSettingsSchema = |
439 | 434 | type: 'image' |
440 | 435 | } |
441 | 436 | ] |
442 | - }, | |
443 | - 'showPolygon', | |
437 | + } | |
444 | 438 | ] |
445 | 439 | }; |
446 | 440 | |
... | ... | @@ -450,6 +444,11 @@ export const mapPolygonSchema = |
450 | 444 | title: 'Map Polygon Configuration', |
451 | 445 | type: 'object', |
452 | 446 | properties: { |
447 | + showPolygon: { | |
448 | + title: 'Show polygon', | |
449 | + type: 'boolean', | |
450 | + default: false | |
451 | + }, | |
453 | 452 | polygonKeyName: { |
454 | 453 | title: 'Polygon key name', |
455 | 454 | type: 'string', |
... | ... | @@ -491,6 +490,7 @@ export const mapPolygonSchema = |
491 | 490 | required: [] |
492 | 491 | }, |
493 | 492 | form: [ |
493 | + 'showPolygon', | |
494 | 494 | 'polygonKeyName', |
495 | 495 | { |
496 | 496 | key: 'polygonColor', | ... | ... |
... | ... | @@ -17,7 +17,7 @@ |
17 | 17 | --> |
18 | 18 | <div class="trip-animation-widget"> |
19 | 19 | <div class="trip-animation-label-container" *ngIf="settings.showLabel"> |
20 | - {{label }} | |
20 | + {{label}} | |
21 | 21 | </div> |
22 | 22 | <div class="trip-animation-container" fxLayout="column"> |
23 | 23 | <div class="map" #map></div> | ... | ... |
... | ... | @@ -100,8 +100,8 @@ export class TripAnimationComponent implements OnInit, AfterViewInit { |
100 | 100 | timeUpdated(time: number) { |
101 | 101 | const currentPosition = this.interpolatedData.map(dataSource => dataSource[time]); |
102 | 102 | this.activeTrip = currentPosition[0]; |
103 | - this.minTime = moment(this.historicalData[0][this.historicalData.length - 1]?.time).format('YYYY-MM-DD HH:mm:ss') | |
104 | - this.maxTime = moment(this.historicalData[0][0]?.time).format('YYYY-MM-DD HH:mm:ss') | |
103 | + this.minTime = moment(this.intervals[this.intervals.length - 1]).format('YYYY-MM-DD HH:mm:ss') | |
104 | + this.maxTime = moment(this.intervals[0]).format('YYYY-MM-DD HH:mm:ss') | |
105 | 105 | this.calcLabel(); |
106 | 106 | this.calcTooltip(); |
107 | 107 | if (this.mapWidget) { | ... | ... |
... | ... | @@ -2,7 +2,11 @@ |
2 | 2 | "extends": "../tsconfig.json", |
3 | 3 | "compilerOptions": { |
4 | 4 | "outDir": "../out-tsc/app", |
5 | - "types": ["node", "jquery", "flot", "tooltipster", "tinycolor2", "js-beautify", "react", "react-dom", "jstree", "raphael", "canvas-gauges"] | |
5 | + "typeRoots": [ | |
6 | + "node_modules/@types" | |
7 | + ], | |
8 | + "types": ["node", "jquery", "flot", "tooltipster", "tinycolor2", "js-beautify", | |
9 | + "react", "react-dom", "jstree", "raphael", "canvas-gauges", "leaflet", "leaflet-markercluster"] | |
6 | 10 | }, |
7 | 11 | "angularCompilerOptions": { |
8 | 12 | "fullTemplateTypeCheck": true | ... | ... |