@aggdirect/coolmap-services 1.4.8 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,1130 +0,0 @@
1
- import * as i0 from '@angular/core';
2
- import { Injectable, Inject } from '@angular/core';
3
- import * as mapboxgl from 'mapbox-gl';
4
- import * as turf from '@turf/turf';
5
- import { BehaviorSubject } from 'rxjs';
6
- import { MapboxLayer } from '@deck.gl/mapbox';
7
- import { ArcLayer } from '@deck.gl/layers';
8
- import * as i1 from '@angular/common/http';
9
- import * as i2 from '@angular/material/snack-bar';
10
- import * as i2$1 from '@angular/platform-browser';
11
-
12
- class Route {
13
- index = 0;
14
- type;
15
- // Job Code
16
- customer_contact;
17
- customer_name;
18
- delivery_contact;
19
- delivery_lat;
20
- delivery_location;
21
- delivery_lon;
22
- driver_list;
23
- material;
24
- order_number;
25
- pickup_lat;
26
- pickup_location;
27
- pickup_lon;
28
- project;
29
- total_count;
30
- unit;
31
- values;
32
- job_id;
33
- isSelected;
34
- date;
35
- // Add Route
36
- created_at;
37
- created_by_name;
38
- customer_id;
39
- delivery_lat_lng;
40
- estimated_distance;
41
- estimated_time;
42
- materials_id;
43
- path;
44
- pickup_lat_lng;
45
- route_id;
46
- route_name;
47
- unit_id;
48
- note;
49
- materialLabel;
50
- isActive;
51
- prevent;
52
- is_system_pickup;
53
- is_system_delivery;
54
- }
55
- const EstinationData = ['estimated_distance', 'estimated_time'];
56
- var EstinationEnum;
57
- (function (EstinationEnum) {
58
- EstinationEnum["estimated_distance"] = "miles";
59
- EstinationEnum["estimated_time"] = "time";
60
- })(EstinationEnum || (EstinationEnum = {}));
61
- const JobCodeOverviewData = ['order_number', 'customer_name', 'project', 'unit', 'material', 'customer_contact', 'delivery_contact', 'pickup_location', 'delivery_location'];
62
- var JobCodeOverviewEnum;
63
- (function (JobCodeOverviewEnum) {
64
- JobCodeOverviewEnum["material"] = "Material";
65
- JobCodeOverviewEnum["order_number"] = "Job Code";
66
- JobCodeOverviewEnum["customer_name"] = "Customer";
67
- JobCodeOverviewEnum["customer_contact"] = "Customer Contact";
68
- JobCodeOverviewEnum["delivery_contact"] = "Delivery Contact";
69
- JobCodeOverviewEnum["project"] = "Project Name";
70
- JobCodeOverviewEnum["unit"] = "Job Type";
71
- JobCodeOverviewEnum["pickup_location"] = "Pickup";
72
- JobCodeOverviewEnum["delivery_location"] = "Delivery";
73
- })(JobCodeOverviewEnum || (JobCodeOverviewEnum = {}));
74
- const DriversmsCardKey = ['order_number', 'date', 'values', 'material', 'unit', 'pickup_location', 'delivery_location'];
75
- var DriverSmsCardEnum;
76
- (function (DriverSmsCardEnum) {
77
- DriverSmsCardEnum["order_number"] = "Jobcode";
78
- DriverSmsCardEnum["date"] = "Date";
79
- DriverSmsCardEnum["values"] = "Total tasks";
80
- DriverSmsCardEnum["material"] = "Material";
81
- DriverSmsCardEnum["unit"] = "Unit";
82
- DriverSmsCardEnum["pickup_location"] = "Pickup Address";
83
- DriverSmsCardEnum["delivery_location"] = "Delivery Address";
84
- })(DriverSmsCardEnum || (DriverSmsCardEnum = {}));
85
- class PopupData {
86
- coordinate;
87
- pickup;
88
- jobCode;
89
- customer;
90
- drop;
91
- routeType;
92
- title;
93
- material;
94
- type;
95
- }
96
- class CoolmapConfigModel {
97
- analyticsRESTURL;
98
- RESTURLPrefix;
99
- repository;
100
- mapboxStyle;
101
- mapboxAccessToken;
102
- }
103
-
104
- class UtilsService {
105
- http;
106
- snackBar;
107
- config;
108
- ngZone;
109
- analyticsRESTURL = '';
110
- RESTURLPrefix = '';
111
- pickupOptions = [];
112
- destOptions = [];
113
- ownerOptions = [];
114
- customerOptions = [];
115
- unitOptions = [];
116
- materialOptions = [];
117
- jcodeOptions = [];
118
- driverOption = [];
119
- truckingCompanayOption = [];
120
- routeNameOptions = [];
121
- preventnavChange = new BehaviorSubject(false);
122
- navChangeObserve = this.preventnavChange.asObservable();
123
- clearViewRouteforJobCode = new BehaviorSubject(false);
124
- clearViewRouteforJobCodeObserve = this.clearViewRouteforJobCode.asObservable();
125
- preVentJobdetailclose = new BehaviorSubject(false);
126
- getpreVentJobdetailclose = this.preVentJobdetailclose.asObservable();
127
- routeDetailsUtility = new BehaviorSubject({});
128
- getrouteDetailsUtility = this.routeDetailsUtility.asObservable();
129
- removeMapEntity = new BehaviorSubject({});
130
- removeMapEntityUtility = this.removeMapEntity.asObservable();
131
- dict = new Map();
132
- unitsList;
133
- materialsList;
134
- materialsListForCustomer;
135
- customersList;
136
- locationList;
137
- pickUpAutocomplete;
138
- constructor(http, snackBar, config, ngZone) {
139
- this.http = http;
140
- this.snackBar = snackBar;
141
- this.config = config;
142
- this.ngZone = ngZone;
143
- this.analyticsRESTURL = config.analyticsRESTURL;
144
- this.RESTURLPrefix = config.RESTURLPrefix;
145
- }
146
- getDateFormat(strVal, seprater) {
147
- seprater = seprater ? seprater : '-';
148
- const mydate = strVal;
149
- return (mydate?.getFullYear() +
150
- seprater +
151
- ((mydate ? mydate.getMonth() : 0) + 1) +
152
- seprater +
153
- mydate?.getDate());
154
- }
155
- getData(path) {
156
- return this.http.get(`${this.analyticsRESTURL}${this.config.repository}/${path}`);
157
- }
158
- getRestData(path) {
159
- return this.http.get(`${this.RESTURLPrefix}${path}`);
160
- }
161
- postdata(path, data) {
162
- return this.http.post(`${this.analyticsRESTURL}${this.config.repository}/${path}`, data);
163
- }
164
- postDataWithRestUrl(path, data) {
165
- return this.http.post(`${this.RESTURLPrefix}${path}`, data);
166
- }
167
- autocomplete(searchElementRef, type) {
168
- return new Promise((resolve, reject) => {
169
- const autocomplete = new google.maps.places.Autocomplete(searchElementRef.nativeElement, {
170
- types: ['address']
171
- });
172
- google.maps.event.addListener(autocomplete, 'place_changed', () => {
173
- this.ngZone.run(() => {
174
- const place = autocomplete.getPlace();
175
- resolve({ lat: place.geometry.location.lat(), lng: place.geometry.location.lng(), formatted_address: place['formatted_address'] });
176
- });
177
- });
178
- });
179
- }
180
- openSnackBar(message, className) {
181
- this.snackBar.open(message, '', {
182
- duration: 5000,
183
- verticalPosition: 'top',
184
- horizontalPosition: 'center',
185
- panelClass: [className ? className : 'default'],
186
- });
187
- }
188
- makeOptions(item) {
189
- if (item.order_number) {
190
- this.jcodeOptions.findIndex((elem) => elem.job_id === item.job_id) === -1
191
- ? this.jcodeOptions.push({
192
- job_code: item.order_number,
193
- job_id: item.job_id,
194
- })
195
- : null;
196
- if (item.driver_list && item.driver_list?.length > 0) {
197
- item.driver_list.forEach((driver) => {
198
- this.driverOption.findIndex((elem) => elem === driver['driver_name']) === -1
199
- ? this.driverOption.push(driver['driver_name'])
200
- : null;
201
- this.truckingCompanayOption.findIndex((elem) => elem === driver['trucking_company']) === -1
202
- ? this.truckingCompanayOption.push(driver['trucking_company'])
203
- : null;
204
- });
205
- }
206
- }
207
- this.pickupOptions.findIndex((elem) => elem === item.pickup_location) === -1
208
- ? this.pickupOptions.push(item.pickup_location)
209
- : null;
210
- this.destOptions.findIndex((elem) => elem === item.delivery_location) === -1
211
- ? this.destOptions.push(item.delivery_location)
212
- : null;
213
- this.customerOptions.findIndex((customer) => customer === item.customer_name) === -1
214
- ? this.customerOptions.push(item.customer_name)
215
- : null;
216
- this.unitOptions.findIndex((elem) => elem === item.unit) === -1
217
- ? this.unitOptions.push(item.unit)
218
- : null;
219
- if (item.material) {
220
- this.materialOptions.findIndex((elem) => elem === item.material) === -1
221
- ? this.materialOptions.push(item.material)
222
- : null;
223
- }
224
- if (item.route_name)
225
- this.routeNameOptions.findIndex((elem) => elem === item.route_name) === -1
226
- ? this.routeNameOptions.push(item.route_name)
227
- : null;
228
- }
229
- filter(value, filters) {
230
- if (typeof value !== 'string') {
231
- return [];
232
- }
233
- const filterValue = value.toLowerCase();
234
- if (filterValue === '') {
235
- return [];
236
- }
237
- const searchResults = [];
238
- this.unitOptions.map((unit) => {
239
- if (unit.toLowerCase().includes(filterValue)) {
240
- searchResults.push({ type: 'unit', label: unit, value: unit });
241
- }
242
- });
243
- this.customerOptions.map((unit) => {
244
- if (unit.toLowerCase().includes(filterValue)) {
245
- searchResults.push({ type: 'customer', label: unit, value: unit });
246
- }
247
- });
248
- if (this.materialOptions.length) {
249
- this.materialOptions.map((unit) => {
250
- if (unit.toLowerCase().includes(filterValue)) {
251
- searchResults.push({ type: 'material', label: unit, value: unit });
252
- }
253
- });
254
- }
255
- this.pickupOptions.map((unit) => {
256
- if (unit.toLowerCase().includes(filterValue)) {
257
- searchResults.push({
258
- type: 'pickup location',
259
- label: unit,
260
- value: unit,
261
- });
262
- }
263
- });
264
- this.destOptions.map((unit) => {
265
- if (unit.toLowerCase().includes(filterValue)) {
266
- searchResults.push({
267
- type: 'destination location',
268
- label: unit,
269
- value: unit,
270
- });
271
- }
272
- });
273
- this.jcodeOptions.map((unit) => {
274
- if (unit.job_code.toLowerCase().includes(filterValue)) {
275
- searchResults.push({
276
- type: 'job',
277
- label: unit['job_code'],
278
- value: unit,
279
- });
280
- }
281
- });
282
- this.driverOption.map((unit) => {
283
- if (unit.toLowerCase().includes(filterValue)) {
284
- searchResults.push({ type: 'Driver', label: unit, value: unit });
285
- }
286
- });
287
- this.truckingCompanayOption.map((unit) => {
288
- if (unit.toLowerCase().includes(filterValue)) {
289
- searchResults.push({
290
- type: 'Trucking Company',
291
- label: unit,
292
- value: unit,
293
- });
294
- }
295
- });
296
- this.routeNameOptions.map((unit) => {
297
- if (unit.toLowerCase().includes(filterValue)) {
298
- searchResults.push({ type: 'Route name', label: unit, value: unit });
299
- }
300
- });
301
- const searchDict = {};
302
- filters.map((filter) => {
303
- searchDict[filter['name'] + filter['type']] = filter;
304
- });
305
- const furtherFilter = [];
306
- searchResults.map((search) => {
307
- if (search['label'] + search['type'] in searchDict) {
308
- }
309
- else {
310
- furtherFilter.push(search);
311
- }
312
- });
313
- return furtherFilter;
314
- }
315
- getSearchResults(list, filterval) {
316
- return list.filter((element) => {
317
- const result_list_boolean = [];
318
- if (filterval.length > 0) {
319
- if (filterval[0]['type'] === 'unit') {
320
- result_list_boolean.push(filterval[0]['name'] ===
321
- element[filterval[0]['type']]);
322
- }
323
- if (filterval[0]['type'] === 'customer') {
324
- result_list_boolean.push(filterval[0]['name'] === element['customer_name']);
325
- }
326
- if (filterval[0]['type'] === 'material') {
327
- result_list_boolean.push(filterval[0]['name'] ===
328
- element[filterval[0]['type']]);
329
- }
330
- if (filterval[0]['type'] === 'pickup location') {
331
- result_list_boolean.push(filterval[0]['name'] === element['pickup_location']);
332
- }
333
- if (filterval[0]['type'] === 'destination location') {
334
- result_list_boolean.push(filterval[0]['name'] === element['delivery_location']);
335
- }
336
- if (filterval[0]['type'] === 'job') {
337
- result_list_boolean.push(filterval[0]['name'] === element['order_number']);
338
- }
339
- if (filterval[0]['type'] === 'Route name') {
340
- result_list_boolean.push(filterval[0]['name'] === element['route_name']);
341
- }
342
- if (filterval[0]['type'] === 'Driver') {
343
- const index = element.driver_list?.findIndex((ele) => {
344
- return filterval[0]['name'] === ele['driver_name'];
345
- });
346
- if (index !== -1)
347
- result_list_boolean.push(true);
348
- }
349
- if (filterval[0]['type'] === 'Trucking Company') {
350
- const index = element.driver_list?.findIndex((ele) => {
351
- return filterval[0]['name'] === ele['trucking_company'];
352
- });
353
- if (index !== -1)
354
- result_list_boolean.push(true);
355
- }
356
- }
357
- if (result_list_boolean.length > 0) {
358
- return result_list_boolean.reduce((prev, curr) => prev && curr);
359
- }
360
- return false;
361
- });
362
- }
363
- clearOptions() {
364
- this.pickupOptions = [];
365
- this.destOptions = [];
366
- this.ownerOptions = [];
367
- this.customerOptions = [];
368
- this.unitOptions = [];
369
- this.materialOptions = [];
370
- this.jcodeOptions = [];
371
- this.routeNameOptions = [];
372
- }
373
- setdictValue(key, value) {
374
- this.dict.set(key, value);
375
- }
376
- getdictValue(key) {
377
- return JSON.parse(this.dict.get(key));
378
- }
379
- removedictValue(key) {
380
- this.dict.delete(key);
381
- }
382
- conveySearchIcon(value) {
383
- if (value && typeof value !== 'object')
384
- return true;
385
- return false;
386
- }
387
- fetchUnitsList() {
388
- return new Promise((resolve, reject) => {
389
- if (!this.unitsList) {
390
- this.getData('unit/list/view').subscribe((res) => {
391
- if (res) {
392
- this.unitsList = res.data;
393
- resolve(this.unitsList);
394
- }
395
- });
396
- }
397
- else {
398
- resolve(this.unitsList);
399
- }
400
- });
401
- }
402
- fetchMaterialsList() {
403
- return new Promise((resolve, reject) => {
404
- if (!this.materialsList) {
405
- this.getData('material/list/view').subscribe((res) => {
406
- this.materialsList = this.filtermaterialList(res.data);
407
- resolve(this.materialsList);
408
- });
409
- }
410
- else {
411
- resolve(this.materialsList);
412
- }
413
- });
414
- }
415
- fetchMaterialsListForCustomer() {
416
- return new Promise((resolve, reject) => {
417
- if (!this.materialsListForCustomer) {
418
- this.getData('material/list/view').subscribe((res) => {
419
- this.materialsListForCustomer = this.filtermaterialList(res.data);
420
- resolve(this.materialsListForCustomer);
421
- });
422
- }
423
- else {
424
- resolve(this.materialsListForCustomer);
425
- }
426
- });
427
- }
428
- filtermaterialList(list) {
429
- let meterialList = [];
430
- list.map((item) => {
431
- if (item.sub.length > 0) {
432
- item.sub.map((subItem) => {
433
- if (subItem.add_to_marketplace) {
434
- subItem.material = item.material;
435
- subItem.material_id = item.material_id;
436
- subItem.label = item.material + ' | ' + subItem.sub_material;
437
- meterialList.push(subItem);
438
- }
439
- });
440
- }
441
- });
442
- meterialList.sort((a, b) => a.label.localeCompare(b.label));
443
- return meterialList;
444
- }
445
- fetchCustomersList() {
446
- return new Promise((resolve, reject) => {
447
- if (!this.customersList) {
448
- this.getData('company/list/view').subscribe((res) => {
449
- if (res) {
450
- this.customersList = res.data;
451
- resolve(this.customersList);
452
- }
453
- });
454
- }
455
- else {
456
- resolve(this.customersList);
457
- }
458
- });
459
- }
460
- fetchLocationlist() {
461
- return new Promise((resolve, reject) => {
462
- this.getRestData('locations/all').subscribe((res) => {
463
- if (res) {
464
- this.locationList = res.data;
465
- this.locationList = this.locationList.map((object) => {
466
- object.formatted_address = `${object.name} | ${object.street} ${object.city}, ${object.state} ${object.zip}`;
467
- const newItem = {
468
- city: object.city,
469
- lng: object.longitude,
470
- location_id: object.location_id,
471
- lat: object.latitude,
472
- name: object.name,
473
- state: object.state,
474
- street: object.street,
475
- zip: object.zip,
476
- formatted_address: object.formatted_address
477
- };
478
- return newItem;
479
- });
480
- resolve(this.locationList);
481
- }
482
- }, err => {
483
- console.log(err);
484
- });
485
- });
486
- }
487
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.2.1", ngImport: i0, type: UtilsService, deps: [{ token: i1.HttpClient }, { token: i2.MatSnackBar }, { token: 'memberData' }, { token: i0.NgZone }], target: i0.ɵɵFactoryTarget.Injectable });
488
- static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.2.1", ngImport: i0, type: UtilsService, providedIn: 'root' });
489
- }
490
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.2.1", ngImport: i0, type: UtilsService, decorators: [{
491
- type: Injectable,
492
- args: [{ providedIn: 'root' }]
493
- }], ctorParameters: () => [{ type: i1.HttpClient }, { type: i2.MatSnackBar }, { type: CoolmapConfigModel, decorators: [{
494
- type: Inject,
495
- args: ['memberData']
496
- }] }, { type: i0.NgZone }] });
497
-
498
- class CoolmapService {
499
- utils;
500
- eventManager;
501
- config;
502
- map;
503
- markerOriginList = [];
504
- markerDestinationList = [];
505
- initiatecoolmap = new BehaviorSubject(true);
506
- reintiatecoolmap = this.initiatecoolmap.asObservable();
507
- bounds = new mapboxgl.LngLatBounds();
508
- originDestinationCordinates = [];
509
- padding;
510
- windowActualHeightWidth;
511
- popup;
512
- customTopForCustomer;
513
- constructor(utils, eventManager, config) {
514
- this.utils = utils;
515
- this.eventManager = eventManager;
516
- this.config = config;
517
- this.customTopForCustomer = this.config.repository === 'customer' ? 65 : 0;
518
- this.windowActualHeightWidth = { availHeight: 0 };
519
- window.addEventListener('resize', this.onResize.bind(this));
520
- }
521
- initiateMapForAddRoute(el) {
522
- return new Promise((resolve, reject) => {
523
- if (this.map)
524
- this.map.remove();
525
- this.map = new mapboxgl.Map({
526
- accessToken: this.config.mapboxAccessToken,
527
- container: el,
528
- style: this.config.mapboxStyle,
529
- center: [-77.036873, 38.907192],
530
- zoom: 10,
531
- bearing: 0,
532
- pitch: 65,
533
- interactive: true,
534
- });
535
- this.map.once('load', (res) => {
536
- resolve(res);
537
- });
538
- });
539
- }
540
- // Below method Load route with animation
541
- loadMapProperty(pinRouteGeojson, index, unit, route, bottom) {
542
- return new Promise((resolve, reject) => {
543
- let origin = pinRouteGeojson.features[0].geometry.coordinates[0];
544
- const linecolor = unit === 'Ton' ? '#ff7272' : unit === 'Load' ? '#a3c52e' : '#ae23d1';
545
- let destination = pinRouteGeojson.features[0].geometry.coordinates[pinRouteGeojson.features[0].geometry.coordinates.length - 1];
546
- this.extendBound(pinRouteGeojson.features[0].geometry.coordinates, true).then((res) => {
547
- const point = {
548
- type: 'FeatureCollection',
549
- features: [
550
- {
551
- type: 'Feature',
552
- properties: {},
553
- geometry: { type: 'Point', coordinates: origin },
554
- },
555
- ],
556
- };
557
- const lineDistance = turf.length(pinRouteGeojson.features[0]);
558
- const arc = [];
559
- const steps = 10 * pinRouteGeojson.features[0].geometry.coordinates.length;
560
- for (let i = 0; i < lineDistance; i += lineDistance / steps) {
561
- const segment = turf.along(pinRouteGeojson.features[0], i);
562
- arc.push(segment.geometry.coordinates);
563
- }
564
- pinRouteGeojson.features[0].geometry.coordinates = arc;
565
- const pinRoute = pinRouteGeojson.features[0].geometry.coordinates;
566
- if (pinRoute && pinRoute.length) {
567
- const marker = new mapboxgl.Marker(document.createElement('div'))
568
- .setLngLat(pinRoute[0])
569
- .addTo(this.map)
570
- .togglePopup();
571
- if (this.map.getSource(`line${index}`)) {
572
- this.removeRouteAndMarker(index).then(() => { });
573
- }
574
- this.map.addSource(`line${index}`, {
575
- type: 'geojson',
576
- lineMetrics: true,
577
- data: pinRouteGeojson,
578
- });
579
- this.map.addLayer({
580
- type: 'line',
581
- source: `line${index}`,
582
- id: `line${index}`,
583
- paint: {
584
- 'line-width': 2,
585
- 'line-gradient': [
586
- 'interpolate',
587
- ['linear'],
588
- ['line-progress'],
589
- 0,
590
- unit === 'Ton'
591
- ? '#d7f7e4'
592
- : unit === 'Load'
593
- ? '#c9d8f5'
594
- : '#f5dcc1',
595
- 1,
596
- unit === 'Ton'
597
- ? '#ff7272'
598
- : unit === 'Load'
599
- ? '#a3c52e'
600
- : '#ae23d1',
601
- ],
602
- },
603
- layout: { 'line-cap': 'round', 'line-join': 'round' },
604
- });
605
- const dataSetForMap = {
606
- counter: 0,
607
- pinRouteGeojson,
608
- steps,
609
- point,
610
- pointId: `point${index}`,
611
- marker,
612
- pinRoute,
613
- lineId: `line${index}`,
614
- index,
615
- origin,
616
- destination,
617
- lineDistance,
618
- linecolor,
619
- route,
620
- isViewRoute: true,
621
- };
622
- this.createMarker(dataSetForMap);
623
- this.map.on('mouseenter', `line${index}`, (e) => {
624
- this.map.setPaintProperty(`line${index}`, 'line-width', 5);
625
- this.map.setPaintProperty(`line${index}`, 'line-opacity', 1);
626
- const datasetForPopup = {
627
- coordinate: [e.lngLat.lng, e.lngLat.lat],
628
- pickup: route.pickup_location ? route.pickup_location : '',
629
- drop: route.delivery_location ? route.delivery_location : '',
630
- routeType: route.project ? 'Project' : 'Route',
631
- title: route.project
632
- ? route.project
633
- : route.route_name
634
- ? route.route_name
635
- : '',
636
- material: route.material ? route.material : '',
637
- type: route.unit ? route.unit : '',
638
- };
639
- this.createPopup(datasetForPopup);
640
- });
641
- this.map.on('mouseleave', `line${index}`, (e) => {
642
- this.map.setPaintProperty(`line${index}`, 'line-width', 2);
643
- if (this.popup) {
644
- this.popup.remove();
645
- }
646
- });
647
- }
648
- });
649
- this.map.once('idle', (res) => {
650
- resolve(true);
651
- });
652
- });
653
- }
654
- // Below method Load route without animation
655
- drawLine(cordinates, index, route, enablefitbound, routeType) {
656
- let linecolor;
657
- let origin = cordinates[0];
658
- let destination = cordinates[cordinates.length - 1];
659
- if (origin[0] &&
660
- origin[1] &&
661
- destination &&
662
- destination[0] &&
663
- destination[1]) {
664
- this.map.once('idle', (res) => {
665
- linecolor = this.provideLineColor(route['unit'], routeType);
666
- if (enablefitbound) {
667
- const padding = {
668
- top: this.padding.top + this.customTopForCustomer,
669
- bottom: this.padding.bottom +
670
- (this.windowActualHeightWidth.availHeight -
671
- (window.innerHeight - 65)),
672
- left: this.padding.left,
673
- right: this.padding.right,
674
- };
675
- this.map.fitBounds([origin, destination], { padding, pitch: 65 }, { fitboundCompleteJob: true });
676
- }
677
- if (this.map.getSource(`route-source-for-job-code${index}`)) {
678
- this.removeRouteAndMarker(index).then(() => { });
679
- }
680
- this.map.addSource(`route-source-for-job-code${index}`, {
681
- type: 'geojson',
682
- data: {
683
- type: 'Feature',
684
- properties: {},
685
- geometry: { type: 'LineString', coordinates: cordinates },
686
- },
687
- });
688
- this.map.addLayer({
689
- id: `route-for-job-code${index}`,
690
- type: 'line',
691
- source: `route-source-for-job-code${index}`,
692
- paint: { 'line-color': linecolor, 'line-width': 2 },
693
- layout: { 'line-cap': 'round', 'line-join': 'round' },
694
- });
695
- const dataSetForMap = {
696
- origin,
697
- destination,
698
- index,
699
- linecolor,
700
- route,
701
- };
702
- this.createMarker(dataSetForMap);
703
- this.map.on('mouseenter', `route-for-job-code${index}`, (e) => {
704
- if (this.popup) {
705
- this.popup.remove();
706
- }
707
- this.map.setPaintProperty(`route-for-job-code${index}`, 'line-width', 5);
708
- this.map.setPaintProperty(`route-for-job-code${index}`, 'line-opacity', 1);
709
- const datasetForPopup = {
710
- coordinate: [e.lngLat.lng, e.lngLat.lat],
711
- pickup: route.pickup_location ? route.pickup_location : '',
712
- drop: route.delivery_location ? route.delivery_location : '',
713
- jobCode: route.project ? route.order_number : null,
714
- customer: route.project ? route.customer_name : null,
715
- routeType: route.project ? 'Project' : 'Route',
716
- title: route.project
717
- ? route.project
718
- : route.route_name
719
- ? route.route_name
720
- : '',
721
- material: route.material ? route.material : '',
722
- type: route.unit ? route.unit : '',
723
- };
724
- this.createPopup(datasetForPopup);
725
- });
726
- this.map.on('mouseleave', `route-for-job-code${index}`, (e) => {
727
- this.map.setPaintProperty(`route-for-job-code${index}`, 'line-width', 2);
728
- if (this.popup) {
729
- this.popup.remove();
730
- }
731
- });
732
- });
733
- }
734
- }
735
- provideLineColor(unitType, type) {
736
- let checkType = type && !['jobrouteList', 'addroute'].includes(type) ? true : false;
737
- let color;
738
- switch (unitType) {
739
- case 'Ton':
740
- color = checkType ? '#39c471' : '#ff7272';
741
- break;
742
- case 'Load':
743
- color = checkType ? '#326ad3' : '#a3c52e';
744
- break;
745
- case 'Hourly':
746
- color = checkType ? '#ffad56' : '#ae23d1';
747
- break;
748
- }
749
- return color;
750
- }
751
- showRoutePopup(arcDetails, event, isViewRoute) {
752
- if (this.popup) {
753
- this.popup.remove();
754
- this.map.setPaintProperty(`${isViewRoute ? 'line' : 'route-for-job-code'}${arcDetails.layer.props.data.index}`, 'line-width', 2);
755
- }
756
- if (arcDetails.color &&
757
- this.map.getLayoutProperty(arcDetails.layer.id, 'visibility') !== 'none') {
758
- this.map.setPaintProperty(`${isViewRoute ? 'line' : 'route-for-job-code'}${arcDetails.layer.props.data.index}`, 'line-width', 5);
759
- this.map.setPaintProperty(`${isViewRoute ? 'line' : 'route-for-job-code'}${arcDetails.layer.props.data.index}`, 'line-opacity', 1);
760
- const datasetForPopup = {
761
- coordinate: arcDetails.coordinate,
762
- pickup: arcDetails.layer.props.data.route.pickup_location
763
- ? arcDetails.layer.props.data.route.pickup_location
764
- : '',
765
- drop: arcDetails.layer.props.data.route.delivery_location
766
- ? arcDetails.layer.props.data.route.delivery_location
767
- : '',
768
- jobCode: arcDetails.layer.props.data.route.project
769
- ? arcDetails.layer.props.data.route.order_number
770
- : '',
771
- customer: arcDetails.layer.props.data.route.project
772
- ? arcDetails.layer.props.data.route.customer_name
773
- : '',
774
- routeType: arcDetails.layer.props.data.route.project
775
- ? 'Project'
776
- : 'Route',
777
- title: arcDetails.layer.props.data.route.project
778
- ? arcDetails.layer.props.data.route.project
779
- : arcDetails.layer.props.data.route.route_name
780
- ? arcDetails.layer.props.data.route.route_name
781
- : '',
782
- material: arcDetails.layer.props.data.route.material
783
- ? arcDetails.layer.props.data.route.material
784
- : '',
785
- type: arcDetails.layer.props.data.route.unit
786
- ? arcDetails.layer.props.data.route.unit
787
- : '',
788
- };
789
- this.createPopup(datasetForPopup);
790
- }
791
- }
792
- createPopup(datasetForPopup) {
793
- this.popup = new mapboxgl.Popup({
794
- closeButton: false,
795
- closeOnClick: false,
796
- closeOnMove: true,
797
- anchor: 'bottom-left',
798
- });
799
- this.popup
800
- .setLngLat(datasetForPopup.coordinate)
801
- .setHTML(`<div class="destination">
802
- <div class="duration">
803
- <p class="pickprt"><b>Pickup Location:</b> ${datasetForPopup.pickup}</p>
804
- <p class="dropprt"><b>Drop Location:</b> ${datasetForPopup.drop}</p>
805
- </div>
806
- ${datasetForPopup.jobCode
807
- ? '<span><b>Job Code:</b> ' + datasetForPopup.jobCode + '</span>'
808
- : ''}
809
- ${datasetForPopup.customer
810
- ? '<span><b>Customer:</b> ' + datasetForPopup.customer + '</span>'
811
- : ''}
812
- <span>
813
- <b>${datasetForPopup.routeType} Name:</b>
814
- ${datasetForPopup.title}
815
- </span>
816
- ${datasetForPopup.material
817
- ? '<span><b>Material:</b> ' + datasetForPopup.material + '</span>'
818
- : ''}
819
- <span><b>Type:</b> ${datasetForPopup.type}</span>
820
- </div>`)
821
- .addTo(this.map);
822
- }
823
- hexToRGB(hex) {
824
- return hex
825
- .replace(/^#?([a-f\d])([a-f\d])([a-f\d])$/i, (m, r, g, b) => '#' + r + r + g + g + b + b)
826
- .substring(1)
827
- .match(/.{2}/g)
828
- .map((x) => parseInt(x, 16));
829
- }
830
- createMarker(routeDetails) {
831
- if (routeDetails.origin[0] &&
832
- routeDetails.origin[1] &&
833
- routeDetails.destination[0] &&
834
- routeDetails.destination[1]) {
835
- const popup = new mapboxgl.Popup({ closeButton: false }).setHTML('<b>Pickup: </b>' + routeDetails.route?.pickup_location);
836
- const popupForDestination = new mapboxgl.Popup({
837
- closeButton: false,
838
- }).setHTML('<b>Delivery: </b>' + routeDetails.route?.delivery_location);
839
- const el = document.createElement('div');
840
- el.className = 'marker';
841
- el.innerHTML = `<span class='markerPointer' style='background:${routeDetails.linecolor}'><b>P</b><span class='markerSpan' style='border-top: 10px solid ${routeDetails.linecolor}'></span></span>`;
842
- const originMarker = new mapboxgl.Marker(el)
843
- .setPopup(popup)
844
- .setLngLat(routeDetails.origin)
845
- .addTo(this.map);
846
- originMarker
847
- .getElement()
848
- .addEventListener('mouseenter', () => originMarker.togglePopup());
849
- originMarker
850
- .getElement()
851
- .addEventListener('mouseleave', () => originMarker.togglePopup());
852
- const elementForDestination = document.createElement('div');
853
- elementForDestination.className = 'marker';
854
- elementForDestination.innerHTML = `<span class='markerPointer' style='background:${routeDetails.linecolor}'><b>D</b><span class='markerSpan' style='border-top: 10px solid ${routeDetails.linecolor}'></span></span>`;
855
- const destinationMarker = new mapboxgl.Marker(elementForDestination)
856
- .setPopup(popupForDestination)
857
- .setLngLat(routeDetails.destination)
858
- .addTo(this.map);
859
- destinationMarker
860
- .getElement()
861
- .addEventListener('mouseenter', () => destinationMarker.togglePopup());
862
- destinationMarker
863
- .getElement()
864
- .addEventListener('mouseleave', () => destinationMarker.togglePopup());
865
- this.markerOriginList[routeDetails.index] = originMarker;
866
- this.markerDestinationList[routeDetails.index] = destinationMarker;
867
- const colorArray = this.hexToRGB(routeDetails.linecolor);
868
- const arcLayer = new MapboxLayer({
869
- id: 'arc-layer' + routeDetails.index,
870
- type: ArcLayer,
871
- pickable: true,
872
- data: { route: routeDetails.route, index: routeDetails.index },
873
- getWidth: 1,
874
- getSourcePosition: routeDetails.origin,
875
- getTargetPosition: routeDetails.destination,
876
- getTargetColor: [255, 255, 255],
877
- getSourceColor: [colorArray[0], colorArray[1], colorArray[2]],
878
- onHover: (info, event) => this.showRoutePopup(info, event, routeDetails.isViewRoute),
879
- });
880
- this.map.addLayer(arcLayer);
881
- }
882
- }
883
- async removeRouteAndMarker(index) {
884
- if (this.map) {
885
- this.map.getLayer(`arc-layer${index}`)
886
- ? this.map.removeLayer(`arc-layer${index}`)
887
- : '';
888
- this.map.getLayer(`line${index}`)
889
- ? this.map.removeLayer(`line${index}`)
890
- : '';
891
- this.map.getLayer(`custom_layer${index}`)
892
- ? this.map.removeLayer(`custom_layer${index}`)
893
- : '';
894
- this.map.getSource(`line${index}`)
895
- ? this.map.removeSource(`line${index}`)
896
- : '';
897
- this.map.getLayer(`route-for-job-code${index}`)
898
- ? this.map.removeLayer(`route-for-job-code${index}`)
899
- : '';
900
- this.map.getSource(`route-source-for-job-code${index}`)
901
- ? this.map.removeSource(`route-source-for-job-code${index}`)
902
- : '';
903
- this.findMarkerBound(index);
904
- this.markerOriginList[index] ? this.markerOriginList[index].remove() : '';
905
- this.markerDestinationList[index]
906
- ? this.markerDestinationList[index].remove()
907
- : '';
908
- await true;
909
- }
910
- }
911
- findMarkerBound(index) {
912
- const indexOfCordinates = this.originDestinationCordinates.findIndex((x) => x[0][0].toFixed(6) ==
913
- this.markerOriginList[index]?.getLngLat()?.lng.toFixed(6) &&
914
- x[0][1].toFixed(6) ==
915
- this.markerOriginList[index]?.getLngLat()?.lat.toFixed(6));
916
- if (indexOfCordinates >= 0) {
917
- this.originDestinationCordinates.splice(indexOfCordinates, 1);
918
- }
919
- }
920
- async filterRoute(ID, visibility, showAllFitbound) {
921
- if (ID) {
922
- if (this.map.getLayer(`route-for-job-code${ID}`)) {
923
- this.map.setLayoutProperty(`route-for-job-code${ID}`, 'visibility', visibility);
924
- const originM = this.markerOriginList[ID].getElement();
925
- originM.style.display = visibility === 'visible' ? 'block' : visibility;
926
- const destinationM = this.markerDestinationList[ID].getElement();
927
- destinationM.style.display =
928
- visibility === 'visible' ? 'block' : visibility;
929
- if (visibility === 'none' && showAllFitbound) {
930
- this.findMarkerBound(ID);
931
- this.extendReBound();
932
- }
933
- }
934
- if (this.map.getLayer(`arc-layer${ID}`)) {
935
- this.map.setLayoutProperty(`arc-layer${ID}`, 'visibility', visibility);
936
- }
937
- }
938
- await true;
939
- }
940
- extendBound(route, showAllFitbound) {
941
- return new Promise((resolve, reject) => {
942
- if (route) {
943
- if (typeof route === 'string') {
944
- let path = route.split(';');
945
- path = path.map((ele) => {
946
- return (ele = this.formateLatLong(ele));
947
- });
948
- path.forEach((ele, index) => {
949
- if (ele.length === 1)
950
- path.splice(index, 1);
951
- });
952
- route = path;
953
- }
954
- if (route[0][0] &&
955
- route[0][1] &&
956
- route[route.length - 1][0] &&
957
- route[route.length - 1][1]) {
958
- this.originDestinationCordinates.push(route);
959
- route.map((item) => {
960
- this.bounds.extend(item);
961
- });
962
- }
963
- }
964
- if (showAllFitbound) {
965
- setTimeout(() => {
966
- if (showAllFitbound && Object.keys(this.bounds).length > 0)
967
- this.map.fitBounds(this.bounds, { pitch: 65 }, { fitboundComplete: true });
968
- }, 100);
969
- this.map.once('moveend', (event) => {
970
- if (event.fitboundComplete) {
971
- resolve(true);
972
- }
973
- });
974
- }
975
- });
976
- }
977
- extendReBound(bottom) {
978
- return new Promise((resolve, reject) => {
979
- this.bounds = new mapboxgl.LngLatBounds();
980
- if (this.originDestinationCordinates.length >= 0) {
981
- this.originDestinationCordinates.map((item, index) => {
982
- item.map((route) => {
983
- this.bounds.extend(route);
984
- });
985
- if (index === this.originDestinationCordinates.length - 1) {
986
- const padding = {
987
- top: this.padding.top + this.customTopForCustomer,
988
- bottom: this.padding.bottom +
989
- (this.windowActualHeightWidth.availHeight -
990
- (window.innerHeight - 65)),
991
- left: this.padding.left,
992
- right: this.padding.right,
993
- };
994
- setTimeout(() => {
995
- if (this.originDestinationCordinates.length > 0)
996
- this.map.fitBounds(this.bounds, { padding, pitch: 65 });
997
- }, 500);
998
- resolve(true);
999
- }
1000
- });
1001
- }
1002
- else {
1003
- resolve(true);
1004
- }
1005
- });
1006
- }
1007
- plotRoute(route, i, type, enablefitbound, showAllFitbound) {
1008
- return new Promise((resolve, reject) => {
1009
- let param = {};
1010
- if (['jobcode'].includes(type)) {
1011
- param['job'] = route['job_id'];
1012
- this.utils.postDataWithRestUrl('schedule/job/path', param).subscribe((res) => {
1013
- if (res['data']['route']) {
1014
- let path = res['data']['route'].split(';');
1015
- path = path.map((ele) => {
1016
- return (ele = this.formateLatLong(ele));
1017
- });
1018
- path.forEach((ele, index) => {
1019
- if (ele.length === 1)
1020
- path.splice(index, 1);
1021
- });
1022
- route['path'] = path;
1023
- this.extendBound(route['path'], showAllFitbound);
1024
- if (route['path'] && route['path'].length > 0)
1025
- this.drawLine(route['path'], i, route, enablefitbound, type);
1026
- route['index'] = i;
1027
- }
1028
- else {
1029
- this.extendBound(null, showAllFitbound);
1030
- }
1031
- resolve(true);
1032
- }, (err) => {
1033
- if (err) {
1034
- reject(false);
1035
- }
1036
- });
1037
- }
1038
- else if (['jobrouteList', 'addroute'].includes(type)) {
1039
- if (route['path'] && route['path'].length > 0) {
1040
- let path = route['path'].split(';');
1041
- path = path.map((ele) => {
1042
- return (ele = this.formateLatLong(ele));
1043
- });
1044
- path.forEach((ele, index) => {
1045
- if (ele.length === 1)
1046
- path.splice(index, 1);
1047
- });
1048
- this.extendBound(path, showAllFitbound);
1049
- this.drawLine(path, i, route, enablefitbound, type);
1050
- }
1051
- }
1052
- });
1053
- }
1054
- clearBound() {
1055
- this.bounds = new mapboxgl.LngLatBounds();
1056
- this.originDestinationCordinates = [];
1057
- this.clearPadding();
1058
- }
1059
- formateLatLong(latlong) {
1060
- return latlong
1061
- ? latlong
1062
- .split(',')
1063
- .map((x) => +x)
1064
- .reverse()
1065
- : null;
1066
- }
1067
- clearBoundWithCordinates() {
1068
- this.bounds = new mapboxgl.LngLatBounds();
1069
- this.originDestinationCordinates = [];
1070
- }
1071
- onResize(event) {
1072
- if (!this.bounds.isEmpty()) {
1073
- this.windowActualHeightWidth.availHeight =
1074
- window.innerHeight > window.screen.availHeight
1075
- ? window.innerHeight
1076
- : window.screen.availHeight;
1077
- setTimeout(() => {
1078
- this.map.fitBounds(this.bounds, {
1079
- padding: {
1080
- top: this.padding.top + this.customTopForCustomer,
1081
- bottom: this.padding.bottom +
1082
- (this.windowActualHeightWidth.availHeight -
1083
- (event.target.innerHeight - 65)),
1084
- left: this.padding.left,
1085
- right: this.padding.right,
1086
- },
1087
- pitch: 65,
1088
- });
1089
- }, 500);
1090
- }
1091
- }
1092
- setWindowHeight(screen) {
1093
- this.windowActualHeightWidth.availHeight = screen;
1094
- }
1095
- setPadding(padding) {
1096
- this.padding = padding;
1097
- }
1098
- clearPadding() {
1099
- this.padding = null;
1100
- }
1101
- removeJobFromMap(data) {
1102
- data.map((ele, index) => {
1103
- const id = ele['job_id'] ? ele['job_id'] : ele['route_id'];
1104
- this.removeRouteAndMarker(id);
1105
- if (index === data.length - 1) {
1106
- this.extendReBound();
1107
- }
1108
- });
1109
- }
1110
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.2.1", ngImport: i0, type: CoolmapService, deps: [{ token: UtilsService }, { token: i2$1.EventManager }, { token: 'memberData' }], target: i0.ɵɵFactoryTarget.Injectable });
1111
- static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.2.1", ngImport: i0, type: CoolmapService, providedIn: 'root' });
1112
- }
1113
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.2.1", ngImport: i0, type: CoolmapService, decorators: [{
1114
- type: Injectable,
1115
- args: [{ providedIn: 'root' }]
1116
- }], ctorParameters: () => [{ type: UtilsService }, { type: i2$1.EventManager }, { type: CoolmapConfigModel, decorators: [{
1117
- type: Inject,
1118
- args: ['memberData']
1119
- }] }] });
1120
-
1121
- /*
1122
- * Public API Surface of @aggdirect/coolmap-services
1123
- */
1124
-
1125
- /**
1126
- * Generated bundle index. Do not edit.
1127
- */
1128
-
1129
- export { CoolmapConfigModel, CoolmapService, DriverSmsCardEnum, DriversmsCardKey, EstinationData, EstinationEnum, JobCodeOverviewData, JobCodeOverviewEnum, PopupData, Route, UtilsService };
1130
- //# sourceMappingURL=aggdirect-coolmap-services.mjs.map