kwikid-agent-dashboard 0.0.49 → 0.0.50
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/bundles/kwikid-agent-dashboard.umd.js +247 -116
- package/bundles/kwikid-agent-dashboard.umd.js.map +1 -1
- package/esm2015/lib/v1/services/open-street-maps.service.js +195 -89
- package/fesm2015/kwikid-agent-dashboard.js +194 -88
- package/fesm2015/kwikid-agent-dashboard.js.map +1 -1
- package/lib/v1/services/open-street-maps.service.d.ts +14 -3
- package/package.json +1 -1
|
@@ -502,8 +502,17 @@
|
|
|
502
502
|
}
|
|
503
503
|
return next();
|
|
504
504
|
}
|
|
505
|
-
function __rewriteRelativeImportExtension(path, preserveJsx) {
|
|
505
|
+
function __rewriteRelativeImportExtension(path, preserveJsx, extraExtensions, ignoreCase) {
|
|
506
506
|
if (typeof path === "string" && /^\.\.?\//.test(path)) {
|
|
507
|
+
if (extraExtensions) {
|
|
508
|
+
for (var extension in extraExtensions) {
|
|
509
|
+
var suffix = path.slice(-extension.length);
|
|
510
|
+
if (suffix === extension || ignoreCase && suffix.toLowerCase() === extension.toLowerCase()) {
|
|
511
|
+
var output = extraExtensions[extension];
|
|
512
|
+
return output === extension ? path : path.slice(0, -extension.length) + output;
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
}
|
|
507
516
|
return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
|
|
508
517
|
return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
|
|
509
518
|
});
|
|
@@ -2228,11 +2237,18 @@
|
|
|
2228
2237
|
this.mapDirectionsService = mapDirectionsService;
|
|
2229
2238
|
this.httpClient = httpClient;
|
|
2230
2239
|
this.allMarkers = [];
|
|
2240
|
+
// Geocoded locations by address, so re-plotting does not query Nominatim again
|
|
2241
|
+
this.locationCache = new Map();
|
|
2242
|
+
this.lastGeocodeAt = 0;
|
|
2243
|
+
// Every Nominatim request goes through this chain, so they never overlap
|
|
2244
|
+
this.geocodeQueue = Promise.resolve();
|
|
2245
|
+
// Only the latest plot may draw; an older one still geocoding is dropped
|
|
2246
|
+
this.plotRunId = 0;
|
|
2231
2247
|
}
|
|
2232
2248
|
// To get Current Position
|
|
2233
2249
|
OpenStreetMapsService.prototype.getPosition = function () {
|
|
2234
2250
|
return new Promise(function (resolve, reject) {
|
|
2235
|
-
navigator.geolocation.
|
|
2251
|
+
navigator.geolocation.getCurrentPosition(function (resp) {
|
|
2236
2252
|
resolve({
|
|
2237
2253
|
lng: resp.coords.longitude,
|
|
2238
2254
|
lat: resp.coords.latitude
|
|
@@ -2246,43 +2262,37 @@
|
|
|
2246
2262
|
OpenStreetMapsService.prototype.getLocation = function (task) {
|
|
2247
2263
|
return __awaiter(this, void 0, void 0, function () {
|
|
2248
2264
|
var _this = this;
|
|
2249
|
-
return __generator(this, function (
|
|
2265
|
+
return __generator(this, function (_l) {
|
|
2250
2266
|
return [2 /*return*/, new Promise(function (resolve) { return __awaiter(_this, void 0, void 0, function () {
|
|
2251
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k,
|
|
2252
|
-
return __generator(this, function (
|
|
2253
|
-
switch (
|
|
2267
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, address, config, config, location, _l, _m, _o, isValidLocation;
|
|
2268
|
+
return __generator(this, function (_p) {
|
|
2269
|
+
switch (_p.label) {
|
|
2254
2270
|
case 0:
|
|
2255
2271
|
// If Fetch Address from Multiple Paths
|
|
2256
2272
|
if (kwikidToolkit.checkObjectPathExists(this.agentService.config, "extendedFlags.taskLocationPaths")) {
|
|
2257
2273
|
config = this.agentService.config.extendedFlags.taskLocationPaths;
|
|
2258
2274
|
address = addressConcator(task, config);
|
|
2259
|
-
// Encode the Address in URI
|
|
2260
|
-
encodedAddres = encodeURI(address);
|
|
2261
2275
|
}
|
|
2262
2276
|
// If Fetch Address from Single Path
|
|
2263
2277
|
else if (kwikidToolkit.checkObjectPathExists(this.agentService.config, "extendedFlags.taskLocationPath")) {
|
|
2264
2278
|
config = this.agentService.config.extendedFlags.taskLocationPath;
|
|
2265
2279
|
address = kwikidToolkit.getObjectValueFromPath(task, config);
|
|
2266
|
-
// Encode the Address in URI
|
|
2267
|
-
encodedAddres = encodeURI(address);
|
|
2268
2280
|
}
|
|
2269
2281
|
// Default Address Paths Avaiable
|
|
2270
2282
|
else {
|
|
2271
|
-
address =
|
|
2272
|
-
|
|
2273
|
-
encodedAddres = encodeURI(address);
|
|
2283
|
+
address =
|
|
2284
|
+
(_k = (_j = (_g = (_d = (_c = (_b = (_a = task === null || task === void 0 ? void 0 : task.extras) === null || _a === void 0 ? void 0 : _a.task_details) === null || _b === void 0 ? void 0 : _b.customer_details) === null || _c === void 0 ? void 0 : _c.address) !== null && _d !== void 0 ? _d : (_f = (_e = task === null || task === void 0 ? void 0 : task.task_details) === null || _e === void 0 ? void 0 : _e.customer_details) === null || _f === void 0 ? void 0 : _f.address) !== null && _g !== void 0 ? _g : (_h = task === null || task === void 0 ? void 0 : task.extras) === null || _h === void 0 ? void 0 : _h.address) !== null && _j !== void 0 ? _j : task === null || task === void 0 ? void 0 : task.address) !== null && _k !== void 0 ? _k : "";
|
|
2274
2285
|
}
|
|
2275
|
-
|
|
2276
|
-
|
|
2286
|
+
address = String(address !== null && address !== void 0 ? address : "")
|
|
2287
|
+
.replace(/\b(undefined|null)\b/g, " ")
|
|
2288
|
+
.replace(/\s+/g, " ")
|
|
2289
|
+
.trim();
|
|
2290
|
+
_m = (_l = Object).assign;
|
|
2291
|
+
_o = [{}];
|
|
2292
|
+
return [4 /*yield*/, this.geocodeAddress(address)];
|
|
2277
2293
|
case 1:
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
case 2:
|
|
2281
|
-
data = _q.sent();
|
|
2282
|
-
isValidLocation = kwikidToolkit.isNotEmptyArray(data) && ((_l = data[0]) === null || _l === void 0 ? void 0 : _l.lat) & ((_m = data[0]) === null || _m === void 0 ? void 0 : _m.lon);
|
|
2283
|
-
location = isValidLocation
|
|
2284
|
-
? { lat: (_o = data[0]) === null || _o === void 0 ? void 0 : _o.lat, lng: (_p = data[0]) === null || _p === void 0 ? void 0 : _p.lon }
|
|
2285
|
-
: { lat: null, lng: null };
|
|
2294
|
+
location = _m.apply(_l, _o.concat([(_p.sent())]));
|
|
2295
|
+
isValidLocation = location.lat !== null && location.lng !== null;
|
|
2286
2296
|
// Set Location validation & Google Maps URL
|
|
2287
2297
|
location.isValidLocation = isValidLocation;
|
|
2288
2298
|
location.color = isValidLocation ? "blue" : "red";
|
|
@@ -2295,55 +2305,122 @@
|
|
|
2295
2305
|
});
|
|
2296
2306
|
});
|
|
2297
2307
|
};
|
|
2298
|
-
//
|
|
2308
|
+
// Geocode an address with Nominatim: one request at a time, results cached
|
|
2309
|
+
OpenStreetMapsService.prototype.geocodeAddress = function (address) {
|
|
2310
|
+
var _this = this;
|
|
2311
|
+
if (!address) {
|
|
2312
|
+
return Promise.resolve({ lat: null, lng: null });
|
|
2313
|
+
}
|
|
2314
|
+
if (!this.locationCache.has(address)) {
|
|
2315
|
+
var request = this.geocodeQueue.then(function () { return _this.fetchLocation(address); });
|
|
2316
|
+
this.geocodeQueue = request.catch(function () { return undefined; });
|
|
2317
|
+
this.locationCache.set(address, request);
|
|
2318
|
+
request.then(function (result) {
|
|
2319
|
+
// Do not keep failures (rate limit, outage); retry on the next plot
|
|
2320
|
+
if (result.failed) {
|
|
2321
|
+
_this.locationCache.delete(address);
|
|
2322
|
+
}
|
|
2323
|
+
});
|
|
2324
|
+
}
|
|
2325
|
+
return this.locationCache
|
|
2326
|
+
.get(address)
|
|
2327
|
+
.then(function (_l) {
|
|
2328
|
+
var lat = _l.lat, lng = _l.lng;
|
|
2329
|
+
return ({ lat: lat, lng: lng });
|
|
2330
|
+
});
|
|
2331
|
+
};
|
|
2332
|
+
OpenStreetMapsService.prototype.fetchLocation = function (address) {
|
|
2333
|
+
var _a, _b;
|
|
2334
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2335
|
+
var wait, url, controller_1, timer, data, response, lat, lng, error_1;
|
|
2336
|
+
return __generator(this, function (_l) {
|
|
2337
|
+
switch (_l.label) {
|
|
2338
|
+
case 0:
|
|
2339
|
+
wait = this.lastGeocodeAt +
|
|
2340
|
+
OpenStreetMapsService.GEOCODE_INTERVAL_MS -
|
|
2341
|
+
Date.now();
|
|
2342
|
+
if (!(wait > 0)) return [3 /*break*/, 2];
|
|
2343
|
+
return [4 /*yield*/, new Promise(function (resolve) { return setTimeout(resolve, wait); })];
|
|
2344
|
+
case 1:
|
|
2345
|
+
_l.sent();
|
|
2346
|
+
_l.label = 2;
|
|
2347
|
+
case 2:
|
|
2348
|
+
this.lastGeocodeAt = Date.now();
|
|
2349
|
+
_l.label = 3;
|
|
2350
|
+
case 3:
|
|
2351
|
+
_l.trys.push([3, 9, , 10]);
|
|
2352
|
+
url = "https://nominatim.openstreetmap.org/search?q=" + encodeURIComponent(address) + "&format=json&limit=1";
|
|
2353
|
+
controller_1 = new AbortController();
|
|
2354
|
+
timer = setTimeout(function () { return controller_1.abort(); }, OpenStreetMapsService.GEOCODE_TIMEOUT_MS);
|
|
2355
|
+
data = void 0;
|
|
2356
|
+
_l.label = 4;
|
|
2357
|
+
case 4:
|
|
2358
|
+
_l.trys.push([4, , 7, 8]);
|
|
2359
|
+
return [4 /*yield*/, fetch(url, { signal: controller_1.signal })];
|
|
2360
|
+
case 5:
|
|
2361
|
+
response = _l.sent();
|
|
2362
|
+
if (!response.ok) {
|
|
2363
|
+
return [2 /*return*/, { lat: null, lng: null, failed: true }];
|
|
2364
|
+
}
|
|
2365
|
+
return [4 /*yield*/, response.json()];
|
|
2366
|
+
case 6:
|
|
2367
|
+
data = _l.sent();
|
|
2368
|
+
return [3 /*break*/, 8];
|
|
2369
|
+
case 7:
|
|
2370
|
+
clearTimeout(timer);
|
|
2371
|
+
return [7 /*endfinally*/];
|
|
2372
|
+
case 8:
|
|
2373
|
+
lat = kwikidToolkit.isNotEmptyArray(data) ? parseFloat((_a = data[0]) === null || _a === void 0 ? void 0 : _a.lat) : NaN;
|
|
2374
|
+
lng = kwikidToolkit.isNotEmptyArray(data) ? parseFloat((_b = data[0]) === null || _b === void 0 ? void 0 : _b.lon) : NaN;
|
|
2375
|
+
return [2 /*return*/, Number.isFinite(lat) && Number.isFinite(lng)
|
|
2376
|
+
? { lat: lat, lng: lng }
|
|
2377
|
+
: { lat: null, lng: null }];
|
|
2378
|
+
case 9:
|
|
2379
|
+
error_1 = _l.sent();
|
|
2380
|
+
return [2 /*return*/, { lat: null, lng: null, failed: true }];
|
|
2381
|
+
case 10: return [2 /*return*/];
|
|
2382
|
+
}
|
|
2383
|
+
});
|
|
2384
|
+
});
|
|
2385
|
+
};
|
|
2386
|
+
// Get Tasks | Markers Location Co Ordinates, in task order
|
|
2299
2387
|
OpenStreetMapsService.prototype.getMarkersLocation = function (myMarker, tasks) {
|
|
2300
2388
|
return __awaiter(this, void 0, void 0, function () {
|
|
2389
|
+
var located;
|
|
2301
2390
|
var _this = this;
|
|
2302
|
-
return __generator(this, function (
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
return [2 /*return*/];
|
|
2321
|
-
}
|
|
2322
|
-
});
|
|
2323
|
-
}); });
|
|
2324
|
-
return [4 /*yield*/, Promise.all(promises)];
|
|
2325
|
-
case 1:
|
|
2326
|
-
_q.sent();
|
|
2327
|
-
resolve(markers);
|
|
2328
|
-
return [2 /*return*/];
|
|
2329
|
-
}
|
|
2330
|
-
});
|
|
2331
|
-
}); })];
|
|
2391
|
+
return __generator(this, function (_l) {
|
|
2392
|
+
switch (_l.label) {
|
|
2393
|
+
case 0: return [4 /*yield*/, Promise.all(tasks.map(function (task) { return __awaiter(_this, void 0, void 0, function () {
|
|
2394
|
+
var _l, _m, _o;
|
|
2395
|
+
return __generator(this, function (_p) {
|
|
2396
|
+
switch (_p.label) {
|
|
2397
|
+
case 0:
|
|
2398
|
+
_m = (_l = Object).assign;
|
|
2399
|
+
_o = [Object.assign({}, task)];
|
|
2400
|
+
return [4 /*yield*/, this.getLocation(task)];
|
|
2401
|
+
case 1: return [2 /*return*/, (_m.apply(_l, _o.concat([(_p.sent())])))];
|
|
2402
|
+
}
|
|
2403
|
+
});
|
|
2404
|
+
}); }))];
|
|
2405
|
+
case 1:
|
|
2406
|
+
located = _l.sent();
|
|
2407
|
+
return [2 /*return*/, __spreadArray([myMarker], __read(located))];
|
|
2408
|
+
}
|
|
2332
2409
|
});
|
|
2333
2410
|
});
|
|
2334
2411
|
};
|
|
2335
2412
|
// To Initialize Open Street Map
|
|
2336
2413
|
OpenStreetMapsService.prototype.initializeMap = function () {
|
|
2337
2414
|
return __awaiter(this, void 0, void 0, function () {
|
|
2338
|
-
var
|
|
2339
|
-
return __generator(this, function (
|
|
2340
|
-
switch (
|
|
2415
|
+
var _l;
|
|
2416
|
+
return __generator(this, function (_m) {
|
|
2417
|
+
switch (_m.label) {
|
|
2341
2418
|
case 0:
|
|
2342
2419
|
console.log("Running Init Open Street Maps");
|
|
2343
|
-
|
|
2420
|
+
_l = this;
|
|
2344
2421
|
return [4 /*yield*/, this.getPosition()];
|
|
2345
2422
|
case 1:
|
|
2346
|
-
|
|
2423
|
+
_l.myPosition = _m.sent();
|
|
2347
2424
|
this.map = L__namespace.map("map", {
|
|
2348
2425
|
center: [this.myPosition.lat, this.myPosition.lng],
|
|
2349
2426
|
zoom: 11
|
|
@@ -2355,8 +2432,11 @@
|
|
|
2355
2432
|
});
|
|
2356
2433
|
};
|
|
2357
2434
|
// To Add Open Street Marker in Map
|
|
2358
|
-
OpenStreetMapsService.prototype.addMarker = function (
|
|
2359
|
-
var lat =
|
|
2435
|
+
OpenStreetMapsService.prototype.addMarker = function (_l) {
|
|
2436
|
+
var lat = _l.lat, lng = _l.lng, title = _l.title, color = _l.color;
|
|
2437
|
+
if (!this.markersLayer) {
|
|
2438
|
+
this.markersLayer = L__namespace.layerGroup().addTo(this.map);
|
|
2439
|
+
}
|
|
2360
2440
|
L__namespace.marker([lat, lng], {
|
|
2361
2441
|
icon: L__namespace.icon({
|
|
2362
2442
|
iconUrl: color == "red"
|
|
@@ -2364,63 +2444,100 @@
|
|
|
2364
2444
|
: "https://kwikid.s3.ap-south-1.amazonaws.com/CONFIG/USER/assets/map-marker-1.png"
|
|
2365
2445
|
})
|
|
2366
2446
|
})
|
|
2367
|
-
.addTo(this.
|
|
2368
|
-
.bindPopup(title);
|
|
2447
|
+
.addTo(this.markersLayer)
|
|
2448
|
+
.bindPopup(String(title));
|
|
2449
|
+
};
|
|
2450
|
+
// Remove markers and routes from a previous plot
|
|
2451
|
+
OpenStreetMapsService.prototype.clearMap = function () {
|
|
2452
|
+
if (this.markersLayer) {
|
|
2453
|
+
this.markersLayer.clearLayers();
|
|
2454
|
+
}
|
|
2455
|
+
if (this.allTasksRoutes) {
|
|
2456
|
+
this.map.removeControl(this.allTasksRoutes);
|
|
2457
|
+
this.allTasksRoutes = undefined;
|
|
2458
|
+
}
|
|
2459
|
+
if (this.selectedTaskRoutes) {
|
|
2460
|
+
this.map.removeControl(this.selectedTaskRoutes);
|
|
2461
|
+
this.selectedTaskRoutes = undefined;
|
|
2462
|
+
}
|
|
2369
2463
|
};
|
|
2370
2464
|
// To Plot Open Street Directions for All Tasks
|
|
2371
2465
|
OpenStreetMapsService.prototype.plotDirectionsForAllTasks = function (tasks) {
|
|
2466
|
+
if (!this.map || !this.myPosition) {
|
|
2467
|
+
return Promise.resolve(tasks);
|
|
2468
|
+
}
|
|
2469
|
+
this.plotRunId += 1;
|
|
2470
|
+
var plot = this.plotTasks(tasks, this.plotRunId);
|
|
2471
|
+
this.latestPlot = plot;
|
|
2472
|
+
return plot;
|
|
2473
|
+
};
|
|
2474
|
+
OpenStreetMapsService.prototype.plotTasks = function (tasks, runId) {
|
|
2475
|
+
var _a;
|
|
2372
2476
|
return __awaiter(this, void 0, void 0, function () {
|
|
2373
|
-
var myMarker,
|
|
2477
|
+
var myMarker, markers, located, notLocated, optimizedRoute, styles, ordered, selectedId, selected;
|
|
2374
2478
|
var _this = this;
|
|
2375
|
-
return __generator(this, function (
|
|
2376
|
-
switch (
|
|
2479
|
+
return __generator(this, function (_l) {
|
|
2480
|
+
switch (_l.label) {
|
|
2377
2481
|
case 0:
|
|
2378
|
-
if (!this.map) return [3 /*break*/, 2];
|
|
2379
|
-
this.allMarkers = [];
|
|
2380
2482
|
myMarker = {
|
|
2381
2483
|
lat: this.myPosition.lat,
|
|
2382
2484
|
lng: this.myPosition.lng,
|
|
2383
|
-
title: 0,
|
|
2485
|
+
title: "0",
|
|
2384
2486
|
color: "red"
|
|
2385
2487
|
};
|
|
2386
|
-
this.addMarker(myMarker);
|
|
2387
|
-
this.allMarkers.push(myMarker);
|
|
2388
|
-
// Create Markers for all Tasks
|
|
2389
|
-
_q = this;
|
|
2390
2488
|
return [4 /*yield*/, this.getMarkersLocation(myMarker, tasks)];
|
|
2391
2489
|
case 1:
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
|
|
2398
|
-
this.
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
|
|
2405
|
-
|
|
2406
|
-
}
|
|
2490
|
+
markers = _l.sent();
|
|
2491
|
+
if (runId !== this.plotRunId) {
|
|
2492
|
+
// A newer plot owns the map; give callers its result instead of stale tasks
|
|
2493
|
+
return [2 /*return*/, this.latestPlot];
|
|
2494
|
+
}
|
|
2495
|
+
this.clearMap();
|
|
2496
|
+
this.addMarker(myMarker);
|
|
2497
|
+
located = markers.slice(1).filter(function (marker) { return marker.isValidLocation; });
|
|
2498
|
+
notLocated = markers
|
|
2499
|
+
.slice(1)
|
|
2500
|
+
.filter(function (marker) { return !marker.isValidLocation; });
|
|
2501
|
+
optimizedRoute = nearestNeighborAlgorithm(myMarker, located);
|
|
2502
|
+
optimizedRoute.slice(1).forEach(function (marker, index) {
|
|
2503
|
+
marker.title = String(index + 1);
|
|
2407
2504
|
});
|
|
2408
|
-
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
2413
|
-
|
|
2505
|
+
this.allMarkers = optimizedRoute;
|
|
2506
|
+
// Plot Markers for located Tasks
|
|
2507
|
+
located.forEach(function (marker) { return _this.addMarker(marker); });
|
|
2508
|
+
// Set Routes for all located Tasks
|
|
2509
|
+
if (located.length > 0) {
|
|
2510
|
+
styles = [
|
|
2511
|
+
{ color: "blue", opacity: 1, weight: 8 },
|
|
2512
|
+
{ color: "white", opacity: 0.6, weight: 12 }
|
|
2513
|
+
];
|
|
2514
|
+
this.allTasksRoutes = this.setRoutes(optimizedRoute, styles);
|
|
2515
|
+
}
|
|
2414
2516
|
this.fitMapBounds();
|
|
2415
|
-
|
|
2416
|
-
|
|
2517
|
+
ordered = __spreadArray(__spreadArray([], __read(optimizedRoute.slice(1))), __read(notLocated));
|
|
2518
|
+
selectedId = (_a = this.agentService.currentTaskDetails) === null || _a === void 0 ? void 0 : _a.session_id;
|
|
2519
|
+
selected = selectedId
|
|
2520
|
+
? ordered.find(function (task) { return task.session_id === selectedId; })
|
|
2521
|
+
: undefined;
|
|
2522
|
+
if (selected === null || selected === void 0 ? void 0 : selected.isValidLocation) {
|
|
2523
|
+
this.agentService.currentTaskDetails = selected;
|
|
2524
|
+
this.plotDirectionsForSelectedTask(selected);
|
|
2525
|
+
}
|
|
2526
|
+
else {
|
|
2527
|
+
// Leave currentTaskDetails alone: it also drives the details panel
|
|
2528
|
+
this.selectedTaskDistanceAndTime = undefined;
|
|
2529
|
+
}
|
|
2530
|
+
return [2 /*return*/, ordered];
|
|
2417
2531
|
}
|
|
2418
2532
|
});
|
|
2419
2533
|
});
|
|
2420
2534
|
};
|
|
2421
2535
|
// To plot Open Street Direction for selected Task
|
|
2422
2536
|
OpenStreetMapsService.prototype.plotDirectionsForSelectedTask = function (task) {
|
|
2423
|
-
if (
|
|
2537
|
+
if (!this.map) {
|
|
2538
|
+
return;
|
|
2539
|
+
}
|
|
2540
|
+
if (task) {
|
|
2424
2541
|
// Remove Previously Selected Task Route
|
|
2425
2542
|
if (this.selectedTaskRoutes) {
|
|
2426
2543
|
this.map.removeControl(this.selectedTaskRoutes);
|
|
@@ -2431,7 +2548,7 @@
|
|
|
2431
2548
|
}
|
|
2432
2549
|
var taskMarker = task;
|
|
2433
2550
|
// If Location is Available in Task Details
|
|
2434
|
-
if (taskMarker
|
|
2551
|
+
if (taskMarker === null || taskMarker === void 0 ? void 0 : taskMarker.isValidLocation) {
|
|
2435
2552
|
var markers = [this.allMarkers[0], taskMarker];
|
|
2436
2553
|
var styles = [
|
|
2437
2554
|
{ color: "green", opacity: 1, weight: 8 },
|
|
@@ -2449,7 +2566,9 @@
|
|
|
2449
2566
|
if (this.selectedTaskRoutes) {
|
|
2450
2567
|
this.map.removeControl(this.selectedTaskRoutes);
|
|
2451
2568
|
}
|
|
2452
|
-
|
|
2569
|
+
if (this.allTasksRoutes) {
|
|
2570
|
+
this.map.addControl(this.allTasksRoutes);
|
|
2571
|
+
}
|
|
2453
2572
|
this.selectedTaskRoutes = undefined;
|
|
2454
2573
|
}
|
|
2455
2574
|
this.fitMapBounds();
|
|
@@ -2460,47 +2579,59 @@
|
|
|
2460
2579
|
};
|
|
2461
2580
|
// Set Distance & Time of Selected Task
|
|
2462
2581
|
OpenStreetMapsService.prototype.setSelectedTaskDistanceAndTime = function () {
|
|
2582
|
+
var _this = this;
|
|
2583
|
+
this.selectedTaskDistanceAndTime = undefined;
|
|
2463
2584
|
this.selectedTaskRoutes.on("routesfound", function (e) {
|
|
2464
2585
|
var routes = e.routes;
|
|
2465
2586
|
var summary = routes[0].summary;
|
|
2466
|
-
var
|
|
2467
|
-
var
|
|
2468
|
-
|
|
2587
|
+
var METRES_PER_KM = 1000;
|
|
2588
|
+
var SECONDS_PER_MINUTE = 60;
|
|
2589
|
+
var distance = Math.round((summary.totalDistance / METRES_PER_KM) * 10) / 10; // eslint-disable-line no-magic-numbers
|
|
2590
|
+
var time = Math.round(summary.totalTime / SECONDS_PER_MINUTE);
|
|
2591
|
+
_this.selectedTaskDistanceAndTime = {
|
|
2469
2592
|
distance: distance,
|
|
2470
2593
|
time: time
|
|
2471
2594
|
};
|
|
2472
2595
|
});
|
|
2473
2596
|
};
|
|
2474
|
-
// To sort Open Street Maps Task as per nearest distance
|
|
2475
|
-
OpenStreetMapsService.prototype.sortTasksAsPerDistance = function (order, tasks, isMarker) {
|
|
2476
|
-
var sortedTasks = [];
|
|
2477
|
-
for (var i = 0; i < tasks.length; i++) {
|
|
2478
|
-
var title = isMarker ? order[i].title : order[i].title - 1;
|
|
2479
|
-
var task = tasks[title];
|
|
2480
|
-
sortedTasks.push(task);
|
|
2481
|
-
}
|
|
2482
|
-
return sortedTasks;
|
|
2483
|
-
};
|
|
2484
2597
|
// To set Open Street routes in the maps
|
|
2485
2598
|
OpenStreetMapsService.prototype.setRoutes = function (markers, styles) {
|
|
2486
2599
|
return L__namespace.Routing.control({
|
|
2487
|
-
waypoints: markers,
|
|
2600
|
+
waypoints: markers.map(function (marker) { return L__namespace.latLng(marker.lat, marker.lng); }),
|
|
2488
2601
|
lineOptions: {
|
|
2489
2602
|
styles: styles
|
|
2490
2603
|
},
|
|
2491
2604
|
createMarker: function () {
|
|
2492
2605
|
return null;
|
|
2493
2606
|
},
|
|
2494
|
-
|
|
2607
|
+
addWaypoints: false,
|
|
2608
|
+
fitSelectedRoutes: false,
|
|
2609
|
+
show: false
|
|
2495
2610
|
}).addTo(this.map);
|
|
2496
2611
|
};
|
|
2497
2612
|
// To set Open Street view point on the map
|
|
2498
2613
|
OpenStreetMapsService.prototype.fitMapBounds = function () {
|
|
2499
|
-
var
|
|
2500
|
-
this.
|
|
2614
|
+
var _a;
|
|
2615
|
+
var markerLatLngs = ((_a = this.allMarkers) !== null && _a !== void 0 ? _a : [])
|
|
2616
|
+
.filter(function (marker) { return marker && marker.lat !== null && marker.lng !== null; })
|
|
2617
|
+
.map(function (marker) { return L__namespace.latLng(marker.lat, marker.lng); });
|
|
2618
|
+
var PADDING_PX = 40;
|
|
2619
|
+
var SINGLE_MARKER_ZOOM = 13;
|
|
2620
|
+
if (markerLatLngs.length > 1) {
|
|
2621
|
+
this.map.fitBounds(L__namespace.latLngBounds(markerLatLngs), {
|
|
2622
|
+
padding: [PADDING_PX, PADDING_PX]
|
|
2623
|
+
});
|
|
2624
|
+
}
|
|
2625
|
+
else if (markerLatLngs.length === 1) {
|
|
2626
|
+
this.map.setView(markerLatLngs[0], SINGLE_MARKER_ZOOM);
|
|
2627
|
+
}
|
|
2501
2628
|
};
|
|
2502
2629
|
return OpenStreetMapsService;
|
|
2503
2630
|
}());
|
|
2631
|
+
// Nominatim allows at most 1 request per second
|
|
2632
|
+
OpenStreetMapsService.GEOCODE_INTERVAL_MS = 1100; // eslint-disable-line no-magic-numbers
|
|
2633
|
+
// A stalled request must not hold up the queue
|
|
2634
|
+
OpenStreetMapsService.GEOCODE_TIMEOUT_MS = 10000; // eslint-disable-line no-magic-numbers
|
|
2504
2635
|
/** @nocollapse */ OpenStreetMapsService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: OpenStreetMapsService, deps: [{ token: AgentService }, { token: i2__namespace$2.MapDirectionsService }, { token: i3__namespace$2.HttpClient }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
|
|
2505
2636
|
/** @nocollapse */ OpenStreetMapsService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: OpenStreetMapsService, providedIn: "root" });
|
|
2506
2637
|
i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: OpenStreetMapsService, decorators: [{
|