@aggdirect/coolmap-services 0.0.8 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9,419 +9,421 @@ 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 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' }]
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.3.0", 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.3.0", ngImport: i0, type: UtilsService, providedIn: 'root' });
212
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: UtilsService, decorators: [{
213
+ type: Injectable,
214
+ args: [{ providedIn: 'root' }]
215
215
  }], ctorParameters: function () { return [{ type: i1.HttpClient }, { type: i2.MatSnackBar }]; } });
216
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)
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
+ if (this.map)
233
+ this.map.remove();
234
+ this.map = new mapboxgl.Map({
235
+ accessToken: 'pk.eyJ1Ijoic2FudGFudS1vZ21hIiwiYSI6ImNsOGQ0cDVrNjAweTMzb3RmdG9ieTU5ZDkifQ.I6ZS7mViZYSvBo4zz-mGQQ',
236
+ container: el,
237
+ style: 'mapbox://styles/santanu-ogma/cl8ep33uz003414n1twlosz9d',
238
+ center: [-77.036873, 38.907192],
239
+ zoom: 10, bearing: 0, pitch: 65, interactive: true,
240
+ });
241
+ this.map.once('load', (res) => {
242
+ resolve(res);
243
+ });
244
+ });
245
+ }
246
+ // Below method Load route with animation
247
+ loadMapProperty(pinRouteGeojson, index, unit, route, bottom) {
248
+ return new Promise((resolve, reject) => {
249
+ let origin = pinRouteGeojson.features[0].geometry.coordinates[0];
250
+ const linecolor = (unit === 'Ton') ? '#ff7272' : (unit === 'Load') ? '#a3c52e' : '#ae23d1';
251
+ let destination = pinRouteGeojson.features[0].geometry.coordinates[pinRouteGeojson.features[0].geometry.coordinates.length - 1];
252
+ this.extendBound(pinRouteGeojson.features[0].geometry.coordinates, true).then((res) => {
253
+ const point = {
254
+ 'type': 'FeatureCollection',
255
+ 'features': [
256
+ { 'type': 'Feature', 'properties': {}, 'geometry': { 'type': 'Point', 'coordinates': origin } }
257
+ ]
258
+ };
259
+ const lineDistance = turf.length(pinRouteGeojson.features[0]);
260
+ const arc = [];
261
+ const steps = 10 * pinRouteGeojson.features[0].geometry.coordinates.length;
262
+ for (let i = 0; i < lineDistance; i += lineDistance / steps) {
263
+ const segment = turf.along(pinRouteGeojson.features[0], i);
264
+ arc.push(segment.geometry.coordinates);
265
+ }
266
+ pinRouteGeojson.features[0].geometry.coordinates = arc;
267
+ const pinRoute = pinRouteGeojson.features[0].geometry.coordinates;
268
+ const marker = new mapboxgl.Marker(document.createElement('div'))
269
+ .setLngLat(pinRoute[0]).addTo(this.map).togglePopup();
270
+ if (this.map.getSource(`line${index}`)) {
271
+ this.removeRouteAndMarker(index).then(() => { });
272
+ }
273
+ this.map.addSource(`line${index}`, { type: 'geojson', lineMetrics: true, data: pinRouteGeojson });
274
+ this.map.addLayer({
275
+ type: 'line',
276
+ source: `line${index}`,
277
+ id: `line${index}`,
278
+ paint: {
279
+ 'line-width': 2,
280
+ 'line-gradient': [
281
+ 'interpolate',
282
+ ['linear'],
283
+ ['line-progress'],
284
+ 0, unit === 'Ton' ? '#d7f7e4' : unit === 'Load' ? '#c9d8f5' : '#f5dcc1',
285
+ 1, unit === 'Ton' ? '#ff7272' : unit === 'Load' ? '#a3c52e' : '#ae23d1',
286
+ ]
287
+ },
288
+ layout: { 'line-cap': 'round', 'line-join': 'round' }
289
+ });
290
+ const dataSetForMap = {
291
+ counter: 0, pinRouteGeojson, steps,
292
+ point, pointId: `point${index}`,
293
+ marker, pinRoute, lineId: `line${index}`, index,
294
+ origin, destination, lineDistance,
295
+ linecolor, route, isViewRoute: true
296
+ };
297
+ this.createMarker(dataSetForMap);
298
+ this.map.on('mouseenter', `line${index}`, (e) => {
299
+ this.map.setPaintProperty(`line${index}`, 'line-width', 5);
300
+ this.map.setPaintProperty(`line${index}`, 'line-opacity', 1);
301
+ const datasetForPopup = {
302
+ coordinate: [e.lngLat.lng, e.lngLat.lat],
303
+ pickup: route.pickup_location ? route.pickup_location : '',
304
+ drop: route.delivery_location ? route.delivery_location : '',
305
+ routeType: route.project ? 'Project' : 'Route',
306
+ title: route.project ? route.project : route.route_name ? route.route_name : '',
307
+ material: route.material ? route.material : '',
308
+ type: route.unit ? route.unit : ''
309
+ };
310
+ this.createPopup(datasetForPopup);
311
+ });
312
+ this.map.on('mouseleave', `line${index}`, (e) => {
313
+ this.map.setPaintProperty(`line${index}`, 'line-width', 2);
314
+ if (this.popup) {
315
+ this.popup.remove();
316
+ }
317
+ });
318
+ });
319
+ this.map.once('idle', (res) => {
320
+ resolve(true);
321
+ });
322
+ });
323
+ }
324
+ // Below method Load route without animation
325
+ drawLine(cordinates, index, route, enablefitbound, routeType) {
326
+ let linecolor;
327
+ let origin = cordinates[0];
328
+ let destination = cordinates[cordinates.length - 1];
329
+ if (origin[0] && origin[1] && destination && destination[0] && destination[1]) {
330
+ linecolor = this.provideLineColor(route['unit'], routeType);
331
+ if (enablefitbound) {
332
+ const padding = {
333
+ top: this.padding.top, bottom: this.padding.bottom + (this.windowActualHeightWidth.availHeight - (window.innerHeight - 65)),
334
+ left: this.padding.left, right: this.padding.right
335
+ };
336
+ this.map.fitBounds([origin, destination], { padding }, { fitboundCompleteJob: true });
337
+ }
338
+ if (this.map.getSource(`route-source-for-job-code${index}`)) {
339
+ this.removeRouteAndMarker(index).then(() => { });
340
+ }
341
+ this.map.addSource(`route-source-for-job-code${index}`, {
342
+ 'type': 'geojson',
343
+ 'data': { 'type': 'Feature', 'properties': {}, 'geometry': { 'type': 'LineString', 'coordinates': cordinates } }
344
+ });
345
+ this.map.addLayer({
346
+ 'id': `route-for-job-code${index}`, 'type': 'line', 'source': `route-source-for-job-code${index}`,
347
+ paint: { 'line-color': linecolor, 'line-width': 2 },
348
+ layout: { 'line-cap': 'round', 'line-join': 'round' }
349
+ });
350
+ const dataSetForMap = {
351
+ origin, destination, index, linecolor, route
352
+ };
353
+ this.createMarker(dataSetForMap);
354
+ this.map.on('mouseenter', `route-for-job-code${index}`, (e) => {
355
+ if (this.popup) {
356
+ this.popup.remove();
357
+ }
358
+ this.map.setPaintProperty(`route-for-job-code${index}`, 'line-width', 5);
359
+ this.map.setPaintProperty(`route-for-job-code${index}`, 'line-opacity', 1);
360
+ const datasetForPopup = {
361
+ coordinate: [e.lngLat.lng, e.lngLat.lat],
362
+ pickup: route.pickup_location ? route.pickup_location : '',
363
+ drop: route.delivery_location ? route.delivery_location : '',
364
+ jobCode: route.project ? route.order_number : null,
365
+ customer: route.project ? route.customer_name : null,
366
+ routeType: route.project ? 'Project' : 'Route',
367
+ title: route.project ? route.project : route.route_name ? route.route_name : '',
368
+ material: route.material ? route.material : '',
369
+ type: route.unit ? route.unit : ''
370
+ };
371
+ this.createPopup(datasetForPopup);
372
+ });
373
+ this.map.on('mouseleave', `route-for-job-code${index}`, (e) => {
374
+ this.map.setPaintProperty(`route-for-job-code${index}`, 'line-width', 2);
375
+ if (this.popup) {
376
+ this.popup.remove();
377
+ }
378
+ });
379
+ }
380
+ }
381
+ provideLineColor(unitType, type) {
382
+ let checkType = (type && !['jobrouteList', 'addroute'].includes(type)) ? true : false;
383
+ let color;
384
+ switch (unitType) {
385
+ case "Ton":
386
+ color = checkType ? '#39c471' : '#ff7272';
387
+ break;
388
+ case "Load":
389
+ color = checkType ? '#326ad3' : '#a3c52e';
390
+ break;
391
+ case "Hourly":
392
+ color = checkType ? '#ffad56' : '#ae23d1';
393
+ break;
394
+ }
395
+ return color;
396
+ }
397
+ showRoutePopup(arcDetails, event, isViewRoute) {
398
+ if (this.popup) {
399
+ this.popup.remove();
400
+ this.map.setPaintProperty(`${isViewRoute ? 'line' : 'route-for-job-code'}${arcDetails.layer.props.data.index}`, 'line-width', 2);
401
+ }
402
+ if (arcDetails.color && this.map.getLayoutProperty(arcDetails.layer.id, 'visibility') !== 'none') {
403
+ this.map.setPaintProperty(`${isViewRoute ? 'line' : 'route-for-job-code'}${arcDetails.layer.props.data.index}`, 'line-width', 5);
404
+ this.map.setPaintProperty(`${isViewRoute ? 'line' : 'route-for-job-code'}${arcDetails.layer.props.data.index}`, 'line-opacity', 1);
405
+ const datasetForPopup = {
406
+ coordinate: arcDetails.coordinate,
407
+ pickup: arcDetails.layer.props.data.route.pickup_location ? arcDetails.layer.props.data.route.pickup_location : '',
408
+ drop: arcDetails.layer.props.data.route.delivery_location ? arcDetails.layer.props.data.route.delivery_location : '',
409
+ jobCode: arcDetails.layer.props.data.route.project ? arcDetails.layer.props.data.route.order_number : '',
410
+ customer: arcDetails.layer.props.data.route.project ? arcDetails.layer.props.data.route.customer_name : '',
411
+ routeType: arcDetails.layer.props.data.route.project ? 'Project' : 'Route',
412
+ 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 : '',
413
+ material: arcDetails.layer.props.data.route.material ? arcDetails.layer.props.data.route.material : '',
414
+ type: arcDetails.layer.props.data.route.unit ? arcDetails.layer.props.data.route.unit : ''
415
+ };
416
+ this.createPopup(datasetForPopup);
417
+ }
418
+ }
419
+ createPopup(datasetForPopup) {
420
+ this.popup = new mapboxgl.Popup({
421
+ closeButton: false,
422
+ closeOnClick: false,
423
+ closeOnMove: true,
424
+ anchor: 'bottom-left'
425
+ });
426
+ this.popup.setLngLat(datasetForPopup.coordinate)
425
427
  .setHTML(`
426
428
  <div class="destination">
427
429
  <div class="duration">
@@ -434,256 +436,256 @@ class CoolmapService {
434
436
  <span><b>Material:</b> ${datasetForPopup.material}</span>
435
437
  <span><b>Type:</b> ${datasetForPopup.type}</span>
436
438
  </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' }]
439
+ `)
440
+ .addTo(this.map);
441
+ }
442
+ hexToRGB(hex) {
443
+ return hex.replace(/^#?([a-f\d])([a-f\d])([a-f\d])$/i, (m, r, g, b) => '#' + r + r + g + g + b + b)
444
+ .substring(1).match(/.{2}/g)
445
+ .map(x => parseInt(x, 16));
446
+ }
447
+ createMarker(routeDetails) {
448
+ if (routeDetails.origin[0] && routeDetails.origin[1] && routeDetails.destination[0] && routeDetails.destination[1]) {
449
+ const popup = new mapboxgl.Popup({ closeButton: false }).setHTML('<b>Pickup: </b>' + routeDetails.route?.pickup_location);
450
+ const popupForDestination = new mapboxgl.Popup({ closeButton: false })
451
+ .setHTML('<b>Delivery: </b>' + routeDetails.route?.delivery_location);
452
+ const el = document.createElement('div');
453
+ el.className = 'marker';
454
+ el.innerHTML = `<span class='markerPointer' style='background:${routeDetails.linecolor}'><b>P</b><span class='markerSpan' style='border-top: 10px solid ${routeDetails.linecolor}'></span></span>`;
455
+ const originMarker = new mapboxgl.Marker(el)
456
+ .setPopup(popup).setLngLat(routeDetails.origin).addTo(this.map);
457
+ originMarker.getElement().addEventListener('mouseenter', () => originMarker.togglePopup());
458
+ originMarker.getElement().addEventListener('mouseleave', () => originMarker.togglePopup());
459
+ const elementForDestination = document.createElement('div');
460
+ elementForDestination.className = 'marker';
461
+ elementForDestination.innerHTML = `<span class='markerPointer' style='background:${routeDetails.linecolor}'><b>D</b><span class='markerSpan' style='border-top: 10px solid ${routeDetails.linecolor}'></span></span>`;
462
+ const destinationMarker = new mapboxgl.Marker(elementForDestination).setPopup(popupForDestination).setLngLat(routeDetails.destination).addTo(this.map);
463
+ destinationMarker.getElement().addEventListener('mouseenter', () => destinationMarker.togglePopup());
464
+ destinationMarker.getElement().addEventListener('mouseleave', () => destinationMarker.togglePopup());
465
+ this.markerOriginList[routeDetails.index] = originMarker;
466
+ this.markerDestinationList[routeDetails.index] = destinationMarker;
467
+ const colorArray = this.hexToRGB(routeDetails.linecolor);
468
+ const arcLayer = new MapboxLayer({
469
+ id: 'arc-layer' + routeDetails.index,
470
+ type: ArcLayer,
471
+ pickable: true,
472
+ data: { route: routeDetails.route, index: routeDetails.index },
473
+ getWidth: 1,
474
+ getSourcePosition: routeDetails.origin,
475
+ getTargetPosition: routeDetails.destination,
476
+ getTargetColor: [255, 255, 255],
477
+ getSourceColor: [colorArray[0], colorArray[1], colorArray[2]],
478
+ onHover: (info, event) => this.showRoutePopup(info, event, routeDetails.isViewRoute),
479
+ });
480
+ this.map.addLayer(arcLayer);
481
+ }
482
+ }
483
+ async removeRouteAndMarker(index) {
484
+ if (this.map) {
485
+ this.map.getLayer(`arc-layer${index}`) ? this.map.removeLayer(`arc-layer${index}`) : '';
486
+ this.map.getLayer(`line${index}`) ? this.map.removeLayer(`line${index}`) : '';
487
+ this.map.getLayer(`custom_layer${index}`) ? this.map.removeLayer(`custom_layer${index}`) : '';
488
+ this.map.getSource(`line${index}`) ? this.map.removeSource(`line${index}`) : '';
489
+ this.map.getLayer(`route-for-job-code${index}`) ? this.map.removeLayer(`route-for-job-code${index}`) : '';
490
+ this.map.getSource(`route-source-for-job-code${index}`) ? this.map.removeSource(`route-source-for-job-code${index}`) : '';
491
+ this.findMarkerBound(index);
492
+ this.markerOriginList[index] ? this.markerOriginList[index].remove() : '';
493
+ this.markerDestinationList[index] ? this.markerDestinationList[index].remove() : '';
494
+ await true;
495
+ }
496
+ }
497
+ findMarkerBound(index) {
498
+ 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)));
499
+ if (indexOfCordinates >= 0) {
500
+ this.originDestinationCordinates.splice(indexOfCordinates, 1);
501
+ }
502
+ }
503
+ async filterRoute(ID, visibility, showAllFitbound) {
504
+ if (ID) {
505
+ if (this.map.getLayer(`route-for-job-code${ID}`)) {
506
+ this.map.setLayoutProperty(`route-for-job-code${ID}`, 'visibility', visibility);
507
+ const originM = this.markerOriginList[ID].getElement();
508
+ originM.style.display = ((visibility === 'visible') ? 'block' : visibility);
509
+ const destinationM = this.markerDestinationList[ID].getElement();
510
+ destinationM.style.display = ((visibility === 'visible') ? 'block' : visibility);
511
+ if (visibility === 'none' && showAllFitbound) {
512
+ this.findMarkerBound(ID);
513
+ this.extendReBound();
514
+ }
515
+ }
516
+ if (this.map.getLayer(`arc-layer${ID}`)) {
517
+ this.map.setLayoutProperty(`arc-layer${ID}`, 'visibility', visibility);
518
+ }
519
+ }
520
+ await true;
521
+ }
522
+ extendBound(route, showAllFitbound) {
523
+ return new Promise((resolve, reject) => {
524
+ if (route) {
525
+ if (typeof route === 'string') {
526
+ let path = route.split(';');
527
+ path = path.map((ele) => { return ele = this.formateLatLong(ele); });
528
+ path.forEach((ele, index) => { if (ele.length === 1)
529
+ path.splice(index, 1); });
530
+ route = path;
531
+ }
532
+ if (route[0][0] && route[0][1] && route[route.length - 1][0] && route[route.length - 1][1]) {
533
+ this.originDestinationCordinates.push(route);
534
+ route.map((item) => {
535
+ this.bounds.extend(item);
536
+ });
537
+ }
538
+ }
539
+ if (showAllFitbound) {
540
+ const padding = { top: this.padding.top, bottom: (this.padding.bottom + (this.windowActualHeightWidth.availHeight - (window.innerHeight - 65))), left: this.padding.left, right: this.padding.right };
541
+ setTimeout(() => {
542
+ if (showAllFitbound && (Object.keys(this.bounds).length > 0))
543
+ this.map.fitBounds(this.bounds, { padding }, { fitboundComplete: true });
544
+ }, 100);
545
+ this.map.once('moveend', (event) => { if (event.fitboundComplete) {
546
+ resolve(true);
547
+ } });
548
+ }
549
+ });
550
+ }
551
+ extendReBound(bottom) {
552
+ return new Promise((resolve, reject) => {
553
+ this.bounds = new mapboxgl.LngLatBounds();
554
+ if (this.originDestinationCordinates.length >= 0) {
555
+ this.originDestinationCordinates.map((item, index) => {
556
+ item.map((route) => {
557
+ this.bounds.extend(route);
558
+ });
559
+ if (index === (this.originDestinationCordinates.length - 1)) {
560
+ const padding = { top: this.padding.top, bottom: (this.padding.bottom + (this.windowActualHeightWidth.availHeight - (window.innerHeight - 65))), left: this.padding.left, right: this.padding.right };
561
+ setTimeout(() => {
562
+ if (this.originDestinationCordinates.length > 0)
563
+ this.map.fitBounds(this.bounds, { padding });
564
+ }, 500);
565
+ resolve(true);
566
+ }
567
+ });
568
+ }
569
+ else {
570
+ resolve(true);
571
+ }
572
+ });
573
+ }
574
+ plotRoute(route, i, type, enablefitbound, showAllFitbound) {
575
+ return new Promise((resolve, reject) => {
576
+ let param = {};
577
+ if (['jobcode'].includes(type)) {
578
+ param['job'] = route['job_id'];
579
+ this.utils.postDataWithRestUrl('schedule/job/path', param).subscribe((res) => {
580
+ if (res['data']['route']) {
581
+ let path = res['data']['route'].split(';');
582
+ path = path.map((ele) => { return ele = this.formateLatLong(ele); });
583
+ path.forEach((ele, index) => { if (ele.length === 1)
584
+ path.splice(index, 1); });
585
+ route['path'] = path;
586
+ this.extendBound(route['path'], showAllFitbound);
587
+ if (route['path'] && route['path'].length > 0)
588
+ this.drawLine(route['path'], i, route, enablefitbound, type);
589
+ route['index'] = i;
590
+ }
591
+ else {
592
+ this.extendBound(null, showAllFitbound);
593
+ }
594
+ resolve(true);
595
+ }, (err) => { if (err) {
596
+ reject(false);
597
+ } });
598
+ }
599
+ else if (['jobrouteList', 'addroute'].includes(type)) {
600
+ if (route['path'] && route['path'].length > 0) {
601
+ let path = route['path'].split(';');
602
+ path = path.map((ele) => { return ele = this.formateLatLong(ele); });
603
+ path.forEach((ele, index) => { if (ele.length === 1)
604
+ path.splice(index, 1); });
605
+ this.extendBound(path, showAllFitbound);
606
+ this.drawLine(path, i, route, enablefitbound, type);
607
+ }
608
+ ;
609
+ }
610
+ });
611
+ }
612
+ clearBound() { this.bounds = new mapboxgl.LngLatBounds(); this.originDestinationCordinates = []; this.clearPadding(); }
613
+ formateLatLong(latlong) { return latlong ? latlong.split(',').map(x => +x).reverse() : null; }
614
+ clearBoundWithCordinates() {
615
+ this.bounds = new mapboxgl.LngLatBounds();
616
+ this.originDestinationCordinates = [];
617
+ }
618
+ onResize(event) {
619
+ if (!this.bounds.isEmpty()) {
620
+ this.windowActualHeightWidth.availHeight = (window.innerHeight > window.screen.availHeight) ? window.innerHeight : window.screen.availHeight;
621
+ setTimeout(() => {
622
+ 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 } });
623
+ }, 500);
624
+ }
625
+ }
626
+ setWindowHeight(screen) {
627
+ this.windowActualHeightWidth.availHeight = screen;
628
+ }
629
+ setPadding(padding) { this.padding = padding; }
630
+ clearPadding() { this.padding = null; }
631
+ removeJobFromMap(data) {
632
+ data.map((ele, index) => {
633
+ const id = (ele['job_id'] ? ele['job_id'] : ele['route_id']);
634
+ this.removeRouteAndMarker(id);
635
+ if (index === (data.length - 1)) {
636
+ this.extendReBound();
637
+ }
638
+ });
639
+ }
640
+ }
641
+ CoolmapService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: CoolmapService, deps: [{ token: UtilsService }, { token: i2$1.EventManager }], target: i0.ɵɵFactoryTarget.Injectable });
642
+ CoolmapService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: CoolmapService, providedIn: 'root' });
643
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: CoolmapService, decorators: [{
644
+ type: Injectable,
645
+ args: [{ providedIn: 'root' }]
644
646
  }], ctorParameters: function () { return [{ type: UtilsService }, { type: i2$1.EventManager }]; } });
645
647
 
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 {
648
+ class Route {
649
+ constructor() {
650
+ this.index = 0;
651
+ }
652
+ }
653
+ const EstinationData = ['estimated_distance', 'estimated_time'];
654
+ var EstinationEnum;
655
+ (function (EstinationEnum) {
656
+ EstinationEnum["estimated_distance"] = "miles";
657
+ EstinationEnum["estimated_time"] = "time";
658
+ })(EstinationEnum || (EstinationEnum = {}));
659
+ const JobCodeOverviewData = ['customer_contact', 'delivery_contact', 'pickup_location', 'delivery_location', 'project', 'unit'];
660
+ var JobCodeOverviewEnum;
661
+ (function (JobCodeOverviewEnum) {
662
+ JobCodeOverviewEnum["customer_contact"] = "Customer Contact";
663
+ JobCodeOverviewEnum["delivery_contact"] = "Delivery Contact";
664
+ JobCodeOverviewEnum["pickup_location"] = "Pickup";
665
+ JobCodeOverviewEnum["delivery_location"] = "Delivery";
666
+ JobCodeOverviewEnum["project"] = "Project Name";
667
+ JobCodeOverviewEnum["unit"] = "Job Type";
668
+ })(JobCodeOverviewEnum || (JobCodeOverviewEnum = {}));
669
+ const DriversmsCardKey = ['order_number', 'date', 'values', 'material', 'unit', 'pickup_location', 'delivery_location'];
670
+ var DriverSmsCardEnum;
671
+ (function (DriverSmsCardEnum) {
672
+ DriverSmsCardEnum["order_number"] = "Jobcode";
673
+ DriverSmsCardEnum["date"] = "Date";
674
+ DriverSmsCardEnum["values"] = "Total tasks";
675
+ DriverSmsCardEnum["material"] = "Material";
676
+ DriverSmsCardEnum["unit"] = "Unit";
677
+ DriverSmsCardEnum["pickup_location"] = "Pickup Address";
678
+ DriverSmsCardEnum["delivery_location"] = "Delivery Address";
679
+ })(DriverSmsCardEnum || (DriverSmsCardEnum = {}));
680
+ class PopupData {
679
681
  }
680
682
 
681
- /*
682
- * Public API Surface of coolmap-services
683
+ /*
684
+ * Public API Surface of coolmap-services
683
685
  */
684
686
 
685
- /**
686
- * Generated bundle index. Do not edit.
687
+ /**
688
+ * Generated bundle index. Do not edit.
687
689
  */
688
690
 
689
691
  export { CoolmapService, DriverSmsCardEnum, DriversmsCardKey, EstinationData, EstinationEnum, JobCodeOverviewData, JobCodeOverviewEnum, PopupData, Route, UtilsService };