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