Commit 235b41c6aa0e07854b7e00ce35971580a6f73f6c

Authored by Artem Halushko
1 parent 09a446bd

WIP on polygons

@@ -520,10 +520,6 @@ export function parseFunction(source: string, params: string[] = []): Function { @@ -520,10 +520,6 @@ export function parseFunction(source: string, params: string[] = []): Function {
520 } 520 }
521 521
522 export function parseTemplate(template, data) { 522 export function parseTemplate(template, data) {
523 - function formatValue(value, pattern) {  
524 -  
525 - }  
526 -  
527 let res = ''; 523 let res = '';
528 try { 524 try {
529 let variables = ''; 525 let variables = '';
@@ -26,12 +26,14 @@ import { Marker } from './markers'; @@ -26,12 +26,14 @@ import { Marker } from './markers';
26 import { Observable, of, BehaviorSubject, Subject } from 'rxjs'; 26 import { Observable, of, BehaviorSubject, Subject } from 'rxjs';
27 import { filter } from 'rxjs/operators'; 27 import { filter } from 'rxjs/operators';
28 import { Polyline } from './polyline'; 28 import { Polyline } from './polyline';
  29 +import { Polygon } from './polygon';
29 30
30 export default abstract class LeafletMap { 31 export default abstract class LeafletMap {
31 32
32 markers: Map<string, Marker> = new Map(); 33 markers: Map<string, Marker> = new Map();
33 tooltips = []; 34 tooltips = [];
34 poly: Polyline; 35 poly: Polyline;
  36 + polygon: Polygon;
35 map: L.Map; 37 map: L.Map;
36 map$: BehaviorSubject<L.Map> = new BehaviorSubject(null); 38 map$: BehaviorSubject<L.Map> = new BehaviorSubject(null);
37 ready$: Observable<L.Map> = this.map$.pipe(filter(map => !!map)); 39 ready$: Observable<L.Map> = this.map$.pipe(filter(map => !!map));
@@ -189,12 +191,40 @@ export default abstract class LeafletMap { @@ -189,12 +191,40 @@ export default abstract class LeafletMap {
189 191
190 updatePolyline(data, dataSources, settings) { 192 updatePolyline(data, dataSources, settings) {
191 this.ready$.subscribe(() => { 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 }
@@ -39,6 +39,7 @@ export class MapWidgetController implements MapWidgetInterface { @@ -39,6 +39,7 @@ export class MapWidgetController implements MapWidgetInterface {
39 provider: MapProviders; 39 provider: MapProviders;
40 schema; 40 schema;
41 data; 41 data;
  42 + settings;
42 43
43 constructor(public mapProvider: MapProviders, private drawRoutes, public ctx, $element) { 44 constructor(public mapProvider: MapProviders, private drawRoutes, public ctx, $element) {
44 if (this.map) { 45 if (this.map) {
@@ -50,13 +51,13 @@ export class MapWidgetController implements MapWidgetInterface { @@ -50,13 +51,13 @@ export class MapWidgetController implements MapWidgetInterface {
50 if (!$element) { 51 if (!$element) {
51 $element = ctx.$container[0]; 52 $element = ctx.$container[0];
52 } 53 }
53 - let settings = this.initSettings(ctx.settings); 54 + this.settings = this.initSettings(ctx.settings);
54 55
55 let MapClass = providerSets[this.provider]?.MapClass; 56 let MapClass = providerSets[this.provider]?.MapClass;
56 if (!MapClass) { 57 if (!MapClass) {
57 return; 58 return;
58 } 59 }
59 - this.map = new MapClass($element, settings); 60 + this.map = new MapClass($element, this.settings);
60 } 61 }
61 62
62 onInit() { 63 onInit() {
@@ -88,6 +89,13 @@ export class MapWidgetController implements MapWidgetInterface { @@ -88,6 +89,13 @@ export class MapWidgetController implements MapWidgetInterface {
88 update() { 89 update() {
89 if (this.drawRoutes) 90 if (this.drawRoutes)
90 this.map.updatePolylines(parseArray(this.data)); 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 this.map.updateMarkers(parseData(this.data)); 99 this.map.updateMarkers(parseData(this.data));
92 } 100 }
93 101
@@ -114,11 +122,10 @@ export class MapWidgetController implements MapWidgetInterface { @@ -114,11 +122,10 @@ export class MapWidgetController implements MapWidgetInterface {
114 public static getProvidersSchema(){ 122 public static getProvidersSchema(){
115 return mergeSchemes([mapProviderSchema, 123 return mergeSchemes([mapProviderSchema,
116 ...Object.values(providerSets)?.map( 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 public static settingsSchema(mapProvider, drawRoutes): Object { 128 public static settingsSchema(mapProvider, drawRoutes): Object {
121 - //const providerInfo = providerSets[mapProvider];  
122 let schema = initSchema(); 129 let schema = initSchema();
123 addToSchema(schema,this.getProvidersSchema()); 130 addToSchema(schema,this.getProvidersSchema());
124 addGroupInfo(schema, "Map Provider Settings"); 131 addGroupInfo(schema, "Map Provider Settings");
@@ -133,8 +140,6 @@ export class MapWidgetController implements MapWidgetInterface { @@ -133,8 +140,6 @@ export class MapWidgetController implements MapWidgetInterface {
133 addToSchema(schema, clusteringSchema); 140 addToSchema(schema, clusteringSchema);
134 addGroupInfo(schema, "Markers Clustering Settings"); 141 addGroupInfo(schema, "Markers Clustering Settings");
135 } 142 }
136 - console.log(11, schema);  
137 -  
138 return schema; 143 return schema;
139 } 144 }
140 145
@@ -18,7 +18,7 @@ import L from 'leaflet'; @@ -18,7 +18,7 @@ import L from 'leaflet';
18 import { interpolateOnPointSegment } from 'leaflet-geometryutil'; 18 import { interpolateOnPointSegment } from 'leaflet-geometryutil';
19 import _ from 'lodash'; 19 import _ from 'lodash';
20 20
21 -export function createTooltip(target, settings, targetArgs?) { 21 +export function createTooltip(target, settings) {
22 const popup = L.popup(); 22 const popup = L.popup();
23 popup.setContent(''); 23 popup.setContent('');
24 target.bindPopup(popup, { autoClose: settings.autocloseTooltip, closeOnClick: false }); 24 target.bindPopup(popup, { autoClose: settings.autocloseTooltip, closeOnClick: false });
@@ -31,12 +31,7 @@ export function createTooltip(target, settings, targetArgs?) { @@ -31,12 +31,7 @@ export function createTooltip(target, settings, targetArgs?) {
31 this.closePopup(); 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,7 +29,7 @@ export class Marker {
29 data; 29 data;
30 dataSources; 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 //this.map = map; 33 //this.map = map;
34 this.location = location; 34 this.location = location;
35 this.setDataSources(data, dataSources); 35 this.setDataSources(data, dataSources);
@@ -45,7 +45,7 @@ export class Marker { @@ -45,7 +45,7 @@ export class Marker {
45 }); 45 });
46 46
47 if (settings.showTooltip) { 47 if (settings.showTooltip) {
48 - this.tooltip = createTooltip(this.leafletMarker, settings, markerArgs); 48 + this.tooltip = createTooltip(this.leafletMarker, settings);
49 this.tooltip.setContent(parseTemplate(this.settings.tooltipPattern, data)); 49 this.tooltip.setContent(parseTemplate(this.settings.tooltipPattern, data));
50 } 50 }
51 51
@@ -19,13 +19,12 @@ import { createTooltip } from './maps-utils'; @@ -19,13 +19,12 @@ import { createTooltip } from './maps-utils';
19 19
20 export class Polygon { 20 export class Polygon {
21 21
22 - map: L.Map;  
23 leafletPoly: L.Polygon; 22 leafletPoly: L.Polygon;
24 23
25 tooltip; 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 fill: true, 28 fill: true,
30 fillColor: settings.polygonColor, 29 fillColor: settings.polygonColor,
31 color: settings.polygonStrokeColor, 30 color: settings.polygonStrokeColor,
@@ -35,7 +34,7 @@ export class Polygon { @@ -35,7 +34,7 @@ export class Polygon {
35 }).addTo(this.map); 34 }).addTo(this.map);
36 35
37 if (settings.showTooltip) { 36 if (settings.showTooltip) {
38 - this.tooltip = createTooltip(this.leafletPoly, location.dsIndex, settings); 37 + this.tooltip = createTooltip(this.leafletPoly, settings);
39 } 38 }
40 if (onClickListener) { 39 if (onClickListener) {
41 this.leafletPoly.on('click', onClickListener); 40 this.leafletPoly.on('click', onClickListener);
@@ -57,10 +57,6 @@ export class TripAnimationComponent implements OnInit, AfterViewInit { @@ -57,10 +57,6 @@ export class TripAnimationComponent implements OnInit, AfterViewInit {
57 let subscription = this.ctx.subscriptions[Object.keys(this.ctx.subscriptions)[0]]; 57 let subscription = this.ctx.subscriptions[Object.keys(this.ctx.subscriptions)[0]];
58 if (subscription) subscription.callbacks.onDataUpdated = (updated) => { 58 if (subscription) subscription.callbacks.onDataUpdated = (updated) => {
59 this.historicalData = parseArray(this.ctx.data); 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 this.calculateIntervals(); 60 this.calculateIntervals();
65 this.timeUpdated(this.intervals[0]); 61 this.timeUpdated(this.intervals[0]);
66 this.mapWidget.map.map.invalidateSize(); 62 this.mapWidget.map.map.invalidateSize();