@aggdirect/coolmap-services 0.0.4 → 0.0.6

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