@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.
- package/esm2020/aggdirect-coolmap-services.mjs +5 -0
- package/esm2020/lib/service/coolmap.service.mjs +438 -0
- package/esm2020/lib/service/data-model.mjs +35 -0
- package/esm2020/lib/service/utils.service.mjs +210 -0
- package/esm2020/public-api.mjs +7 -0
- package/fesm2015/aggdirect-coolmap-services.mjs +708 -0
- package/fesm2015/aggdirect-coolmap-services.mjs.map +1 -0
- package/fesm2020/aggdirect-coolmap-services.mjs +690 -0
- package/fesm2020/aggdirect-coolmap-services.mjs.map +1 -0
- package/index.d.ts +5 -0
- package/lib/service/coolmap.service.d.ts +45 -0
- package/lib/service/data-model.d.ts +73 -0
- package/lib/service/utils.service.d.ts +49 -0
- package/package.json +28 -5
- package/public-api.d.ts +3 -0
- package/karma.conf.js +0 -44
- package/ng-package.json +0 -7
- package/src/lib/coolmap-services.component.spec.ts +0 -23
- package/src/lib/coolmap-services.component.ts +0 -20
- package/src/lib/coolmap-services.module.ts +0 -16
- package/src/lib/coolmap-services.service.spec.ts +0 -16
- package/src/lib/coolmap-services.service.ts +0 -9
- package/src/lib/service/coolmap.service.ts +0 -445
- package/src/lib/service/data-model.ts +0 -80
- package/src/lib/service/utils.service.ts +0 -198
- package/src/public-api.ts +0 -13
- package/src/test.ts +0 -27
- package/tsconfig.lib.json +0 -15
- package/tsconfig.lib.prod.json +0 -10
- package/tsconfig.spec.json +0 -17
|
@@ -1,445 +0,0 @@
|
|
|
1
|
-
import { Injectable } from '@angular/core';
|
|
2
|
-
import * as mapboxgl from 'mapbox-gl';
|
|
3
|
-
import * as turf from '@turf/turf';
|
|
4
|
-
import { BehaviorSubject } from 'rxjs';
|
|
5
|
-
import { PopupData, Route } from './data-model';
|
|
6
|
-
import { UtilsService } from './utils.service';
|
|
7
|
-
import { EventManager } from '@angular/platform-browser';
|
|
8
|
-
import { MapboxLayer } from "@deck.gl/mapbox";
|
|
9
|
-
import { ArcLayer } from '@deck.gl/layers';
|
|
10
|
-
|
|
11
|
-
declare const Threebox: any;
|
|
12
|
-
|
|
13
|
-
@Injectable({ providedIn: 'root' })
|
|
14
|
-
export class CoolmapService {
|
|
15
|
-
map!: mapboxgl.Map
|
|
16
|
-
markerOriginList: mapboxgl.Marker[] = [];
|
|
17
|
-
markerDestinationList: mapboxgl.Marker[] = [];
|
|
18
|
-
public initiatecoolmap = new BehaviorSubject(true);
|
|
19
|
-
reintiatecoolmap = this.initiatecoolmap.asObservable();
|
|
20
|
-
bounds = new mapboxgl.LngLatBounds();
|
|
21
|
-
originDestinationCordinates: any = [];
|
|
22
|
-
padding!: any;
|
|
23
|
-
windowActualHeightWidth!: any;
|
|
24
|
-
popup: mapboxgl.Popup;
|
|
25
|
-
|
|
26
|
-
constructor(private utils: UtilsService, private eventManager: EventManager) {
|
|
27
|
-
this.eventManager.addGlobalEventListener('window', 'resize', this.onResize.bind(this)); this.windowActualHeightWidth = { availHeight: 0 };
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
initiateMapForAddRoute(el: HTMLElement) {
|
|
31
|
-
return new Promise((resolve, reject) => {
|
|
32
|
-
this.map = new mapboxgl.Map({
|
|
33
|
-
accessToken: 'pk.eyJ1Ijoic2FudGFudS1vZ21hIiwiYSI6ImNsOGQ0cDVrNjAweTMzb3RmdG9ieTU5ZDkifQ.I6ZS7mViZYSvBo4zz-mGQQ',
|
|
34
|
-
container: el,
|
|
35
|
-
style: 'mapbox://styles/santanu-ogma/cl8ep33uz003414n1twlosz9d',
|
|
36
|
-
center: [-77.036873, 38.907192],
|
|
37
|
-
zoom: 10, bearing: 0, pitch: 65, interactive: true,
|
|
38
|
-
});
|
|
39
|
-
this.map.once('load', (res) => {
|
|
40
|
-
resolve(res);
|
|
41
|
-
});
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
// Below method Load route with animation
|
|
45
|
-
loadMapProperty(pinRouteGeojson: any, index: number, unit: any, route?: any, bottom?: number) {
|
|
46
|
-
return new Promise((resolve, reject)=>{
|
|
47
|
-
let origin = pinRouteGeojson.features[0].geometry.coordinates[0];
|
|
48
|
-
const linecolor = (unit === 'Ton') ? '#ff7272' : (unit === 'Load') ? '#a3c52e' : '#ae23d1';
|
|
49
|
-
let destination = pinRouteGeojson.features[0].geometry.coordinates[pinRouteGeojson.features[0].geometry.coordinates.length - 1];
|
|
50
|
-
this.extendBound(pinRouteGeojson.features[0].geometry.coordinates, true).then((res: any) => {
|
|
51
|
-
const point: any = {
|
|
52
|
-
'type': 'FeatureCollection',
|
|
53
|
-
'features': [
|
|
54
|
-
{ 'type': 'Feature', 'properties': {}, 'geometry': { 'type': 'Point', 'coordinates': origin } }
|
|
55
|
-
]
|
|
56
|
-
}
|
|
57
|
-
const lineDistance = turf.length(pinRouteGeojson.features[0]);
|
|
58
|
-
const arc = [];
|
|
59
|
-
const steps = 10 * pinRouteGeojson.features[0].geometry.coordinates.length;
|
|
60
|
-
for (let i = 0; i < lineDistance; i += lineDistance / steps) {
|
|
61
|
-
const segment = turf.along(pinRouteGeojson.features[0], i);
|
|
62
|
-
arc.push(segment.geometry.coordinates);
|
|
63
|
-
}
|
|
64
|
-
pinRouteGeojson.features[0].geometry.coordinates = arc;
|
|
65
|
-
const pinRoute = pinRouteGeojson.features[0].geometry.coordinates;
|
|
66
|
-
const marker = new mapboxgl.Marker(document.createElement('div'))
|
|
67
|
-
.setLngLat(pinRoute[0]).addTo(this.map).togglePopup();
|
|
68
|
-
|
|
69
|
-
if (this.map.getSource(`line${index}`)) {
|
|
70
|
-
this.removeRouteAndMarker(index).then(() => { })
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
this.map.addSource(`line${index}`, { type: 'geojson', lineMetrics: true, data: pinRouteGeojson });
|
|
74
|
-
this.map.addLayer({
|
|
75
|
-
type: 'line',
|
|
76
|
-
source: `line${index}`,
|
|
77
|
-
id: `line${index}`,
|
|
78
|
-
paint: {
|
|
79
|
-
'line-width': 2,
|
|
80
|
-
'line-gradient': [
|
|
81
|
-
'interpolate',
|
|
82
|
-
['linear'],
|
|
83
|
-
['line-progress'],
|
|
84
|
-
0, unit === 'Ton' ? '#d7f7e4' : unit === 'Load' ? '#c9d8f5' : '#f5dcc1',
|
|
85
|
-
1, unit === 'Ton' ? '#ff7272' : unit === 'Load' ? '#a3c52e' : '#ae23d1',
|
|
86
|
-
]
|
|
87
|
-
},
|
|
88
|
-
layout: { 'line-cap': 'round', 'line-join': 'round' }
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
const dataSetForMap = {
|
|
92
|
-
counter: 0, pinRouteGeojson, steps,
|
|
93
|
-
point, pointId: `point${index}`,
|
|
94
|
-
marker, pinRoute, lineId: `line${index}`, index,
|
|
95
|
-
origin, destination, lineDistance,
|
|
96
|
-
linecolor, route, isViewRoute: true
|
|
97
|
-
}
|
|
98
|
-
this.createMarker(dataSetForMap);
|
|
99
|
-
this.map.on('mouseenter', `line${index}`, (e) => {
|
|
100
|
-
this.map.setPaintProperty(`line${index}`, 'line-width', 5);
|
|
101
|
-
this.map.setPaintProperty(`line${index}`, 'line-opacity', 1);
|
|
102
|
-
const datasetForPopup: PopupData = {
|
|
103
|
-
coordinate: [e.lngLat.lng, e.lngLat.lat],
|
|
104
|
-
pickup: route.pickup_location ? route.pickup_location : '',
|
|
105
|
-
drop: route.delivery_location ? route.delivery_location : '',
|
|
106
|
-
routeType: route.project ? 'Project' : 'Route',
|
|
107
|
-
title: route.project ? route.project : route.route_name ? route.route_name : '',
|
|
108
|
-
material: route.material ? route.material : '',
|
|
109
|
-
type: route.unit ? route.unit : ''
|
|
110
|
-
}
|
|
111
|
-
this.createPopup(datasetForPopup);
|
|
112
|
-
});
|
|
113
|
-
this.map.on('mouseleave', `line${index}`, (e) => {
|
|
114
|
-
this.map.setPaintProperty(`line${index}`, 'line-width', 2);
|
|
115
|
-
if (this.popup) {
|
|
116
|
-
this.popup.remove();
|
|
117
|
-
}
|
|
118
|
-
});
|
|
119
|
-
})
|
|
120
|
-
|
|
121
|
-
this.map.once('idle', (res) => {
|
|
122
|
-
resolve(true)
|
|
123
|
-
});
|
|
124
|
-
})
|
|
125
|
-
}
|
|
126
|
-
// Below method Load route without animation
|
|
127
|
-
drawLine(cordinates?: any, index?: number | any, route?: any, enablefitbound?: boolean, routeType?: string) {
|
|
128
|
-
let linecolor: any;
|
|
129
|
-
let origin = cordinates[0]; let destination = cordinates[cordinates.length - 1]
|
|
130
|
-
if (origin[0] && origin[1] && destination && destination[0] && destination[1]) {
|
|
131
|
-
linecolor = this.provideLineColor(route['unit'], routeType);
|
|
132
|
-
if (enablefitbound) {
|
|
133
|
-
const padding = {
|
|
134
|
-
top: this.padding.top, bottom: this.padding.bottom + (this.windowActualHeightWidth.availHeight - (window.innerHeight - 65)),
|
|
135
|
-
left: this.padding.left, right: this.padding.right
|
|
136
|
-
}
|
|
137
|
-
this.map.fitBounds([origin, destination], { padding }, { fitboundCompleteJob: true })
|
|
138
|
-
}
|
|
139
|
-
if (this.map.getSource(`route-source-for-job-code${index}`)) {
|
|
140
|
-
this.removeRouteAndMarker(index).then(() => { })
|
|
141
|
-
}
|
|
142
|
-
this.map.addSource(`route-source-for-job-code${index}`, {
|
|
143
|
-
'type': 'geojson',
|
|
144
|
-
'data': { 'type': 'Feature', 'properties': {}, 'geometry': { 'type': 'LineString', 'coordinates': cordinates } }
|
|
145
|
-
});
|
|
146
|
-
this.map.addLayer({
|
|
147
|
-
'id': `route-for-job-code${index}`, 'type': 'line', 'source': `route-source-for-job-code${index}`,
|
|
148
|
-
paint: { 'line-color': linecolor, 'line-width': 2 },
|
|
149
|
-
layout: { 'line-cap': 'round', 'line-join': 'round' }
|
|
150
|
-
});
|
|
151
|
-
const dataSetForMap = {
|
|
152
|
-
origin, destination, index, linecolor, route
|
|
153
|
-
}
|
|
154
|
-
this.createMarker(dataSetForMap);
|
|
155
|
-
this.map.on('mouseenter', `route-for-job-code${index}`, (e) => {
|
|
156
|
-
if (this.popup) {
|
|
157
|
-
this.popup.remove();
|
|
158
|
-
}
|
|
159
|
-
this.map.setPaintProperty(`route-for-job-code${index}`, 'line-width', 5);
|
|
160
|
-
this.map.setPaintProperty(`route-for-job-code${index}`, 'line-opacity', 1);
|
|
161
|
-
const datasetForPopup: PopupData = {
|
|
162
|
-
coordinate: [e.lngLat.lng, e.lngLat.lat],
|
|
163
|
-
pickup: route.pickup_location ? route.pickup_location : '',
|
|
164
|
-
drop: route.delivery_location ? route.delivery_location : '',
|
|
165
|
-
jobCode: route.project ? route.order_number : null,
|
|
166
|
-
customer: route.project ? route.customer_name : null,
|
|
167
|
-
routeType: route.project ? 'Project' : 'Route',
|
|
168
|
-
title: route.project ? route.project : route.route_name ? route.route_name : '',
|
|
169
|
-
material: route.material ? route.material : '',
|
|
170
|
-
type: route.unit ? route.unit : ''
|
|
171
|
-
}
|
|
172
|
-
this.createPopup(datasetForPopup);
|
|
173
|
-
});
|
|
174
|
-
this.map.on('mouseleave', `route-for-job-code${index}`, (e) => {
|
|
175
|
-
this.map.setPaintProperty(`route-for-job-code${index}`, 'line-width', 2);
|
|
176
|
-
if (this.popup) {
|
|
177
|
-
this.popup.remove();
|
|
178
|
-
}
|
|
179
|
-
});
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
provideLineColor(unitType: string, type?: string | undefined) {
|
|
184
|
-
let checkType = (type && !['jobrouteList', 'addroute'].includes(type)) ? true : false;
|
|
185
|
-
let color;
|
|
186
|
-
switch (unitType) {
|
|
187
|
-
case "Ton":
|
|
188
|
-
color = checkType ? '#39c471' : '#ff7272';
|
|
189
|
-
break;
|
|
190
|
-
case "Load":
|
|
191
|
-
color = checkType ? '#326ad3' : '#a3c52e';
|
|
192
|
-
break;
|
|
193
|
-
case "Hourly":
|
|
194
|
-
color = checkType ? '#ffad56' : '#ae23d1';
|
|
195
|
-
break;
|
|
196
|
-
}
|
|
197
|
-
return color;
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
showRoutePopup(arcDetails, event, isViewRoute?): void {
|
|
201
|
-
if (this.popup) {
|
|
202
|
-
this.popup.remove();
|
|
203
|
-
this.map.setPaintProperty(`${isViewRoute ? 'line' : 'route-for-job-code'}${arcDetails.layer.props.data.index}`, 'line-width', 2);
|
|
204
|
-
}
|
|
205
|
-
if (arcDetails.color && this.map.getLayoutProperty(arcDetails.layer.id, 'visibility') !== 'none') {
|
|
206
|
-
this.map.setPaintProperty(`${isViewRoute ? 'line' : 'route-for-job-code'}${arcDetails.layer.props.data.index}`, 'line-width', 5);
|
|
207
|
-
this.map.setPaintProperty(`${isViewRoute ? 'line' : 'route-for-job-code'}${arcDetails.layer.props.data.index}`, 'line-opacity', 1);
|
|
208
|
-
|
|
209
|
-
const datasetForPopup: PopupData = {
|
|
210
|
-
coordinate: arcDetails.coordinate,
|
|
211
|
-
pickup: arcDetails.layer.props.data.route.pickup_location ? arcDetails.layer.props.data.route.pickup_location : '',
|
|
212
|
-
drop: arcDetails.layer.props.data.route.delivery_location ? arcDetails.layer.props.data.route.delivery_location : '',
|
|
213
|
-
jobCode: arcDetails.layer.props.data.route.project ? arcDetails.layer.props.data.route.order_number : '',
|
|
214
|
-
customer: arcDetails.layer.props.data.route.project ? arcDetails.layer.props.data.route.customer_name : '',
|
|
215
|
-
routeType: arcDetails.layer.props.data.route.project ? 'Project' : 'Route',
|
|
216
|
-
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 : '',
|
|
217
|
-
material: arcDetails.layer.props.data.route.material ? arcDetails.layer.props.data.route.material : '',
|
|
218
|
-
type: arcDetails.layer.props.data.route.unit ? arcDetails.layer.props.data.route.unit : ''
|
|
219
|
-
}
|
|
220
|
-
this.createPopup(datasetForPopup);
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
createPopup(datasetForPopup: PopupData): void {
|
|
225
|
-
this.popup = new mapboxgl.Popup({
|
|
226
|
-
closeButton: false,
|
|
227
|
-
closeOnClick: false,
|
|
228
|
-
closeOnMove: true,
|
|
229
|
-
anchor: 'bottom-left'
|
|
230
|
-
});
|
|
231
|
-
|
|
232
|
-
this.popup.setLngLat(datasetForPopup.coordinate)
|
|
233
|
-
.setHTML(`
|
|
234
|
-
<div class="destination">
|
|
235
|
-
<div class="duration">
|
|
236
|
-
<p class="pickprt"><b>Pickup Location:</b> ${datasetForPopup.pickup}</p>
|
|
237
|
-
<p class="dropprt"><b>Drop Location:</b> ${datasetForPopup.drop}</p>
|
|
238
|
-
</div>
|
|
239
|
-
${datasetForPopup.jobCode ? '<span><b>Job Code:</b> ' + datasetForPopup.jobCode + '</span>' : ''}
|
|
240
|
-
${datasetForPopup.customer ? '<span><b>Customer:</b> ' + datasetForPopup.customer + '</span>' : ''}
|
|
241
|
-
<span><b>${datasetForPopup.routeType} Name:</b> ${datasetForPopup.title}</span>
|
|
242
|
-
<span><b>Material:</b> ${datasetForPopup.material}</span>
|
|
243
|
-
<span><b>Type:</b> ${datasetForPopup.type}</span>
|
|
244
|
-
</div>
|
|
245
|
-
`)
|
|
246
|
-
.addTo(this.map);
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
hexToRGB(hex: any): [number, number, number] {
|
|
250
|
-
return hex.replace(/^#?([a-f\d])([a-f\d])([a-f\d])$/i
|
|
251
|
-
, (m, r, g, b) => '#' + r + r + g + g + b + b)
|
|
252
|
-
.substring(1).match(/.{2}/g)
|
|
253
|
-
.map(x => parseInt(x, 16))
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
createMarker(routeDetails) {
|
|
257
|
-
if (routeDetails.origin[0] && routeDetails.origin[1] && routeDetails.destination[0] && routeDetails.destination[1]) {
|
|
258
|
-
|
|
259
|
-
const popup = new mapboxgl.Popup({ closeButton: false }).setHTML('<b>Pickup: </b>' + routeDetails.route?.pickup_location);
|
|
260
|
-
const popupForDestination = new mapboxgl.Popup({ closeButton: false })
|
|
261
|
-
.setHTML('<b>Delivery: </b>' + routeDetails.route?.delivery_location);
|
|
262
|
-
|
|
263
|
-
const el = document.createElement('div');
|
|
264
|
-
el.className = 'marker';
|
|
265
|
-
el.innerHTML = `<span class='markerPointer' style='background:${routeDetails.linecolor}'><b>P</b><span class='markerSpan' style='border-top: 10px solid ${routeDetails.linecolor}'></span></span>`
|
|
266
|
-
|
|
267
|
-
const originMarker = new mapboxgl.Marker(el)
|
|
268
|
-
.setPopup(popup).setLngLat(routeDetails.origin).addTo(this.map);
|
|
269
|
-
|
|
270
|
-
originMarker.getElement().addEventListener('mouseenter', () => originMarker.togglePopup());
|
|
271
|
-
originMarker.getElement().addEventListener('mouseleave', () => originMarker.togglePopup());
|
|
272
|
-
|
|
273
|
-
const elementForDestination = document.createElement('div');
|
|
274
|
-
elementForDestination.className = 'marker';
|
|
275
|
-
elementForDestination.innerHTML = `<span class='markerPointer' style='background:${routeDetails.linecolor}'><b>D</b><span class='markerSpan' style='border-top: 10px solid ${routeDetails.linecolor}'></span></span>`
|
|
276
|
-
|
|
277
|
-
const destinationMarker = new mapboxgl.Marker(elementForDestination).setPopup(popupForDestination).setLngLat(routeDetails.destination).addTo(this.map);
|
|
278
|
-
destinationMarker.getElement().addEventListener('mouseenter', () => destinationMarker.togglePopup());
|
|
279
|
-
destinationMarker.getElement().addEventListener('mouseleave', () => destinationMarker.togglePopup());
|
|
280
|
-
this.markerOriginList[routeDetails.index] = originMarker;
|
|
281
|
-
this.markerDestinationList[routeDetails.index] = destinationMarker;
|
|
282
|
-
|
|
283
|
-
const colorArray = this.hexToRGB(routeDetails.linecolor)
|
|
284
|
-
const arcLayer = new MapboxLayer({
|
|
285
|
-
id: 'arc-layer' + routeDetails.index,
|
|
286
|
-
type: ArcLayer,
|
|
287
|
-
pickable: true,
|
|
288
|
-
data: { route: routeDetails.route, index: routeDetails.index },
|
|
289
|
-
getWidth: 1,
|
|
290
|
-
getSourcePosition: routeDetails.origin,
|
|
291
|
-
getTargetPosition: routeDetails.destination,
|
|
292
|
-
getTargetColor: [255, 255, 255],
|
|
293
|
-
getSourceColor: [colorArray[0], colorArray[1], colorArray[2]],
|
|
294
|
-
onHover: (info, event) => this.showRoutePopup(info, event, routeDetails.isViewRoute),
|
|
295
|
-
});
|
|
296
|
-
this.map.addLayer(arcLayer);
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
async removeRouteAndMarker(index: number | string | any) {
|
|
301
|
-
if (this.map) {
|
|
302
|
-
this.map.getLayer(`arc-layer${index}`) ? this.map.removeLayer(`arc-layer${index}`) : '';
|
|
303
|
-
this.map.getLayer(`line${index}`) ? this.map.removeLayer(`line${index}`) : '';
|
|
304
|
-
this.map.getLayer(`custom_layer${index}`) ? this.map.removeLayer(`custom_layer${index}`) : '';
|
|
305
|
-
this.map.getSource(`line${index}`) ? this.map.removeSource(`line${index}`) : '';
|
|
306
|
-
this.map.getLayer(`route-for-job-code${index}`) ? this.map.removeLayer(`route-for-job-code${index}`) : '';
|
|
307
|
-
this.map.getSource(`route-source-for-job-code${index}`) ? this.map.removeSource(`route-source-for-job-code${index}`) : '';
|
|
308
|
-
this.findMarkerBound(index);
|
|
309
|
-
this.markerOriginList[index] ? this.markerOriginList[index].remove() : '';
|
|
310
|
-
this.markerDestinationList[index] ? this.markerDestinationList[index].remove() : '';
|
|
311
|
-
await true;
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
findMarkerBound(index: any) {
|
|
315
|
-
const indexOfCordinates = this.originDestinationCordinates.findIndex((x: any) =>
|
|
316
|
-
(x[0][0].toFixed(6) == this.markerOriginList[index]?.getLngLat()?.lng.toFixed(6)) && (x[0][1].toFixed(6) == this.markerOriginList[index]?.getLngLat()?.lat.toFixed(6)));
|
|
317
|
-
if (indexOfCordinates >= 0) { this.originDestinationCordinates.splice(indexOfCordinates, 1) }
|
|
318
|
-
}
|
|
319
|
-
async filterRoute(ID: any, visibility: string, showAllFitbound?: boolean) {
|
|
320
|
-
if (ID) {
|
|
321
|
-
if (this.map.getLayer(`route-for-job-code${ID}`)) {
|
|
322
|
-
this.map.setLayoutProperty(`route-for-job-code${ID}`, 'visibility', visibility);
|
|
323
|
-
const originM = this.markerOriginList[ID].getElement();
|
|
324
|
-
originM.style.display = ((visibility === 'visible') ? 'block' : visibility);
|
|
325
|
-
const destinationM = this.markerDestinationList[ID].getElement();
|
|
326
|
-
destinationM.style.display = ((visibility === 'visible') ? 'block' : visibility);
|
|
327
|
-
if (visibility === 'none' && showAllFitbound) {
|
|
328
|
-
this.findMarkerBound(ID);
|
|
329
|
-
this.extendReBound();
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
if (this.map.getLayer(`arc-layer${ID}`)) {
|
|
333
|
-
this.map.setLayoutProperty(`arc-layer${ID}`, 'visibility', visibility);
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
await true;
|
|
337
|
-
}
|
|
338
|
-
extendBound(route: any, showAllFitbound: boolean | undefined) {
|
|
339
|
-
return new Promise((resolve, reject) => {
|
|
340
|
-
if (route) {
|
|
341
|
-
if (typeof route === 'string') {
|
|
342
|
-
let path: any = route.split(';');
|
|
343
|
-
path = path.map((ele: string | any) => { return ele = this.formateLatLong(ele) });
|
|
344
|
-
path.forEach((ele: any, index: number) => { if (ele.length === 1) path.splice(index, 1) });
|
|
345
|
-
route = path
|
|
346
|
-
}
|
|
347
|
-
if (route[0][0] && route[0][1] && route[route.length - 1][0] && route[route.length - 1][1]) {
|
|
348
|
-
this.originDestinationCordinates.push(route);
|
|
349
|
-
route.map((item: any) => {
|
|
350
|
-
this.bounds.extend(item);
|
|
351
|
-
})
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
if (showAllFitbound) {
|
|
355
|
-
const padding = { top: this.padding.top, bottom: (this.padding.bottom + (this.windowActualHeightWidth.availHeight - (window.innerHeight - 65))), left: this.padding.left, right: this.padding.right }
|
|
356
|
-
setTimeout(() => {
|
|
357
|
-
if (showAllFitbound && (Object.keys(this.bounds).length > 0)) this.map.fitBounds(this.bounds, { padding }, { fitboundComplete: true })
|
|
358
|
-
}, 100);
|
|
359
|
-
this.map.once('moveend', (event: any) => { if (event.fitboundComplete) { resolve(true) } });
|
|
360
|
-
}
|
|
361
|
-
});
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
extendReBound(bottom?: number) {
|
|
365
|
-
return new Promise((resolve, reject) => {
|
|
366
|
-
this.bounds = new mapboxgl.LngLatBounds();
|
|
367
|
-
|
|
368
|
-
if (this.originDestinationCordinates.length >= 0) {
|
|
369
|
-
this.originDestinationCordinates.map((item: any, index: number) => {
|
|
370
|
-
item.map((route: any) => {
|
|
371
|
-
this.bounds.extend(route);
|
|
372
|
-
})
|
|
373
|
-
if (index === (this.originDestinationCordinates.length - 1)) {
|
|
374
|
-
const padding = { top: this.padding.top, bottom: (this.padding.bottom + (this.windowActualHeightWidth.availHeight - (window.innerHeight - 65))), left: this.padding.left, right: this.padding.right }
|
|
375
|
-
setTimeout(() => {
|
|
376
|
-
if (this.originDestinationCordinates.length > 0) this.map.fitBounds(this.bounds, { padding });
|
|
377
|
-
}, 500);
|
|
378
|
-
resolve(true);
|
|
379
|
-
}
|
|
380
|
-
})
|
|
381
|
-
} else {
|
|
382
|
-
resolve(true);
|
|
383
|
-
}
|
|
384
|
-
})
|
|
385
|
-
}
|
|
386
|
-
plotRoute(route: any, i: number | any, type: string, enablefitbound?: boolean, showAllFitbound?: boolean) {
|
|
387
|
-
return new Promise((resolve, reject) => {
|
|
388
|
-
let param: any = {};
|
|
389
|
-
if (['jobcode'].includes(type)) {
|
|
390
|
-
param['job'] = route['job_id']
|
|
391
|
-
this.utils.postDataWithRestUrl('schedule/job/path', param).subscribe((res: any) => {
|
|
392
|
-
if (res['data']['route']) {
|
|
393
|
-
let path = res['data']['route'].split(';');
|
|
394
|
-
path = path.map((ele: string | any) => { return ele = this.formateLatLong(ele) });
|
|
395
|
-
path.forEach((ele: any, index: number) => { if (ele.length === 1) path.splice(index, 1) });
|
|
396
|
-
route['path'] = path;
|
|
397
|
-
this.extendBound(route['path'], showAllFitbound);
|
|
398
|
-
if (route['path'] && route['path'].length > 0) this.drawLine(route['path'], i, route, enablefitbound, type);
|
|
399
|
-
route['index'] = i;
|
|
400
|
-
} else {
|
|
401
|
-
this.extendBound(null, showAllFitbound);
|
|
402
|
-
}
|
|
403
|
-
resolve(true);
|
|
404
|
-
}, (err) => { if (err) { reject(false) } });
|
|
405
|
-
} else if (['jobrouteList', 'addroute'].includes(type)) {
|
|
406
|
-
if (route['path'] && route['path'].length > 0) {
|
|
407
|
-
let path = route['path'].split(';');
|
|
408
|
-
path = path.map((ele: string | any) => { return ele = this.formateLatLong(ele) });
|
|
409
|
-
path.forEach((ele: any, index: number) => { if (ele.length === 1) path.splice(index, 1) });
|
|
410
|
-
this.extendBound(path, showAllFitbound);
|
|
411
|
-
this.drawLine(path, i, route, enablefitbound, type)
|
|
412
|
-
};
|
|
413
|
-
}
|
|
414
|
-
})
|
|
415
|
-
}
|
|
416
|
-
clearBound() { this.bounds = new mapboxgl.LngLatBounds(); this.originDestinationCordinates = []; this.clearPadding(); }
|
|
417
|
-
formateLatLong(latlong: string) { return latlong ? latlong.split(',').map(x => +x).reverse() : null; }
|
|
418
|
-
clearBoundWithCordinates() {
|
|
419
|
-
this.bounds = new mapboxgl.LngLatBounds(); this.originDestinationCordinates = [];
|
|
420
|
-
}
|
|
421
|
-
|
|
422
|
-
onResize(event: any) {
|
|
423
|
-
if (!this.bounds.isEmpty()) {
|
|
424
|
-
this.windowActualHeightWidth.availHeight = (window.innerHeight > window.screen.availHeight) ? window.innerHeight : window.screen.availHeight;
|
|
425
|
-
setTimeout(() => {
|
|
426
|
-
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 } });
|
|
427
|
-
}, 500);
|
|
428
|
-
}
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
setWindowHeight(screen: any) {
|
|
432
|
-
this.windowActualHeightWidth.availHeight = screen;
|
|
433
|
-
}
|
|
434
|
-
setPadding(padding: any) { this.padding = padding }
|
|
435
|
-
clearPadding() { this.padding = null }
|
|
436
|
-
removeJobFromMap(data: Route[]) {
|
|
437
|
-
data.map((ele: any, index: number) => {
|
|
438
|
-
const id = (ele['job_id'] ? ele['job_id'] : ele['route_id']);
|
|
439
|
-
this.removeRouteAndMarker(id);
|
|
440
|
-
if (index === (data.length - 1)) {
|
|
441
|
-
this.extendReBound();
|
|
442
|
-
}
|
|
443
|
-
})
|
|
444
|
-
}
|
|
445
|
-
}
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
export class Route {
|
|
3
|
-
index: number = 0;
|
|
4
|
-
type?: string | null;
|
|
5
|
-
// Job Code
|
|
6
|
-
customer_contact?: string | null;
|
|
7
|
-
customer_name?: string | null;
|
|
8
|
-
delivery_contact?: string | null;
|
|
9
|
-
delivery_lat?: number | null;
|
|
10
|
-
delivery_location?: string | null | undefined;
|
|
11
|
-
delivery_lon?: number | null;
|
|
12
|
-
driver_list?: Array<any>;
|
|
13
|
-
material?: string | null;
|
|
14
|
-
order_number?: string | null;
|
|
15
|
-
pickup_lat?: number | null;
|
|
16
|
-
pickup_location?: string | null | undefined;
|
|
17
|
-
pickup_lon?: number | null;
|
|
18
|
-
project?: string | null;
|
|
19
|
-
total_count?: number;
|
|
20
|
-
unit?: string | null;
|
|
21
|
-
values: any;
|
|
22
|
-
job_id?: string;
|
|
23
|
-
isSelected?: boolean;
|
|
24
|
-
date?: string;
|
|
25
|
-
// Add Route
|
|
26
|
-
created_at?: string | null;
|
|
27
|
-
created_by_name?: string | null;
|
|
28
|
-
customer_id?: string | null;
|
|
29
|
-
delivery_lat_lng?: string | null;
|
|
30
|
-
estimated_distance?: string | null;
|
|
31
|
-
estimated_time?: string | null;
|
|
32
|
-
materials_id?: string | null;
|
|
33
|
-
path?: [number, number];
|
|
34
|
-
pickup_lat_lng?: string | null;
|
|
35
|
-
route_id?: string | null;
|
|
36
|
-
route_name?: string | null;
|
|
37
|
-
unit_id?: string | null;
|
|
38
|
-
note?: string | null
|
|
39
|
-
isActive?: boolean;
|
|
40
|
-
prevent?: boolean;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export const EstinationData = ['estimated_distance', 'estimated_time']
|
|
44
|
-
export enum EstinationEnum {
|
|
45
|
-
estimated_distance = "miles",
|
|
46
|
-
estimated_time = "time"
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export const JobCodeOverviewData = ['customer_contact', 'delivery_contact', 'pickup_location', 'delivery_location', 'project', 'unit']
|
|
50
|
-
export enum JobCodeOverviewEnum {
|
|
51
|
-
customer_contact = 'Customer Contact',
|
|
52
|
-
delivery_contact = 'Delivery Contact',
|
|
53
|
-
pickup_location = 'Pickup',
|
|
54
|
-
delivery_location = 'Delivery',
|
|
55
|
-
project = 'Project Name',
|
|
56
|
-
unit = 'Job Type',
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export const DriversmsCardKey = ['order_number', 'date', 'values', 'material', 'unit', 'pickup_location', 'delivery_location']
|
|
60
|
-
export enum DriverSmsCardEnum {
|
|
61
|
-
order_number = 'Jobcode',
|
|
62
|
-
date = 'Date',
|
|
63
|
-
values = 'Total tasks',
|
|
64
|
-
material = 'Material',
|
|
65
|
-
unit = 'Unit',
|
|
66
|
-
pickup_location = 'Pickup Address',
|
|
67
|
-
delivery_location = 'Delivery Address'
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export class PopupData {
|
|
71
|
-
coordinate: [number, number];
|
|
72
|
-
pickup: string | null;
|
|
73
|
-
jobCode?: string | null;
|
|
74
|
-
customer?: string | null;
|
|
75
|
-
drop: string | null;
|
|
76
|
-
routeType: string | null;
|
|
77
|
-
title: string | null;
|
|
78
|
-
material: string | null;
|
|
79
|
-
type: string | null;
|
|
80
|
-
}
|