@aggdirect/coolmap-services 0.0.5 → 0.0.7

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