@aggdirect/coolmap-services 1.0.7 → 1.0.9

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.
@@ -0,0 +1,741 @@
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
+ constructor() {
14
+ this.index = 0;
15
+ }
16
+ }
17
+ const EstinationData = ['estimated_distance', 'estimated_time'];
18
+ var EstinationEnum;
19
+ (function (EstinationEnum) {
20
+ EstinationEnum["estimated_distance"] = "miles";
21
+ EstinationEnum["estimated_time"] = "time";
22
+ })(EstinationEnum || (EstinationEnum = {}));
23
+ const JobCodeOverviewData = ['customer_contact', 'delivery_contact', 'pickup_location', 'delivery_location', 'project', 'unit'];
24
+ var JobCodeOverviewEnum;
25
+ (function (JobCodeOverviewEnum) {
26
+ JobCodeOverviewEnum["customer_contact"] = "Customer Contact";
27
+ JobCodeOverviewEnum["delivery_contact"] = "Delivery Contact";
28
+ JobCodeOverviewEnum["pickup_location"] = "Pickup";
29
+ JobCodeOverviewEnum["delivery_location"] = "Delivery";
30
+ JobCodeOverviewEnum["project"] = "Project Name";
31
+ JobCodeOverviewEnum["unit"] = "Job Type";
32
+ })(JobCodeOverviewEnum || (JobCodeOverviewEnum = {}));
33
+ const DriversmsCardKey = ['order_number', 'date', 'values', 'material', 'unit', 'pickup_location', 'delivery_location'];
34
+ var DriverSmsCardEnum;
35
+ (function (DriverSmsCardEnum) {
36
+ DriverSmsCardEnum["order_number"] = "Jobcode";
37
+ DriverSmsCardEnum["date"] = "Date";
38
+ DriverSmsCardEnum["values"] = "Total tasks";
39
+ DriverSmsCardEnum["material"] = "Material";
40
+ DriverSmsCardEnum["unit"] = "Unit";
41
+ DriverSmsCardEnum["pickup_location"] = "Pickup Address";
42
+ DriverSmsCardEnum["delivery_location"] = "Delivery Address";
43
+ })(DriverSmsCardEnum || (DriverSmsCardEnum = {}));
44
+ class PopupData {
45
+ }
46
+ class CoolmapConfigModel {
47
+ }
48
+
49
+ class UtilsService {
50
+ constructor(http, snackBar, config) {
51
+ this.http = http;
52
+ this.snackBar = snackBar;
53
+ this.config = config;
54
+ this.analyticsRESTURL = '';
55
+ this.RESTURLPrefix = '';
56
+ this.pickupOptions = [];
57
+ this.destOptions = [];
58
+ this.ownerOptions = [];
59
+ this.customerOptions = [];
60
+ this.unitOptions = [];
61
+ this.materialOptions = [];
62
+ this.jcodeOptions = [];
63
+ this.driverOption = [];
64
+ this.truckingCompanayOption = [];
65
+ this.routeNameOptions = [];
66
+ this.preventnavChange = new BehaviorSubject(false);
67
+ this.navChangeObserve = this.preventnavChange.asObservable();
68
+ this.clearViewRouteforJobCode = new BehaviorSubject(false);
69
+ this.clearViewRouteforJobCodeObserve = this.clearViewRouteforJobCode.asObservable();
70
+ this.preVentJobdetailclose = new BehaviorSubject(false);
71
+ this.getpreVentJobdetailclose = this.preVentJobdetailclose.asObservable();
72
+ this.routeDetailsUtility = new BehaviorSubject({});
73
+ this.getrouteDetailsUtility = this.routeDetailsUtility.asObservable();
74
+ this.removeMapEntity = new BehaviorSubject({});
75
+ this.removeMapEntityUtility = this.removeMapEntity.asObservable();
76
+ this.dict = new Map();
77
+ this.analyticsRESTURL = config.analyticsRESTURL;
78
+ this.RESTURLPrefix = config.RESTURLPrefix;
79
+ }
80
+ getDateFormat(strVal, seprater) {
81
+ seprater = seprater ? seprater : '-';
82
+ const mydate = strVal;
83
+ return mydate?.getFullYear() + seprater + ((mydate ? mydate.getMonth() : 0) + 1) + seprater + mydate?.getDate();
84
+ }
85
+ getData(path) { return this.http.get(`${this.analyticsRESTURL}${this.config.repository}/${path}`); }
86
+ postdata(path, data) { return this.http.post(`${this.analyticsRESTURL}${this.config.repository}/${path}`, data); }
87
+ postDataWithRestUrl(path, data) { return this.http.post(`${this.RESTURLPrefix}${path}`, data); }
88
+ fetchAutoCompleteLocations(keyword) {
89
+ return this.http.get(`https://api.mapbox.com/geocoding/v5/mapbox.places/${keyword}.json?access_token=pk.eyJ1Ijoic2FudGFudS1vZ21hIiwiYSI6ImNsOGQ0cDVrNjAweTMzb3RmdG9ieTU5ZDkifQ.I6ZS7mViZYSvBo4zz-mGQQ&country=US`);
90
+ }
91
+ openSnackBar(message, className) {
92
+ this.snackBar.open(message, '', {
93
+ duration: 5000, verticalPosition: 'top', horizontalPosition: 'center', panelClass: [className ? className : 'default']
94
+ });
95
+ }
96
+ makeOptions(item) {
97
+ if (item.order_number) {
98
+ (this.jcodeOptions.findIndex((elem) => elem.job_id === item.job_id) === -1) ? this.jcodeOptions.push({ job_code: item.order_number, job_id: item.job_id }) : null;
99
+ if (item.driver_list && item.driver_list?.length > 0) {
100
+ item.driver_list.forEach((driver) => {
101
+ this.driverOption.findIndex(elem => elem === driver['driver_name']) === -1 ? this.driverOption.push(driver['driver_name']) : null;
102
+ this.truckingCompanayOption.findIndex(elem => elem === driver['trucking_company']) === -1 ? this.truckingCompanayOption.push(driver['trucking_company']) : null;
103
+ });
104
+ }
105
+ }
106
+ ((this.pickupOptions.findIndex((elem) => elem === item.pickup_location)) === -1) ? this.pickupOptions.push(item.pickup_location) : null;
107
+ ((this.destOptions.findIndex((elem) => elem === item.delivery_location)) === -1) ? this.destOptions.push(item.delivery_location) : null;
108
+ (this.customerOptions.findIndex((customer) => customer === item.customer_name) === -1) ? this.customerOptions.push(item.customer_name) : null;
109
+ (this.unitOptions.findIndex((elem) => elem === item.unit) === -1) ? this.unitOptions.push(item.unit) : null;
110
+ (this.materialOptions.findIndex((elem) => elem === item.material) === -1) ? this.materialOptions.push(item.material) : null;
111
+ if (item.route_name)
112
+ this.routeNameOptions.findIndex(elem => elem === item.route_name) === -1 ? this.routeNameOptions.push(item.route_name) : null;
113
+ }
114
+ filter(value, filters) {
115
+ if (typeof value !== 'string') {
116
+ return [];
117
+ }
118
+ const filterValue = value.toLowerCase();
119
+ if (filterValue === '') {
120
+ return [];
121
+ }
122
+ const searchResults = [];
123
+ this.unitOptions.map(unit => {
124
+ if (unit.toLowerCase().includes(filterValue)) {
125
+ searchResults.push({ "type": "unit", "label": unit, "value": unit });
126
+ }
127
+ });
128
+ this.customerOptions.map(unit => {
129
+ if (unit.toLowerCase().includes(filterValue)) {
130
+ searchResults.push({ "type": "customer", "label": unit, "value": unit });
131
+ }
132
+ });
133
+ this.materialOptions.map(unit => {
134
+ if (unit.toLowerCase().includes(filterValue)) {
135
+ searchResults.push({ "type": "material", "label": unit, "value": unit });
136
+ }
137
+ });
138
+ this.pickupOptions.map(unit => {
139
+ if (unit.toLowerCase().includes(filterValue)) {
140
+ searchResults.push({ "type": "pickup location", "label": unit, "value": unit });
141
+ }
142
+ });
143
+ this.destOptions.map(unit => {
144
+ if (unit.toLowerCase().includes(filterValue)) {
145
+ searchResults.push({ "type": "destination location", "label": unit, "value": unit });
146
+ }
147
+ });
148
+ this.jcodeOptions.map(unit => {
149
+ if (unit.job_code.toLowerCase().includes(filterValue)) {
150
+ searchResults.push({ "type": "job", "label": unit['job_code'], "value": unit });
151
+ }
152
+ });
153
+ this.driverOption.map(unit => {
154
+ if (unit.toLowerCase().includes(filterValue)) {
155
+ searchResults.push({ "type": "Driver", "label": unit, "value": unit });
156
+ }
157
+ });
158
+ this.truckingCompanayOption.map(unit => {
159
+ if (unit.toLowerCase().includes(filterValue)) {
160
+ searchResults.push({ "type": "Trucking Company", "label": unit, "value": unit });
161
+ }
162
+ });
163
+ this.routeNameOptions.map(unit => {
164
+ if (unit.toLowerCase().includes(filterValue)) {
165
+ searchResults.push({ "type": "Route name", "label": unit, "value": unit });
166
+ }
167
+ });
168
+ const searchDict = {};
169
+ filters.map((filter) => {
170
+ searchDict[filter['name'] + filter['type']] = filter;
171
+ });
172
+ const furtherFilter = [];
173
+ searchResults.map(search => {
174
+ if ((search['label'] + search['type']) in searchDict) { }
175
+ else {
176
+ furtherFilter.push(search);
177
+ }
178
+ });
179
+ return furtherFilter;
180
+ }
181
+ getSearchResults(list, filterval) {
182
+ return list.filter(element => {
183
+ const result_list_boolean = [];
184
+ if (filterval.length > 0) {
185
+ if (filterval[0]['type'] === 'unit') {
186
+ result_list_boolean.push(filterval[0]['name'] === element[filterval[0]['type']]);
187
+ }
188
+ if (filterval[0]['type'] === 'customer') {
189
+ result_list_boolean.push(filterval[0]['name'] === element['customer_name']);
190
+ }
191
+ if (filterval[0]['type'] === 'material') {
192
+ result_list_boolean.push(filterval[0]['name'] === element[filterval[0]['type']]);
193
+ }
194
+ if (filterval[0]['type'] === 'pickup location') {
195
+ result_list_boolean.push(filterval[0]['name'] === element['pickup_location']);
196
+ }
197
+ if (filterval[0]['type'] === 'destination location') {
198
+ result_list_boolean.push(filterval[0]['name'] === element['delivery_location']);
199
+ }
200
+ if (filterval[0]['type'] === 'job') {
201
+ result_list_boolean.push(filterval[0]['name'] === element['order_number']);
202
+ }
203
+ if (filterval[0]['type'] === 'Route name') {
204
+ result_list_boolean.push(filterval[0]['name'] === element['route_name']);
205
+ }
206
+ if (filterval[0]['type'] === 'Driver') {
207
+ const index = element.driver_list?.findIndex(ele => { return filterval[0]['name'] === ele['driver_name']; });
208
+ if (index !== -1)
209
+ result_list_boolean.push(true);
210
+ }
211
+ if (filterval[0]['type'] === 'Trucking Company') {
212
+ const index = element.driver_list?.findIndex(ele => { return filterval[0]['name'] === ele['trucking_company']; });
213
+ if (index !== -1)
214
+ result_list_boolean.push(true);
215
+ }
216
+ }
217
+ if (result_list_boolean.length > 0) {
218
+ return result_list_boolean.reduce((prev, curr) => prev && curr);
219
+ }
220
+ return false;
221
+ });
222
+ }
223
+ clearOptions() {
224
+ this.pickupOptions = [];
225
+ this.destOptions = [];
226
+ this.ownerOptions = [];
227
+ this.customerOptions = [];
228
+ this.unitOptions = [];
229
+ this.materialOptions = [];
230
+ this.jcodeOptions = [];
231
+ this.routeNameOptions = [];
232
+ }
233
+ setdictValue(key, value) {
234
+ this.dict.set(key, value);
235
+ }
236
+ getdictValue(key) {
237
+ return JSON.parse(this.dict.get(key));
238
+ }
239
+ removedictValue(key) {
240
+ this.dict.delete(key);
241
+ }
242
+ conveySearchIcon(value) {
243
+ if (value && typeof (value) !== 'object')
244
+ return true;
245
+ return false;
246
+ }
247
+ fetchUnitsList() {
248
+ return new Promise((resolve, reject) => {
249
+ if (!this.unitsList) {
250
+ this.getData('unit/list/view').subscribe((res) => {
251
+ if (res) {
252
+ this.unitsList = res.data;
253
+ resolve(this.unitsList);
254
+ }
255
+ });
256
+ }
257
+ else {
258
+ resolve(this.unitsList);
259
+ }
260
+ });
261
+ }
262
+ fetchMaterialsList() {
263
+ return new Promise((resolve, reject) => {
264
+ if (!this.materialsList) {
265
+ this.getData('material/list/view').subscribe(((res) => {
266
+ res.data.sort((a, b) => a.material.localeCompare(b.material));
267
+ this.materialsList = res.data;
268
+ resolve(this.materialsList);
269
+ }));
270
+ }
271
+ else {
272
+ resolve(this.materialsList);
273
+ }
274
+ });
275
+ }
276
+ fetchCustomersList() {
277
+ return new Promise((resolve, reject) => {
278
+ if (!this.customersList) {
279
+ this.getData('company/list/view').subscribe((res) => {
280
+ if (res) {
281
+ this.customersList = res.data;
282
+ }
283
+ });
284
+ }
285
+ else {
286
+ resolve(this.customersList);
287
+ }
288
+ });
289
+ }
290
+ }
291
+ UtilsService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: UtilsService, deps: [{ token: i1.HttpClient }, { token: i2.MatSnackBar }, { token: 'memberData' }], target: i0.ɵɵFactoryTarget.Injectable });
292
+ UtilsService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: UtilsService, providedIn: 'root' });
293
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: UtilsService, decorators: [{
294
+ type: Injectable,
295
+ args: [{ providedIn: 'root' }]
296
+ }], ctorParameters: function () { return [{ type: i1.HttpClient }, { type: i2.MatSnackBar }, { type: CoolmapConfigModel, decorators: [{
297
+ type: Inject,
298
+ args: ['memberData']
299
+ }] }]; } });
300
+
301
+ class CoolmapService {
302
+ constructor(utils, eventManager) {
303
+ this.utils = utils;
304
+ this.eventManager = eventManager;
305
+ this.markerOriginList = [];
306
+ this.markerDestinationList = [];
307
+ this.initiatecoolmap = new BehaviorSubject(true);
308
+ this.reintiatecoolmap = this.initiatecoolmap.asObservable();
309
+ this.bounds = new mapboxgl.LngLatBounds();
310
+ this.originDestinationCordinates = [];
311
+ this.eventManager.addGlobalEventListener('window', 'resize', this.onResize.bind(this));
312
+ this.windowActualHeightWidth = { availHeight: 0 };
313
+ }
314
+ initiateMapForAddRoute(el) {
315
+ return new Promise((resolve, reject) => {
316
+ if (this.map)
317
+ this.map.remove();
318
+ this.map = new mapboxgl.Map({
319
+ accessToken: 'pk.eyJ1Ijoic2FudGFudS1vZ21hIiwiYSI6ImNsOGQ0cDVrNjAweTMzb3RmdG9ieTU5ZDkifQ.I6ZS7mViZYSvBo4zz-mGQQ',
320
+ container: el,
321
+ style: 'mapbox://styles/santanu-ogma/cl8ep33uz003414n1twlosz9d',
322
+ center: [-77.036873, 38.907192],
323
+ zoom: 10, bearing: 0, pitch: 65, interactive: true,
324
+ });
325
+ this.map.once('load', (res) => {
326
+ resolve(res);
327
+ });
328
+ });
329
+ }
330
+ // Below method Load route with animation
331
+ loadMapProperty(pinRouteGeojson, index, unit, route, bottom) {
332
+ return new Promise((resolve, reject) => {
333
+ let origin = pinRouteGeojson.features[0].geometry.coordinates[0];
334
+ const linecolor = (unit === 'Ton') ? '#ff7272' : (unit === 'Load') ? '#a3c52e' : '#ae23d1';
335
+ let destination = pinRouteGeojson.features[0].geometry.coordinates[pinRouteGeojson.features[0].geometry.coordinates.length - 1];
336
+ this.extendBound(pinRouteGeojson.features[0].geometry.coordinates, true).then((res) => {
337
+ const point = {
338
+ 'type': 'FeatureCollection',
339
+ 'features': [
340
+ { 'type': 'Feature', 'properties': {}, 'geometry': { 'type': 'Point', 'coordinates': origin } }
341
+ ]
342
+ };
343
+ const lineDistance = turf.length(pinRouteGeojson.features[0]);
344
+ const arc = [];
345
+ const steps = 10 * pinRouteGeojson.features[0].geometry.coordinates.length;
346
+ for (let i = 0; i < lineDistance; i += lineDistance / steps) {
347
+ const segment = turf.along(pinRouteGeojson.features[0], i);
348
+ arc.push(segment.geometry.coordinates);
349
+ }
350
+ pinRouteGeojson.features[0].geometry.coordinates = arc;
351
+ const pinRoute = pinRouteGeojson.features[0].geometry.coordinates;
352
+ const marker = new mapboxgl.Marker(document.createElement('div'))
353
+ .setLngLat(pinRoute[0]).addTo(this.map).togglePopup();
354
+ if (this.map.getSource(`line${index}`)) {
355
+ this.removeRouteAndMarker(index).then(() => { });
356
+ }
357
+ this.map.addSource(`line${index}`, { type: 'geojson', lineMetrics: true, data: pinRouteGeojson });
358
+ this.map.addLayer({
359
+ type: 'line',
360
+ source: `line${index}`,
361
+ id: `line${index}`,
362
+ paint: {
363
+ 'line-width': 2,
364
+ 'line-gradient': [
365
+ 'interpolate',
366
+ ['linear'],
367
+ ['line-progress'],
368
+ 0, unit === 'Ton' ? '#d7f7e4' : unit === 'Load' ? '#c9d8f5' : '#f5dcc1',
369
+ 1, unit === 'Ton' ? '#ff7272' : unit === 'Load' ? '#a3c52e' : '#ae23d1',
370
+ ]
371
+ },
372
+ layout: { 'line-cap': 'round', 'line-join': 'round' }
373
+ });
374
+ const dataSetForMap = {
375
+ counter: 0, pinRouteGeojson, steps,
376
+ point, pointId: `point${index}`,
377
+ marker, pinRoute, lineId: `line${index}`, index,
378
+ origin, destination, lineDistance,
379
+ linecolor, route, isViewRoute: true
380
+ };
381
+ this.createMarker(dataSetForMap);
382
+ this.map.on('mouseenter', `line${index}`, (e) => {
383
+ this.map.setPaintProperty(`line${index}`, 'line-width', 5);
384
+ this.map.setPaintProperty(`line${index}`, 'line-opacity', 1);
385
+ const datasetForPopup = {
386
+ coordinate: [e.lngLat.lng, e.lngLat.lat],
387
+ pickup: route.pickup_location ? route.pickup_location : '',
388
+ drop: route.delivery_location ? route.delivery_location : '',
389
+ routeType: route.project ? 'Project' : 'Route',
390
+ title: route.project ? route.project : route.route_name ? route.route_name : '',
391
+ material: route.material ? route.material : '',
392
+ type: route.unit ? route.unit : ''
393
+ };
394
+ this.createPopup(datasetForPopup);
395
+ });
396
+ this.map.on('mouseleave', `line${index}`, (e) => {
397
+ this.map.setPaintProperty(`line${index}`, 'line-width', 2);
398
+ if (this.popup) {
399
+ this.popup.remove();
400
+ }
401
+ });
402
+ });
403
+ this.map.once('idle', (res) => {
404
+ resolve(true);
405
+ });
406
+ });
407
+ }
408
+ // Below method Load route without animation
409
+ drawLine(cordinates, index, route, enablefitbound, routeType) {
410
+ let linecolor;
411
+ let origin = cordinates[0];
412
+ let destination = cordinates[cordinates.length - 1];
413
+ if (origin[0] && origin[1] && destination && destination[0] && destination[1]) {
414
+ linecolor = this.provideLineColor(route['unit'], routeType);
415
+ if (enablefitbound) {
416
+ const padding = {
417
+ top: this.padding.top, bottom: this.padding.bottom + (this.windowActualHeightWidth.availHeight - (window.innerHeight - 65)),
418
+ left: this.padding.left, right: this.padding.right
419
+ };
420
+ this.map.fitBounds([origin, destination], { padding }, { fitboundCompleteJob: true });
421
+ }
422
+ if (this.map.getSource(`route-source-for-job-code${index}`)) {
423
+ this.removeRouteAndMarker(index).then(() => { });
424
+ }
425
+ this.map.addSource(`route-source-for-job-code${index}`, {
426
+ 'type': 'geojson',
427
+ 'data': { 'type': 'Feature', 'properties': {}, 'geometry': { 'type': 'LineString', 'coordinates': cordinates } }
428
+ });
429
+ this.map.addLayer({
430
+ 'id': `route-for-job-code${index}`, 'type': 'line', 'source': `route-source-for-job-code${index}`,
431
+ paint: { 'line-color': linecolor, 'line-width': 2 },
432
+ layout: { 'line-cap': 'round', 'line-join': 'round' }
433
+ });
434
+ const dataSetForMap = {
435
+ origin, destination, index, linecolor, route
436
+ };
437
+ this.createMarker(dataSetForMap);
438
+ this.map.on('mouseenter', `route-for-job-code${index}`, (e) => {
439
+ if (this.popup) {
440
+ this.popup.remove();
441
+ }
442
+ this.map.setPaintProperty(`route-for-job-code${index}`, 'line-width', 5);
443
+ this.map.setPaintProperty(`route-for-job-code${index}`, 'line-opacity', 1);
444
+ const datasetForPopup = {
445
+ coordinate: [e.lngLat.lng, e.lngLat.lat],
446
+ pickup: route.pickup_location ? route.pickup_location : '',
447
+ drop: route.delivery_location ? route.delivery_location : '',
448
+ jobCode: route.project ? route.order_number : null,
449
+ customer: route.project ? route.customer_name : null,
450
+ routeType: route.project ? 'Project' : 'Route',
451
+ title: route.project ? route.project : route.route_name ? route.route_name : '',
452
+ material: route.material ? route.material : '',
453
+ type: route.unit ? route.unit : ''
454
+ };
455
+ this.createPopup(datasetForPopup);
456
+ });
457
+ this.map.on('mouseleave', `route-for-job-code${index}`, (e) => {
458
+ this.map.setPaintProperty(`route-for-job-code${index}`, 'line-width', 2);
459
+ if (this.popup) {
460
+ this.popup.remove();
461
+ }
462
+ });
463
+ }
464
+ }
465
+ provideLineColor(unitType, type) {
466
+ let checkType = (type && !['jobrouteList', 'addroute'].includes(type)) ? true : false;
467
+ let color;
468
+ switch (unitType) {
469
+ case "Ton":
470
+ color = checkType ? '#39c471' : '#ff7272';
471
+ break;
472
+ case "Load":
473
+ color = checkType ? '#326ad3' : '#a3c52e';
474
+ break;
475
+ case "Hourly":
476
+ color = checkType ? '#ffad56' : '#ae23d1';
477
+ break;
478
+ }
479
+ return color;
480
+ }
481
+ showRoutePopup(arcDetails, event, isViewRoute) {
482
+ if (this.popup) {
483
+ this.popup.remove();
484
+ this.map.setPaintProperty(`${isViewRoute ? 'line' : 'route-for-job-code'}${arcDetails.layer.props.data.index}`, 'line-width', 2);
485
+ }
486
+ if (arcDetails.color && this.map.getLayoutProperty(arcDetails.layer.id, 'visibility') !== 'none') {
487
+ this.map.setPaintProperty(`${isViewRoute ? 'line' : 'route-for-job-code'}${arcDetails.layer.props.data.index}`, 'line-width', 5);
488
+ this.map.setPaintProperty(`${isViewRoute ? 'line' : 'route-for-job-code'}${arcDetails.layer.props.data.index}`, 'line-opacity', 1);
489
+ const datasetForPopup = {
490
+ coordinate: arcDetails.coordinate,
491
+ pickup: arcDetails.layer.props.data.route.pickup_location ? arcDetails.layer.props.data.route.pickup_location : '',
492
+ drop: arcDetails.layer.props.data.route.delivery_location ? arcDetails.layer.props.data.route.delivery_location : '',
493
+ jobCode: arcDetails.layer.props.data.route.project ? arcDetails.layer.props.data.route.order_number : '',
494
+ customer: arcDetails.layer.props.data.route.project ? arcDetails.layer.props.data.route.customer_name : '',
495
+ routeType: arcDetails.layer.props.data.route.project ? 'Project' : 'Route',
496
+ title: arcDetails.layer.props.data.route.project ? arcDetails.layer.props.data.route.project : arcDetails.layer.props.data.route.route_name ? arcDetails.layer.props.data.route.route_name : '',
497
+ material: arcDetails.layer.props.data.route.material ? arcDetails.layer.props.data.route.material : '',
498
+ type: arcDetails.layer.props.data.route.unit ? arcDetails.layer.props.data.route.unit : ''
499
+ };
500
+ this.createPopup(datasetForPopup);
501
+ }
502
+ }
503
+ createPopup(datasetForPopup) {
504
+ this.popup = new mapboxgl.Popup({
505
+ closeButton: false,
506
+ closeOnClick: false,
507
+ closeOnMove: true,
508
+ anchor: 'bottom-left'
509
+ });
510
+ this.popup.setLngLat(datasetForPopup.coordinate)
511
+ .setHTML(`
512
+ <div class="destination">
513
+ <div class="duration">
514
+ <p class="pickprt"><b>Pickup Location:</b> ${datasetForPopup.pickup}</p>
515
+ <p class="dropprt"><b>Drop Location:</b> ${datasetForPopup.drop}</p>
516
+ </div>
517
+ ${datasetForPopup.jobCode ? '<span><b>Job Code:</b> ' + datasetForPopup.jobCode + '</span>' : ''}
518
+ ${datasetForPopup.customer ? '<span><b>Customer:</b> ' + datasetForPopup.customer + '</span>' : ''}
519
+ <span><b>${datasetForPopup.routeType} Name:</b> ${datasetForPopup.title}</span>
520
+ <span><b>Material:</b> ${datasetForPopup.material}</span>
521
+ <span><b>Type:</b> ${datasetForPopup.type}</span>
522
+ </div>
523
+ `)
524
+ .addTo(this.map);
525
+ }
526
+ hexToRGB(hex) {
527
+ return hex.replace(/^#?([a-f\d])([a-f\d])([a-f\d])$/i, (m, r, g, b) => '#' + r + r + g + g + b + b)
528
+ .substring(1).match(/.{2}/g)
529
+ .map(x => parseInt(x, 16));
530
+ }
531
+ createMarker(routeDetails) {
532
+ if (routeDetails.origin[0] && routeDetails.origin[1] && routeDetails.destination[0] && routeDetails.destination[1]) {
533
+ const popup = new mapboxgl.Popup({ closeButton: false }).setHTML('<b>Pickup: </b>' + routeDetails.route?.pickup_location);
534
+ const popupForDestination = new mapboxgl.Popup({ closeButton: false })
535
+ .setHTML('<b>Delivery: </b>' + routeDetails.route?.delivery_location);
536
+ const el = document.createElement('div');
537
+ el.className = 'marker';
538
+ el.innerHTML = `<span class='markerPointer' style='background:${routeDetails.linecolor}'><b>P</b><span class='markerSpan' style='border-top: 10px solid ${routeDetails.linecolor}'></span></span>`;
539
+ const originMarker = new mapboxgl.Marker(el)
540
+ .setPopup(popup).setLngLat(routeDetails.origin).addTo(this.map);
541
+ originMarker.getElement().addEventListener('mouseenter', () => originMarker.togglePopup());
542
+ originMarker.getElement().addEventListener('mouseleave', () => originMarker.togglePopup());
543
+ const elementForDestination = document.createElement('div');
544
+ elementForDestination.className = 'marker';
545
+ elementForDestination.innerHTML = `<span class='markerPointer' style='background:${routeDetails.linecolor}'><b>D</b><span class='markerSpan' style='border-top: 10px solid ${routeDetails.linecolor}'></span></span>`;
546
+ const destinationMarker = new mapboxgl.Marker(elementForDestination).setPopup(popupForDestination).setLngLat(routeDetails.destination).addTo(this.map);
547
+ destinationMarker.getElement().addEventListener('mouseenter', () => destinationMarker.togglePopup());
548
+ destinationMarker.getElement().addEventListener('mouseleave', () => destinationMarker.togglePopup());
549
+ this.markerOriginList[routeDetails.index] = originMarker;
550
+ this.markerDestinationList[routeDetails.index] = destinationMarker;
551
+ const colorArray = this.hexToRGB(routeDetails.linecolor);
552
+ const arcLayer = new MapboxLayer({
553
+ id: 'arc-layer' + routeDetails.index,
554
+ type: ArcLayer,
555
+ pickable: true,
556
+ data: { route: routeDetails.route, index: routeDetails.index },
557
+ getWidth: 1,
558
+ getSourcePosition: routeDetails.origin,
559
+ getTargetPosition: routeDetails.destination,
560
+ getTargetColor: [255, 255, 255],
561
+ getSourceColor: [colorArray[0], colorArray[1], colorArray[2]],
562
+ onHover: (info, event) => this.showRoutePopup(info, event, routeDetails.isViewRoute),
563
+ });
564
+ this.map.addLayer(arcLayer);
565
+ }
566
+ }
567
+ async removeRouteAndMarker(index) {
568
+ if (this.map) {
569
+ this.map.getLayer(`arc-layer${index}`) ? this.map.removeLayer(`arc-layer${index}`) : '';
570
+ this.map.getLayer(`line${index}`) ? this.map.removeLayer(`line${index}`) : '';
571
+ this.map.getLayer(`custom_layer${index}`) ? this.map.removeLayer(`custom_layer${index}`) : '';
572
+ this.map.getSource(`line${index}`) ? this.map.removeSource(`line${index}`) : '';
573
+ this.map.getLayer(`route-for-job-code${index}`) ? this.map.removeLayer(`route-for-job-code${index}`) : '';
574
+ this.map.getSource(`route-source-for-job-code${index}`) ? this.map.removeSource(`route-source-for-job-code${index}`) : '';
575
+ this.findMarkerBound(index);
576
+ this.markerOriginList[index] ? this.markerOriginList[index].remove() : '';
577
+ this.markerDestinationList[index] ? this.markerDestinationList[index].remove() : '';
578
+ await true;
579
+ }
580
+ }
581
+ findMarkerBound(index) {
582
+ const indexOfCordinates = this.originDestinationCordinates.findIndex((x) => (x[0][0].toFixed(6) == this.markerOriginList[index]?.getLngLat()?.lng.toFixed(6)) && (x[0][1].toFixed(6) == this.markerOriginList[index]?.getLngLat()?.lat.toFixed(6)));
583
+ if (indexOfCordinates >= 0) {
584
+ this.originDestinationCordinates.splice(indexOfCordinates, 1);
585
+ }
586
+ }
587
+ async filterRoute(ID, visibility, showAllFitbound) {
588
+ if (ID) {
589
+ if (this.map.getLayer(`route-for-job-code${ID}`)) {
590
+ this.map.setLayoutProperty(`route-for-job-code${ID}`, 'visibility', visibility);
591
+ const originM = this.markerOriginList[ID].getElement();
592
+ originM.style.display = ((visibility === 'visible') ? 'block' : visibility);
593
+ const destinationM = this.markerDestinationList[ID].getElement();
594
+ destinationM.style.display = ((visibility === 'visible') ? 'block' : visibility);
595
+ if (visibility === 'none' && showAllFitbound) {
596
+ this.findMarkerBound(ID);
597
+ this.extendReBound();
598
+ }
599
+ }
600
+ if (this.map.getLayer(`arc-layer${ID}`)) {
601
+ this.map.setLayoutProperty(`arc-layer${ID}`, 'visibility', visibility);
602
+ }
603
+ }
604
+ await true;
605
+ }
606
+ extendBound(route, showAllFitbound) {
607
+ return new Promise((resolve, reject) => {
608
+ if (route) {
609
+ if (typeof route === 'string') {
610
+ let path = route.split(';');
611
+ path = path.map((ele) => { return ele = this.formateLatLong(ele); });
612
+ path.forEach((ele, index) => { if (ele.length === 1)
613
+ path.splice(index, 1); });
614
+ route = path;
615
+ }
616
+ if (route[0][0] && route[0][1] && route[route.length - 1][0] && route[route.length - 1][1]) {
617
+ this.originDestinationCordinates.push(route);
618
+ route.map((item) => {
619
+ this.bounds.extend(item);
620
+ });
621
+ }
622
+ }
623
+ if (showAllFitbound) {
624
+ const padding = { top: this.padding.top, bottom: (this.padding.bottom + (this.windowActualHeightWidth.availHeight - (window.innerHeight - 65))), left: this.padding.left, right: this.padding.right };
625
+ setTimeout(() => {
626
+ if (showAllFitbound && (Object.keys(this.bounds).length > 0))
627
+ this.map.fitBounds(this.bounds, { padding }, { fitboundComplete: true });
628
+ }, 100);
629
+ this.map.once('moveend', (event) => { if (event.fitboundComplete) {
630
+ resolve(true);
631
+ } });
632
+ }
633
+ });
634
+ }
635
+ extendReBound(bottom) {
636
+ return new Promise((resolve, reject) => {
637
+ this.bounds = new mapboxgl.LngLatBounds();
638
+ if (this.originDestinationCordinates.length >= 0) {
639
+ this.originDestinationCordinates.map((item, index) => {
640
+ item.map((route) => {
641
+ this.bounds.extend(route);
642
+ });
643
+ if (index === (this.originDestinationCordinates.length - 1)) {
644
+ const padding = { top: this.padding.top, bottom: (this.padding.bottom + (this.windowActualHeightWidth.availHeight - (window.innerHeight - 65))), left: this.padding.left, right: this.padding.right };
645
+ setTimeout(() => {
646
+ if (this.originDestinationCordinates.length > 0)
647
+ this.map.fitBounds(this.bounds, { padding });
648
+ }, 500);
649
+ resolve(true);
650
+ }
651
+ });
652
+ }
653
+ else {
654
+ resolve(true);
655
+ }
656
+ });
657
+ }
658
+ plotRoute(route, i, type, enablefitbound, showAllFitbound) {
659
+ return new Promise((resolve, reject) => {
660
+ let param = {};
661
+ if (['jobcode'].includes(type)) {
662
+ param['job'] = route['job_id'];
663
+ this.utils.postDataWithRestUrl('schedule/job/path', param).subscribe((res) => {
664
+ if (res['data']['route']) {
665
+ let path = res['data']['route'].split(';');
666
+ path = path.map((ele) => { return ele = this.formateLatLong(ele); });
667
+ path.forEach((ele, index) => { if (ele.length === 1)
668
+ path.splice(index, 1); });
669
+ route['path'] = path;
670
+ this.extendBound(route['path'], showAllFitbound);
671
+ if (route['path'] && route['path'].length > 0)
672
+ this.drawLine(route['path'], i, route, enablefitbound, type);
673
+ route['index'] = i;
674
+ }
675
+ else {
676
+ this.extendBound(null, showAllFitbound);
677
+ }
678
+ resolve(true);
679
+ }, (err) => { if (err) {
680
+ reject(false);
681
+ } });
682
+ }
683
+ else if (['jobrouteList', 'addroute'].includes(type)) {
684
+ if (route['path'] && route['path'].length > 0) {
685
+ let path = route['path'].split(';');
686
+ path = path.map((ele) => { return ele = this.formateLatLong(ele); });
687
+ path.forEach((ele, index) => { if (ele.length === 1)
688
+ path.splice(index, 1); });
689
+ this.extendBound(path, showAllFitbound);
690
+ this.drawLine(path, i, route, enablefitbound, type);
691
+ }
692
+ ;
693
+ }
694
+ });
695
+ }
696
+ clearBound() { this.bounds = new mapboxgl.LngLatBounds(); this.originDestinationCordinates = []; this.clearPadding(); }
697
+ formateLatLong(latlong) { return latlong ? latlong.split(',').map(x => +x).reverse() : null; }
698
+ clearBoundWithCordinates() {
699
+ this.bounds = new mapboxgl.LngLatBounds();
700
+ this.originDestinationCordinates = [];
701
+ }
702
+ onResize(event) {
703
+ if (!this.bounds.isEmpty()) {
704
+ this.windowActualHeightWidth.availHeight = (window.innerHeight > window.screen.availHeight) ? window.innerHeight : window.screen.availHeight;
705
+ setTimeout(() => {
706
+ this.map.fitBounds(this.bounds, { padding: { top: this.padding.top, bottom: this.padding.bottom + (this.windowActualHeightWidth.availHeight - (event.target.innerHeight - 65)), left: this.padding.left, right: this.padding.right } });
707
+ }, 500);
708
+ }
709
+ }
710
+ setWindowHeight(screen) {
711
+ this.windowActualHeightWidth.availHeight = screen;
712
+ }
713
+ setPadding(padding) { this.padding = padding; }
714
+ clearPadding() { this.padding = null; }
715
+ removeJobFromMap(data) {
716
+ data.map((ele, index) => {
717
+ const id = (ele['job_id'] ? ele['job_id'] : ele['route_id']);
718
+ this.removeRouteAndMarker(id);
719
+ if (index === (data.length - 1)) {
720
+ this.extendReBound();
721
+ }
722
+ });
723
+ }
724
+ }
725
+ CoolmapService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: CoolmapService, deps: [{ token: UtilsService }, { token: i2$1.EventManager }], target: i0.ɵɵFactoryTarget.Injectable });
726
+ CoolmapService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: CoolmapService, providedIn: 'root' });
727
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: CoolmapService, decorators: [{
728
+ type: Injectable,
729
+ args: [{ providedIn: 'root' }]
730
+ }], ctorParameters: function () { return [{ type: UtilsService }, { type: i2$1.EventManager }]; } });
731
+
732
+ /*
733
+ * Public API Surface of coolmap-services
734
+ */
735
+
736
+ /**
737
+ * Generated bundle index. Do not edit.
738
+ */
739
+
740
+ export { CoolmapConfigModel, CoolmapService, DriverSmsCardEnum, DriversmsCardKey, EstinationData, EstinationEnum, JobCodeOverviewData, JobCodeOverviewEnum, PopupData, Route, UtilsService };
741
+ //# sourceMappingURL=coolmap-services.mjs.map