Showing
7 changed files
with
54 additions
and
33 deletions
... | ... | @@ -520,10 +520,6 @@ export function parseFunction(source: string, params: string[] = []): Function { |
520 | 520 | } |
521 | 521 | |
522 | 522 | export function parseTemplate(template, data) { |
523 | - function formatValue(value, pattern) { | |
524 | - | |
525 | - } | |
526 | - | |
527 | 523 | let res = ''; |
528 | 524 | try { |
529 | 525 | let variables = ''; | ... | ... |
... | ... | @@ -26,12 +26,14 @@ import { Marker } from './markers'; |
26 | 26 | import { Observable, of, BehaviorSubject, Subject } from 'rxjs'; |
27 | 27 | import { filter } from 'rxjs/operators'; |
28 | 28 | import { Polyline } from './polyline'; |
29 | +import { Polygon } from './polygon'; | |
29 | 30 | |
30 | 31 | export default abstract class LeafletMap { |
31 | 32 | |
32 | 33 | markers: Map<string, Marker> = new Map(); |
33 | 34 | tooltips = []; |
34 | 35 | poly: Polyline; |
36 | + polygon: Polygon; | |
35 | 37 | map: L.Map; |
36 | 38 | map$: BehaviorSubject<L.Map> = new BehaviorSubject(null); |
37 | 39 | ready$: Observable<L.Map> = this.map$.pipe(filter(map => !!map)); |
... | ... | @@ -189,12 +191,40 @@ export default abstract class LeafletMap { |
189 | 191 | |
190 | 192 | updatePolyline(data, dataSources, settings) { |
191 | 193 | this.ready$.subscribe(() => { |
192 | - this.poly.updatePolyline(settings, data, dataSources); | |
193 | - /* const bounds = this.bounds.extend(this.poly.leafletPoly.getBounds()); | |
194 | - if (bounds.isValid()) { | |
195 | - this.map.fitBounds(bounds); | |
196 | - this.bounds = bounds; | |
197 | - }*/ | |
194 | + this.poly.updatePolyline(settings, data, dataSources); | |
198 | 195 | }); |
196 | + } | |
197 | + | |
198 | + //polygon | |
199 | + | |
200 | + updatePolygon(polyData: Array<Array<any>>) { | |
201 | + polyData.forEach(data => { | |
202 | + if (data.length) { | |
203 | + let dataSource = polyData.map(arr => arr[0]); | |
204 | + if (this.poly) { | |
205 | + this.updatePolyline(data, dataSource, this.options); | |
206 | + } | |
207 | + else { | |
208 | + this.createPolyline(data, dataSource, this.options); | |
209 | + } | |
210 | + } | |
211 | + }) | |
199 | 212 | } |
213 | + | |
214 | + createPolygon(data, dataSources, settings) { | |
215 | + this.ready$.subscribe(() => { | |
216 | + this.polygon = new Polygon(this.map, data.map(data => this.convertPosition(data)), data, dataSources, settings); | |
217 | + const bounds = this.bounds.extend(this.poly.leafletPoly.getBounds()); | |
218 | + if (bounds.isValid()) { | |
219 | + this.map.fitBounds(bounds); | |
220 | + this.bounds = bounds; | |
221 | + } | |
222 | + }); | |
223 | + } | |
224 | + | |
225 | + updatePolygons(data, dataSources, settings) { | |
226 | + this.ready$.subscribe(() => { | |
227 | + this.poly.updatePolyline(settings, data, dataSources); | |
228 | + }); | |
229 | + } | |
200 | 230 | } |
\ No newline at end of file | ... | ... |
... | ... | @@ -39,6 +39,7 @@ export class MapWidgetController implements MapWidgetInterface { |
39 | 39 | provider: MapProviders; |
40 | 40 | schema; |
41 | 41 | data; |
42 | + settings; | |
42 | 43 | |
43 | 44 | constructor(public mapProvider: MapProviders, private drawRoutes, public ctx, $element) { |
44 | 45 | if (this.map) { |
... | ... | @@ -50,13 +51,13 @@ export class MapWidgetController implements MapWidgetInterface { |
50 | 51 | if (!$element) { |
51 | 52 | $element = ctx.$container[0]; |
52 | 53 | } |
53 | - let settings = this.initSettings(ctx.settings); | |
54 | + this.settings = this.initSettings(ctx.settings); | |
54 | 55 | |
55 | 56 | let MapClass = providerSets[this.provider]?.MapClass; |
56 | 57 | if (!MapClass) { |
57 | 58 | return; |
58 | 59 | } |
59 | - this.map = new MapClass($element, settings); | |
60 | + this.map = new MapClass($element, this.settings); | |
60 | 61 | } |
61 | 62 | |
62 | 63 | onInit() { |
... | ... | @@ -88,6 +89,13 @@ export class MapWidgetController implements MapWidgetInterface { |
88 | 89 | update() { |
89 | 90 | if (this.drawRoutes) |
90 | 91 | this.map.updatePolylines(parseArray(this.data)); |
92 | + if(this.settings.showPolygon) | |
93 | + { | |
94 | + console.log(this.data); | |
95 | + | |
96 | + let dummy = [[37.771121,-22.510761],[37.774581,-22.454885],[37.766575,-22.453683],[37.764268,-22.509945]]; | |
97 | + this.map.updatePolygon(dummy); | |
98 | + } | |
91 | 99 | this.map.updateMarkers(parseData(this.data)); |
92 | 100 | } |
93 | 101 | |
... | ... | @@ -114,11 +122,10 @@ export class MapWidgetController implements MapWidgetInterface { |
114 | 122 | public static getProvidersSchema(){ |
115 | 123 | return mergeSchemes([mapProviderSchema, |
116 | 124 | ...Object.values(providerSets)?.map( |
117 | - setting => addCondition(setting?.schema, `model.provider === '${setting.name}'`))]) | |
125 | + setting => addCondition(setting?.schema, `model.provider === '${setting.name}'`))]); | |
118 | 126 | } |
119 | 127 | |
120 | 128 | public static settingsSchema(mapProvider, drawRoutes): Object { |
121 | - //const providerInfo = providerSets[mapProvider]; | |
122 | 129 | let schema = initSchema(); |
123 | 130 | addToSchema(schema,this.getProvidersSchema()); |
124 | 131 | addGroupInfo(schema, "Map Provider Settings"); |
... | ... | @@ -133,8 +140,6 @@ export class MapWidgetController implements MapWidgetInterface { |
133 | 140 | addToSchema(schema, clusteringSchema); |
134 | 141 | addGroupInfo(schema, "Markers Clustering Settings"); |
135 | 142 | } |
136 | - console.log(11, schema); | |
137 | - | |
138 | 143 | return schema; |
139 | 144 | } |
140 | 145 | ... | ... |
... | ... | @@ -18,7 +18,7 @@ import L from 'leaflet'; |
18 | 18 | import { interpolateOnPointSegment } from 'leaflet-geometryutil'; |
19 | 19 | import _ from 'lodash'; |
20 | 20 | |
21 | -export function createTooltip(target, settings, targetArgs?) { | |
21 | +export function createTooltip(target, settings) { | |
22 | 22 | const popup = L.popup(); |
23 | 23 | popup.setContent(''); |
24 | 24 | target.bindPopup(popup, { autoClose: settings.autocloseTooltip, closeOnClick: false }); |
... | ... | @@ -31,12 +31,7 @@ export function createTooltip(target, settings, targetArgs?) { |
31 | 31 | this.closePopup(); |
32 | 32 | }); |
33 | 33 | } |
34 | - return popup/*{ | |
35 | - markerArgs: targetArgs, | |
36 | - popup: popup, | |
37 | - locationSettings: settings, | |
38 | - dsIndex: settings.dsIndex | |
39 | - };*/ | |
34 | + return popup; | |
40 | 35 | } |
41 | 36 | |
42 | 37 | ... | ... |
... | ... | @@ -29,7 +29,7 @@ export class Marker { |
29 | 29 | data; |
30 | 30 | dataSources; |
31 | 31 | |
32 | - constructor(private map: L.Map, location: L.LatLngExpression, public settings: MarkerSettings, data, dataSources, onClickListener?, markerArgs?, onDragendListener?) { | |
32 | + constructor(private map: L.Map, location: L.LatLngExpression, public settings: MarkerSettings, data, dataSources, onClickListener?, onDragendListener?) { | |
33 | 33 | //this.map = map; |
34 | 34 | this.location = location; |
35 | 35 | this.setDataSources(data, dataSources); |
... | ... | @@ -45,7 +45,7 @@ export class Marker { |
45 | 45 | }); |
46 | 46 | |
47 | 47 | if (settings.showTooltip) { |
48 | - this.tooltip = createTooltip(this.leafletMarker, settings, markerArgs); | |
48 | + this.tooltip = createTooltip(this.leafletMarker, settings); | |
49 | 49 | this.tooltip.setContent(parseTemplate(this.settings.tooltipPattern, data)); |
50 | 50 | } |
51 | 51 | ... | ... |
... | ... | @@ -19,13 +19,12 @@ import { createTooltip } from './maps-utils'; |
19 | 19 | |
20 | 20 | export class Polygon { |
21 | 21 | |
22 | - map: L.Map; | |
23 | 22 | leafletPoly: L.Polygon; |
24 | 23 | |
25 | 24 | tooltip; |
26 | 25 | |
27 | - constructor(latLangs, settings, location, onClickListener) { | |
28 | - this.leafletPoly = L.polygon(latLangs, { | |
26 | + constructor(public map, coordinates, dataSources, settings, onClickListener?) { | |
27 | + this.leafletPoly = L.polygon(coordinates, { | |
29 | 28 | fill: true, |
30 | 29 | fillColor: settings.polygonColor, |
31 | 30 | color: settings.polygonStrokeColor, |
... | ... | @@ -35,7 +34,7 @@ export class Polygon { |
35 | 34 | }).addTo(this.map); |
36 | 35 | |
37 | 36 | if (settings.showTooltip) { |
38 | - this.tooltip = createTooltip(this.leafletPoly, location.dsIndex, settings); | |
37 | + this.tooltip = createTooltip(this.leafletPoly, settings); | |
39 | 38 | } |
40 | 39 | if (onClickListener) { |
41 | 40 | this.leafletPoly.on('click', onClickListener); | ... | ... |
... | ... | @@ -57,10 +57,6 @@ export class TripAnimationComponent implements OnInit, AfterViewInit { |
57 | 57 | let subscription = this.ctx.subscriptions[Object.keys(this.ctx.subscriptions)[0]]; |
58 | 58 | if (subscription) subscription.callbacks.onDataUpdated = (updated) => { |
59 | 59 | this.historicalData = parseArray(this.ctx.data); |
60 | - this.historicalData.forEach(ds => ds.forEach(el => { | |
61 | - el.longitude += (Math.random() - 0.5) | |
62 | - el.latitude += (Math.random() - 0.5) | |
63 | - })); | |
64 | 60 | this.calculateIntervals(); |
65 | 61 | this.timeUpdated(this.intervals[0]); |
66 | 62 | this.mapWidget.map.map.invalidateSize(); | ... | ... |