sgerp-frontend-lib 0.1.0 → 0.1.2
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/README.md +1 -1
- package/dist/connection-manager.d.ts +48 -0
- package/dist/connection-manager.d.ts.map +1 -0
- package/dist/connection-manager.js +156 -0
- package/dist/index.js +20 -2
- package/dist/locales/locale-server.d.ts +10 -0
- package/dist/locales/locale-server.d.ts.map +1 -0
- package/dist/locales/locale-server.js +49 -0
- package/dist/locales/locale.d.ts +23 -0
- package/dist/locales/locale.d.ts.map +1 -0
- package/dist/locales/locale.js +145 -0
- package/dist/locales/locale_en.d.ts.map +1 -1
- package/dist/locales/locale_en.js +93 -9
- package/dist/locales/locale_ja.d.ts.map +1 -1
- package/dist/locales/locale_ja.js +93 -9
- package/dist/locales/locale_ms.d.ts.map +1 -1
- package/dist/locales/locale_ms.js +84 -9
- package/dist/locales/useLocalization.d.ts +11 -0
- package/dist/locales/useLocalization.d.ts.map +1 -0
- package/dist/locales/useLocalization.js +64 -0
- package/dist/locales.d.ts +228 -0
- package/dist/locales.d.ts.map +1 -0
- package/dist/locales.js +229 -0
- package/dist/sgerp/api/client.d.ts +45 -0
- package/dist/sgerp/api/client.d.ts.map +1 -0
- package/dist/sgerp/api/client.js +141 -0
- package/dist/sgerp/client.js +341 -0
- package/dist/sgerp/collection.d.ts +391 -0
- package/dist/sgerp/collection.d.ts.map +1 -0
- package/dist/sgerp/collection.js +756 -0
- package/dist/sgerp/collections/account/user.d.ts +8 -0
- package/dist/sgerp/collections/account/user.d.ts.map +1 -0
- package/dist/sgerp/collections/account/user.js +10 -0
- package/dist/sgerp/collections/masstransit/building.d.ts +26 -0
- package/dist/sgerp/collections/masstransit/building.d.ts.map +1 -0
- package/dist/sgerp/collections/masstransit/building.js +53 -0
- package/dist/sgerp/collections/masstransit/transitstop.d.ts +15 -0
- package/dist/sgerp/collections/masstransit/transitstop.d.ts.map +1 -0
- package/dist/sgerp/collections/masstransit/transitstop.js +54 -0
- package/dist/sgerp/collections/masstransit/transitstopset.d.ts +10 -0
- package/dist/sgerp/collections/masstransit/transitstopset.d.ts.map +1 -0
- package/dist/sgerp/collections/masstransit/transitstopset.js +10 -0
- package/dist/sgerp/collections/sharing/organization-project.d.ts +11 -0
- package/dist/sgerp/collections/sharing/organization-project.d.ts.map +1 -0
- package/dist/sgerp/collections/sharing/organization-project.js +13 -0
- package/dist/sgerp/collections/sharing/organization.d.ts +11 -0
- package/dist/sgerp/collections/sharing/organization.d.ts.map +1 -0
- package/dist/sgerp/collections/sharing/organization.js +13 -0
- package/dist/sgerp/collections/sharing/pricing.d.ts +18 -0
- package/dist/sgerp/collections/sharing/pricing.d.ts.map +1 -0
- package/dist/sgerp/collections/sharing/pricing.js +23 -0
- package/dist/sgerp/collections/sharing/project-member.d.ts +8 -0
- package/dist/sgerp/collections/sharing/project-member.d.ts.map +1 -0
- package/dist/sgerp/collections/sharing/project-member.js +10 -0
- package/dist/sgerp/collections/sharing/project.d.ts +8 -0
- package/dist/sgerp/collections/sharing/project.d.ts.map +1 -0
- package/dist/sgerp/collections/sharing/project.js +10 -0
- package/dist/sgerp/collections/simulation/booking.d.ts +11 -0
- package/dist/sgerp/collections/simulation/booking.d.ts.map +1 -0
- package/dist/sgerp/collections/simulation/booking.js +13 -0
- package/dist/sgerp/collections/simulation/dataset.d.ts +14 -0
- package/dist/sgerp/collections/simulation/dataset.d.ts.map +1 -0
- package/dist/sgerp/collections/simulation/dataset.js +17 -0
- package/dist/sgerp/collections/simulation/driver.d.ts +12 -0
- package/dist/sgerp/collections/simulation/driver.d.ts.map +1 -0
- package/dist/sgerp/collections/simulation/driver.js +40 -0
- package/dist/sgerp/collections/simulation/geofence.d.ts +24 -0
- package/dist/sgerp/collections/simulation/geofence.d.ts.map +1 -0
- package/dist/sgerp/collections/simulation/geofence.js +66 -0
- package/dist/sgerp/collections/simulation/mapboxtoken.d.ts +18 -0
- package/dist/sgerp/collections/simulation/mapboxtoken.d.ts.map +1 -0
- package/dist/sgerp/collections/simulation/mapboxtoken.js +24 -0
- package/dist/sgerp/collections/simulation/node.js +13 -0
- package/dist/sgerp/collections/simulation/operationslocation.d.ts +28 -0
- package/dist/sgerp/collections/simulation/operationslocation.d.ts.map +1 -0
- package/dist/sgerp/collections/simulation/operationslocation.js +64 -0
- package/dist/sgerp/collections/simulation/operationslocationgroup.d.ts +12 -0
- package/dist/sgerp/collections/simulation/operationslocationgroup.d.ts.map +1 -0
- package/dist/sgerp/collections/simulation/operationslocationgroup.js +24 -0
- package/dist/sgerp/collections/simulation/routingprofile.d.ts +10 -0
- package/dist/sgerp/collections/simulation/routingprofile.d.ts.map +1 -0
- package/dist/sgerp/collections/simulation/routingprofile.js +10 -0
- package/dist/sgerp/collections/simulation/simulation.d.ts +12 -0
- package/dist/sgerp/collections/simulation/simulation.d.ts.map +1 -0
- package/dist/sgerp/collections/simulation/simulation.js +35 -0
- package/dist/sgerp/collections/simulation/simulationprocessor.d.ts +19 -0
- package/dist/sgerp/collections/simulation/simulationprocessor.d.ts.map +1 -0
- package/dist/sgerp/collections/simulation/simulationprocessor.js +27 -0
- package/dist/sgerp/collections/simulation/vehicle.js +13 -0
- package/dist/sgerp/collections/simulation/vehicletype.d.ts +11 -0
- package/dist/sgerp/collections/simulation/vehicletype.d.ts.map +1 -0
- package/dist/sgerp/collections/simulation/vehicletype.js +13 -0
- package/dist/sgerp/collections/sms_notify/smsscheduled.d.ts +11 -0
- package/dist/sgerp/collections/sms_notify/smsscheduled.d.ts.map +1 -0
- package/dist/sgerp/collections/sms_notify/smsscheduled.js +13 -0
- package/dist/sgerp/collections/transportation/passenger.d.ts +8 -0
- package/dist/sgerp/collections/transportation/passenger.d.ts.map +1 -0
- package/dist/sgerp/collections/transportation/passenger.js +10 -0
- package/dist/sgerp/collections/transportation/ticket.d.ts +11 -0
- package/dist/sgerp/collections/transportation/ticket.d.ts.map +1 -0
- package/dist/sgerp/collections/transportation/ticket.js +13 -0
- package/dist/sgerp/collections/transportation/transaction.d.ts +11 -0
- package/dist/sgerp/collections/transportation/transaction.d.ts.map +1 -0
- package/dist/sgerp/collections/transportation/transaction.js +13 -0
- package/dist/sgerp/constants/bulkoperations-enums.d.ts +71 -0
- package/dist/sgerp/constants/bulkoperations-enums.d.ts.map +1 -0
- package/dist/sgerp/constants/bulkoperations-enums.js +99 -0
- package/dist/sgerp/constants/messages-enums.d.ts +47 -0
- package/dist/sgerp/constants/messages-enums.d.ts.map +1 -0
- package/dist/sgerp/constants/messages-enums.js +67 -0
- package/dist/sgerp/constants/scheduling-enums.d.ts +42 -0
- package/dist/sgerp/constants/scheduling-enums.d.ts.map +1 -0
- package/dist/sgerp/constants/scheduling-enums.js +61 -0
- package/dist/sgerp/constants/simulation-enums.d.ts +93 -0
- package/dist/sgerp/constants/simulation-enums.d.ts.map +1 -0
- package/dist/sgerp/constants/simulation-enums.js +147 -0
- package/dist/sgerp/constants/solver-strategies.d.ts +75 -0
- package/dist/sgerp/constants/solver-strategies.d.ts.map +1 -0
- package/dist/sgerp/constants/solver-strategies.js +26 -0
- package/dist/sgerp/context/sgerp-context.js +134 -0
- package/dist/sgerp/domains.d.ts +47 -0
- package/dist/sgerp/domains.d.ts.map +1 -0
- package/dist/sgerp/domains.js +45 -0
- package/dist/sgerp/hooks/use-collection.js +122 -0
- package/dist/sgerp/hooks/use-live-updates.js +16 -13
- package/dist/sgerp/index.js +153 -0
- package/dist/sgerp/map-states/operations-location-state.d.ts +12 -0
- package/dist/sgerp/map-states/operations-location-state.d.ts.map +1 -0
- package/dist/sgerp/map-states/operations-location-state.js +86 -0
- package/dist/sgerp/routing/index.d.ts +51 -0
- package/dist/sgerp/routing/index.d.ts.map +1 -0
- package/dist/sgerp/routing/index.js +373 -0
- package/dist/sgerp/simulation-logic/fetchUtils.js +226 -0
- package/dist/sgerp/simulation-logic/index.js +27 -7
- package/dist/sgerp/simulation-logic/manualEditUtils.js +69 -0
- package/dist/sgerp/simulation-logic/mapUtils.js +58 -0
- package/dist/sgerp/simulation-logic/optimisticUpdateUtils.js +8 -5
- package/dist/sgerp/simulation-logic/referenceUtils.js +110 -0
- package/dist/sgerp/simulation-logic/routeCalculationUtils.js +43 -0
- package/dist/sgerp/simulation-logic/timeShiftUtils.js +63 -0
- package/dist/sgerp/types/account/user.d.ts +38 -0
- package/dist/sgerp/types/account/user.d.ts.map +1 -0
- package/dist/sgerp/types/account/user.js +2 -0
- package/dist/sgerp/types/bulkoperations/index.d.ts +37 -0
- package/dist/sgerp/types/bulkoperations/index.d.ts.map +1 -0
- package/dist/sgerp/types/bulkoperations/index.js +35 -0
- package/dist/sgerp/types/bulkoperations/vehicle-upload.d.ts +335 -0
- package/dist/sgerp/types/bulkoperations/vehicle-upload.d.ts.map +1 -0
- package/dist/sgerp/types/bulkoperations/vehicle-upload.js +49 -0
- package/dist/sgerp/types/config.d.ts +25 -0
- package/dist/sgerp/types/config.d.ts.map +1 -0
- package/dist/sgerp/types/config.js +2 -0
- package/dist/sgerp/types/geojson.d.ts +45 -0
- package/dist/sgerp/types/geojson.d.ts.map +1 -0
- package/dist/sgerp/types/geojson.js +6 -0
- package/dist/sgerp/types/map.d.ts +24 -0
- package/dist/sgerp/types/map.d.ts.map +1 -0
- package/dist/sgerp/types/map.js +2 -0
- package/dist/sgerp/types/masstransit/building.d.ts +24 -0
- package/dist/sgerp/types/masstransit/building.d.ts.map +1 -0
- package/dist/sgerp/types/masstransit/building.js +2 -0
- package/dist/sgerp/types/masstransit/transitstop.d.ts +35 -0
- package/dist/sgerp/types/masstransit/transitstop.d.ts.map +1 -0
- package/dist/sgerp/types/masstransit/transitstop.js +2 -0
- package/dist/sgerp/types/masstransit/transitstopset.d.ts +14 -0
- package/dist/sgerp/types/masstransit/transitstopset.d.ts.map +1 -0
- package/dist/sgerp/types/masstransit/transitstopset.js +2 -0
- package/dist/sgerp/types/sharing/organization-project.d.ts +14 -0
- package/dist/sgerp/types/sharing/organization-project.d.ts.map +1 -0
- package/dist/sgerp/types/sharing/organization-project.js +2 -0
- package/dist/sgerp/types/sharing/organization.d.ts +14 -0
- package/dist/sgerp/types/sharing/organization.d.ts.map +1 -0
- package/dist/sgerp/types/sharing/organization.js +2 -0
- package/dist/sgerp/types/sharing/pricing.d.ts +98 -0
- package/dist/sgerp/types/sharing/pricing.d.ts.map +1 -0
- package/dist/sgerp/types/sharing/pricing.js +2 -0
- package/dist/sgerp/types/sharing/project-member.d.ts +15 -0
- package/dist/sgerp/types/sharing/project-member.d.ts.map +1 -0
- package/dist/sgerp/types/sharing/project-member.js +2 -0
- package/dist/sgerp/types/sharing/project.d.ts +16 -0
- package/dist/sgerp/types/sharing/project.d.ts.map +1 -0
- package/dist/sgerp/types/sharing/project.js +2 -0
- package/dist/sgerp/types/simulation/booking.d.ts +128 -0
- package/dist/sgerp/types/simulation/booking.d.ts.map +1 -0
- package/dist/sgerp/types/simulation/booking.js +24 -0
- package/dist/sgerp/types/simulation/calculation-params.d.ts +20 -0
- package/dist/sgerp/types/simulation/calculation-params.d.ts.map +1 -0
- package/dist/sgerp/types/simulation/calculation-params.js +2 -0
- package/dist/sgerp/types/simulation/dataset.d.ts +16 -0
- package/dist/sgerp/types/simulation/dataset.d.ts.map +1 -0
- package/dist/sgerp/types/simulation/dataset.js +2 -0
- package/dist/sgerp/types/simulation/driver.d.ts +19 -0
- package/dist/sgerp/types/simulation/driver.d.ts.map +1 -0
- package/dist/sgerp/types/simulation/driver.js +2 -0
- package/dist/sgerp/types/simulation/geofence.d.ts +19 -0
- package/dist/sgerp/types/simulation/geofence.d.ts.map +1 -0
- package/dist/sgerp/types/simulation/geofence.js +2 -0
- package/dist/sgerp/types/simulation/logistics-api-settings.d.ts +98 -0
- package/dist/sgerp/types/simulation/logistics-api-settings.d.ts.map +1 -0
- package/dist/sgerp/types/simulation/logistics-api-settings.js +104 -0
- package/dist/sgerp/types/simulation/mapboxtoken.d.ts +13 -0
- package/dist/sgerp/types/simulation/mapboxtoken.d.ts.map +1 -0
- package/dist/sgerp/types/simulation/mapboxtoken.js +2 -0
- package/dist/sgerp/types/simulation/node.js +5 -2
- package/dist/sgerp/types/simulation/operationslocation.d.ts +40 -0
- package/dist/sgerp/types/simulation/operationslocation.d.ts.map +1 -0
- package/dist/sgerp/types/simulation/operationslocation.js +2 -0
- package/dist/sgerp/types/simulation/operationslocationgroup.d.ts +11 -0
- package/dist/sgerp/types/simulation/operationslocationgroup.d.ts.map +1 -0
- package/dist/sgerp/types/simulation/operationslocationgroup.js +2 -0
- package/dist/sgerp/types/simulation/pricing.d.ts +171 -0
- package/dist/sgerp/types/simulation/pricing.d.ts.map +1 -0
- package/dist/sgerp/types/simulation/pricing.js +2 -0
- package/dist/sgerp/types/simulation/route-cost-modification.d.ts +35 -0
- package/dist/sgerp/types/simulation/route-cost-modification.d.ts.map +1 -0
- package/dist/sgerp/types/simulation/route-cost-modification.js +5 -0
- package/dist/sgerp/types/simulation/routing-engine-settings.d.ts +42 -0
- package/dist/sgerp/types/simulation/routing-engine-settings.d.ts.map +1 -0
- package/dist/sgerp/types/simulation/routing-engine-settings.js +35 -0
- package/dist/sgerp/types/simulation/routingprofile.d.ts +32 -0
- package/dist/sgerp/types/simulation/routingprofile.d.ts.map +1 -0
- package/dist/sgerp/types/simulation/routingprofile.js +37 -0
- package/dist/sgerp/types/simulation/simulation.d.ts +120 -0
- package/dist/sgerp/types/simulation/simulation.d.ts.map +1 -0
- package/dist/sgerp/types/simulation/simulation.js +2 -0
- package/dist/sgerp/types/simulation/simulationprocessor.d.ts +31 -0
- package/dist/sgerp/types/simulation/simulationprocessor.d.ts.map +1 -0
- package/dist/sgerp/types/simulation/simulationprocessor.js +2 -0
- package/dist/sgerp/types/simulation/vehicle.js +2 -1
- package/dist/sgerp/types/simulation/vehicletype.d.ts +33 -0
- package/dist/sgerp/types/simulation/vehicletype.d.ts.map +1 -0
- package/dist/sgerp/types/simulation/vehicletype.js +2 -0
- package/dist/sgerp/types/sms_notify/smsscheduled.d.ts +36 -0
- package/dist/sgerp/types/sms_notify/smsscheduled.d.ts.map +1 -0
- package/dist/sgerp/types/sms_notify/smsscheduled.js +6 -0
- package/dist/sgerp/types/transportation/passenger.d.ts +49 -0
- package/dist/sgerp/types/transportation/passenger.d.ts.map +1 -0
- package/dist/sgerp/types/transportation/passenger.js +13 -0
- package/dist/sgerp/types/transportation/ticket.d.ts +31 -0
- package/dist/sgerp/types/transportation/ticket.d.ts.map +1 -0
- package/dist/sgerp/types/transportation/ticket.js +2 -0
- package/dist/sgerp/types/transportation/transaction.d.ts +71 -0
- package/dist/sgerp/types/transportation/transaction.d.ts.map +1 -0
- package/dist/sgerp/types/transportation/transaction.js +54 -0
- package/dist/sgerp/utils/bookingPayload.d.ts +80 -0
- package/dist/sgerp/utils/bookingPayload.d.ts.map +1 -0
- package/dist/sgerp/utils/bookingPayload.js +44 -0
- package/dist/sgerp/utils/color.d.ts +30 -0
- package/dist/sgerp/utils/color.d.ts.map +1 -0
- package/dist/sgerp/utils/color.js +117 -0
- package/dist/sgerp/utils/enum-helpers.d.ts +41 -0
- package/dist/sgerp/utils/enum-helpers.d.ts.map +1 -0
- package/dist/sgerp/utils/enum-helpers.js +54 -0
- package/dist/sgerp/utils/routeUtils.js +171 -0
- package/package.json +1 -1
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OperationsLocationByProjectMapState = exports.OperationsLocationMapState = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Default map state for OperationsLocation visualization
|
|
6
|
+
* Displays locations as blue circles with hover interactions
|
|
7
|
+
*/
|
|
8
|
+
exports.OperationsLocationMapState = {
|
|
9
|
+
mapBoundingBox: [[-180, -90], [180, 90]],
|
|
10
|
+
mapLayers: {
|
|
11
|
+
locations: {
|
|
12
|
+
source: {
|
|
13
|
+
type: 'geojson',
|
|
14
|
+
data: {
|
|
15
|
+
type: 'FeatureCollection',
|
|
16
|
+
features: [], // Initially empty, will be populated with toGeoJSON()
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
layers: [
|
|
20
|
+
{
|
|
21
|
+
id: 'operations-locations',
|
|
22
|
+
type: 'circle',
|
|
23
|
+
source: 'locations',
|
|
24
|
+
paint: {
|
|
25
|
+
'circle-radius': 8,
|
|
26
|
+
'circle-color': '#3b82f6', // Blue
|
|
27
|
+
'circle-stroke-width': 2,
|
|
28
|
+
'circle-stroke-color': '#ffffff',
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
],
|
|
32
|
+
interactions: [
|
|
33
|
+
{
|
|
34
|
+
layer_id: 'operations-locations',
|
|
35
|
+
interaction_type: 'hover',
|
|
36
|
+
properties: ['name', 'code', 'address', 'postal_code'],
|
|
37
|
+
},
|
|
38
|
+
],
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Map state with color coding by project
|
|
44
|
+
* Uses project_id to color code locations
|
|
45
|
+
*/
|
|
46
|
+
exports.OperationsLocationByProjectMapState = {
|
|
47
|
+
mapBoundingBox: [[-180, -90], [180, 90]],
|
|
48
|
+
mapLayers: {
|
|
49
|
+
locations: {
|
|
50
|
+
source: {
|
|
51
|
+
type: 'geojson',
|
|
52
|
+
data: {
|
|
53
|
+
type: 'FeatureCollection',
|
|
54
|
+
features: [],
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
layers: [
|
|
58
|
+
{
|
|
59
|
+
id: 'operations-locations',
|
|
60
|
+
type: 'circle',
|
|
61
|
+
source: 'locations',
|
|
62
|
+
paint: {
|
|
63
|
+
'circle-radius': 8,
|
|
64
|
+
'circle-color': [
|
|
65
|
+
'match',
|
|
66
|
+
['get', 'project_id'],
|
|
67
|
+
759, '#3b82f6', // Blue for project 759
|
|
68
|
+
760, '#ef4444', // Red for project 760
|
|
69
|
+
761, '#10b981', // Green for project 761
|
|
70
|
+
'#94a3b8', // Default gray
|
|
71
|
+
],
|
|
72
|
+
'circle-stroke-width': 2,
|
|
73
|
+
'circle-stroke-color': '#ffffff',
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
],
|
|
77
|
+
interactions: [
|
|
78
|
+
{
|
|
79
|
+
layer_id: 'operations-locations',
|
|
80
|
+
interaction_type: 'hover',
|
|
81
|
+
properties: ['name', 'code', 'project_id'],
|
|
82
|
+
},
|
|
83
|
+
],
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
interface Coordinates {
|
|
2
|
+
type: 'LineString';
|
|
3
|
+
coordinates: number[][];
|
|
4
|
+
}
|
|
5
|
+
export declare class Step {
|
|
6
|
+
key: string;
|
|
7
|
+
feature: Coordinates;
|
|
8
|
+
duration: number;
|
|
9
|
+
distance: number;
|
|
10
|
+
constructor(key: string, coordinates: number[][], duration: number, distance: number);
|
|
11
|
+
}
|
|
12
|
+
export declare class Leg {
|
|
13
|
+
key: string;
|
|
14
|
+
start: number[];
|
|
15
|
+
end: number[];
|
|
16
|
+
steps: Step[];
|
|
17
|
+
duration: number;
|
|
18
|
+
distance: number;
|
|
19
|
+
feature: Coordinates;
|
|
20
|
+
constructor(key: string, start: number[], end: number[], steps: Step[], duration: number, distance: number);
|
|
21
|
+
}
|
|
22
|
+
export declare function airLeg(coordsFrom: number[], coordsTo: number[]): Leg;
|
|
23
|
+
export declare class Route {
|
|
24
|
+
legs: Leg[];
|
|
25
|
+
distance: number;
|
|
26
|
+
feature: Coordinates;
|
|
27
|
+
constructor(legs: Leg[], coordinates: number[][]);
|
|
28
|
+
}
|
|
29
|
+
interface RoutingSettings {
|
|
30
|
+
continue_straight?: boolean;
|
|
31
|
+
speed?: number;
|
|
32
|
+
}
|
|
33
|
+
type RouteCallback = (result: {
|
|
34
|
+
osrmRoute: Route;
|
|
35
|
+
} | undefined, status: 'ok' | 'error', message?: string) => void;
|
|
36
|
+
export declare class RoutingEngine {
|
|
37
|
+
routing_engine_name: string;
|
|
38
|
+
default_backend: string;
|
|
39
|
+
settings: RoutingSettings | null;
|
|
40
|
+
useAirDistance: boolean;
|
|
41
|
+
url: string;
|
|
42
|
+
road_network: string;
|
|
43
|
+
key: string;
|
|
44
|
+
requestCache: Record<string, unknown>;
|
|
45
|
+
constructor(routing_engine_name: string, url: string, road_network: string, key: string, default_backend?: string, settings?: RoutingSettings | null);
|
|
46
|
+
getUrl(): string;
|
|
47
|
+
route(coords: number[][], curb: boolean, callback: RouteCallback, airDistanceOnly?: boolean): Promise<void>;
|
|
48
|
+
haversineDistance(coords1: number[], coords2: number[]): number;
|
|
49
|
+
}
|
|
50
|
+
export {};
|
|
51
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../sgerplib/sgerp/routing/index.ts"],"names":[],"mappings":"AAIA,UAAU,WAAW;IACnB,IAAI,EAAE,YAAY,CAAC;IACnB,WAAW,EAAE,MAAM,EAAE,EAAE,CAAC;CACzB;AAED,qBAAa,IAAI;IACf,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,WAAW,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;gBAEL,GAAG,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM;CASrF;AAED,qBAAa,GAAG;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,GAAG,EAAE,MAAM,EAAE,CAAC;IACd,KAAK,EAAE,IAAI,EAAE,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,WAAW,CAAC;gBAGnB,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,MAAM,EAAE,EACf,GAAG,EAAE,MAAM,EAAE,EACb,KAAK,EAAE,IAAI,EAAE,EACb,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM;CAoBnB;AAED,wBAAgB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,GAAG,CAUpE;AAED,qBAAa,KAAK;IAChB,IAAI,EAAE,GAAG,EAAE,CAAC;IACZ,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,WAAW,CAAC;gBAET,IAAI,EAAE,GAAG,EAAE,EAAE,WAAW,EAAE,MAAM,EAAE,EAAE;CAYjD;AAmKD,UAAU,eAAe;IACvB,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,KAAK,aAAa,GAAG,CACnB,MAAM,EAAE;IAAE,SAAS,EAAE,KAAK,CAAA;CAAE,GAAG,SAAS,EACxC,MAAM,EAAE,IAAI,GAAG,OAAO,EACtB,OAAO,CAAC,EAAE,MAAM,KACb,IAAI,CAAC;AAEV,qBAAa,aAAa;IACxB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,eAAe,EAAE,MAAM,CAAC;IACxB,QAAQ,EAAE,eAAe,GAAG,IAAI,CAAC;IACjC,cAAc,EAAE,OAAO,CAAC;IACxB,GAAG,EAAE,MAAM,CAAC;IACZ,YAAY,EAAE,MAAM,CAAC;IACrB,GAAG,EAAE,MAAM,CAAC;IACZ,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;gBAGpC,mBAAmB,EAAE,MAAM,EAC3B,GAAG,EAAE,MAAM,EACX,YAAY,EAAE,MAAM,EACpB,GAAG,EAAE,MAAM,EACX,eAAe,GAAE,MAAqB,EACtC,QAAQ,GAAE,eAAe,GAAG,IAAW;IAoDzC,MAAM,IAAI,MAAM;IAiBV,KAAK,CACT,MAAM,EAAE,MAAM,EAAE,EAAE,EAClB,IAAI,EAAE,OAAO,EACb,QAAQ,EAAE,aAAa,EACvB,eAAe,GAAE,OAAe,GAC/B,OAAO,CAAC,IAAI,CAAC;IAqHhB,iBAAiB,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,MAAM;CAgBhE"}
|
|
@@ -0,0 +1,373 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.RoutingEngine = exports.Route = exports.Leg = exports.Step = void 0;
|
|
7
|
+
exports.airLeg = airLeg;
|
|
8
|
+
const polyline_1 = __importDefault(require("@mapbox/polyline"));
|
|
9
|
+
const domains_1 = require("../domains");
|
|
10
|
+
class Step {
|
|
11
|
+
constructor(key, coordinates, duration, distance) {
|
|
12
|
+
this.key = key;
|
|
13
|
+
this.feature = {
|
|
14
|
+
type: 'LineString',
|
|
15
|
+
coordinates: coordinates,
|
|
16
|
+
};
|
|
17
|
+
this.duration = duration;
|
|
18
|
+
this.distance = distance;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.Step = Step;
|
|
22
|
+
class Leg {
|
|
23
|
+
constructor(key, start, end, steps, duration, distance) {
|
|
24
|
+
this.key = key;
|
|
25
|
+
this.start = start;
|
|
26
|
+
this.end = end;
|
|
27
|
+
this.steps = steps;
|
|
28
|
+
this.duration = duration;
|
|
29
|
+
this.distance = distance;
|
|
30
|
+
// Flatten step coordinates into one continuous LineString
|
|
31
|
+
this.feature = {
|
|
32
|
+
type: 'LineString',
|
|
33
|
+
coordinates: steps.reduce((acc, step) => {
|
|
34
|
+
const downsizedCoordinates = step.feature.coordinates.map(([lat, lon]) => [
|
|
35
|
+
parseFloat(lat.toFixed(6)),
|
|
36
|
+
parseFloat(lon.toFixed(6)),
|
|
37
|
+
]);
|
|
38
|
+
return [...acc, ...downsizedCoordinates];
|
|
39
|
+
}, []),
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.Leg = Leg;
|
|
44
|
+
function airLeg(coordsFrom, coordsTo) {
|
|
45
|
+
const legKey = `${coordsFrom.join(',')}-${coordsTo.join(',')}`;
|
|
46
|
+
const step = new Step(legKey, [coordsFrom, coordsTo], 0, // todo
|
|
47
|
+
0 // todo
|
|
48
|
+
);
|
|
49
|
+
return new Leg(legKey, coordsFrom, coordsTo, [step], 0, 0);
|
|
50
|
+
}
|
|
51
|
+
class Route {
|
|
52
|
+
constructor(legs, coordinates) {
|
|
53
|
+
this.legs = legs;
|
|
54
|
+
this.distance = parseInt(legs
|
|
55
|
+
.reduce((totalDistance, currentLeg) => totalDistance + currentLeg.distance, 0)
|
|
56
|
+
.toString());
|
|
57
|
+
this.feature = {
|
|
58
|
+
type: 'LineString',
|
|
59
|
+
coordinates: coordinates,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
exports.Route = Route;
|
|
64
|
+
// IndexedDB utilities
|
|
65
|
+
const dbName = 'MapRoutingCache';
|
|
66
|
+
const storeName = 'routes';
|
|
67
|
+
function openDB() {
|
|
68
|
+
return new Promise((resolve, reject) => {
|
|
69
|
+
const request = indexedDB.open(dbName, 1);
|
|
70
|
+
request.onerror = () => {
|
|
71
|
+
reject(request.error);
|
|
72
|
+
};
|
|
73
|
+
request.onupgradeneeded = (event) => {
|
|
74
|
+
const db = event.target.result;
|
|
75
|
+
// Check if the object store exists, if not create it
|
|
76
|
+
if (!db.objectStoreNames.contains(storeName)) {
|
|
77
|
+
db.createObjectStore(storeName);
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
request.onsuccess = (event) => {
|
|
81
|
+
const db = event.target.result;
|
|
82
|
+
// Verify the object store exists
|
|
83
|
+
if (!db.objectStoreNames.contains(storeName)) {
|
|
84
|
+
// If it doesn't exist, close the database and recreate it with the correct schema
|
|
85
|
+
db.close();
|
|
86
|
+
const deleteRequest = indexedDB.deleteDatabase(dbName);
|
|
87
|
+
deleteRequest.onsuccess = () => {
|
|
88
|
+
// Recursively try opening again, which will trigger onupgradeneeded
|
|
89
|
+
openDB().then(resolve).catch(reject);
|
|
90
|
+
};
|
|
91
|
+
deleteRequest.onerror = () => reject(deleteRequest.error);
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
resolve(db);
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
async function ensureStoreExists() {
|
|
100
|
+
let db;
|
|
101
|
+
try {
|
|
102
|
+
db = await openDB();
|
|
103
|
+
const transaction = db.transaction(storeName, 'readonly');
|
|
104
|
+
await new Promise((resolve, reject) => {
|
|
105
|
+
transaction.oncomplete = () => resolve();
|
|
106
|
+
transaction.onerror = () => reject(transaction.error);
|
|
107
|
+
});
|
|
108
|
+
return true;
|
|
109
|
+
}
|
|
110
|
+
catch (error) {
|
|
111
|
+
console.error('Error ensuring store exists:', error);
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
finally {
|
|
115
|
+
if (db)
|
|
116
|
+
db.close();
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
async function readFromDB(key) {
|
|
120
|
+
if (!(await ensureStoreExists())) {
|
|
121
|
+
return null;
|
|
122
|
+
}
|
|
123
|
+
let db;
|
|
124
|
+
try {
|
|
125
|
+
db = await openDB();
|
|
126
|
+
return new Promise((resolve, reject) => {
|
|
127
|
+
const transaction = db.transaction(storeName, 'readonly');
|
|
128
|
+
const store = transaction.objectStore(storeName);
|
|
129
|
+
const request = store.get(key);
|
|
130
|
+
request.onsuccess = () => resolve(request.result);
|
|
131
|
+
request.onerror = () => reject(request.error);
|
|
132
|
+
transaction.oncomplete = () => {
|
|
133
|
+
db.close();
|
|
134
|
+
};
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
catch (error) {
|
|
138
|
+
console.error('Error reading from DB:', error);
|
|
139
|
+
return null;
|
|
140
|
+
}
|
|
141
|
+
finally {
|
|
142
|
+
if (db)
|
|
143
|
+
db.close();
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
async function writeToDB(key, data) {
|
|
147
|
+
if (!(await ensureStoreExists())) {
|
|
148
|
+
return false;
|
|
149
|
+
}
|
|
150
|
+
let db;
|
|
151
|
+
try {
|
|
152
|
+
db = await openDB();
|
|
153
|
+
return new Promise((resolve, reject) => {
|
|
154
|
+
const transaction = db.transaction(storeName, 'readwrite');
|
|
155
|
+
const store = transaction.objectStore(storeName);
|
|
156
|
+
const request = store.put(data, key);
|
|
157
|
+
request.onsuccess = () => resolve(true);
|
|
158
|
+
request.onerror = () => reject(request.error);
|
|
159
|
+
transaction.oncomplete = () => {
|
|
160
|
+
db.close();
|
|
161
|
+
};
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
catch (error) {
|
|
165
|
+
console.error('Error writing to DB:', error);
|
|
166
|
+
return false;
|
|
167
|
+
}
|
|
168
|
+
finally {
|
|
169
|
+
if (db)
|
|
170
|
+
db.close();
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
const fetchData = async (url) => {
|
|
174
|
+
const cacheKey = `routing-${url}`;
|
|
175
|
+
try {
|
|
176
|
+
// Try to read from cache
|
|
177
|
+
const cachedData = await readFromDB(cacheKey);
|
|
178
|
+
if (cachedData) {
|
|
179
|
+
return JSON.parse(cachedData);
|
|
180
|
+
}
|
|
181
|
+
// If no cached data, fetch from network
|
|
182
|
+
let response = await fetch(url);
|
|
183
|
+
// If 401 error, try the alternative environment
|
|
184
|
+
if (response.status === 401) {
|
|
185
|
+
let fallbackUrl = null;
|
|
186
|
+
if (url.includes('gcprod')) {
|
|
187
|
+
console.log('401 error with gcprod, trying with gcdev...');
|
|
188
|
+
fallbackUrl = url.replace('gcprod', 'gcdev');
|
|
189
|
+
}
|
|
190
|
+
else if (url.includes('gcdev')) {
|
|
191
|
+
console.log('401 error with gcdev, trying with gcprod...');
|
|
192
|
+
fallbackUrl = url.replace('gcdev', 'gcprod');
|
|
193
|
+
}
|
|
194
|
+
if (fallbackUrl) {
|
|
195
|
+
response = await fetch(fallbackUrl);
|
|
196
|
+
// Update cache key to use the successful URL
|
|
197
|
+
const fallbackCacheKey = `routing-${fallbackUrl}`;
|
|
198
|
+
const data = await response.json();
|
|
199
|
+
await writeToDB(fallbackCacheKey, JSON.stringify(data));
|
|
200
|
+
return data;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
const data = await response.json();
|
|
204
|
+
// Cache the new data
|
|
205
|
+
await writeToDB(cacheKey, JSON.stringify(data));
|
|
206
|
+
return data;
|
|
207
|
+
}
|
|
208
|
+
catch (error) {
|
|
209
|
+
console.error('Error in fetchData:', error);
|
|
210
|
+
return null;
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
class RoutingEngine {
|
|
214
|
+
constructor(routing_engine_name, url, road_network, key, default_backend = 'production', settings = null) {
|
|
215
|
+
this.routing_engine_name = routing_engine_name;
|
|
216
|
+
this.default_backend = default_backend;
|
|
217
|
+
console.log(`default backend in routing engine ${default_backend}`);
|
|
218
|
+
this.settings = settings;
|
|
219
|
+
this.useAirDistance = !url || url === 'null' || url === '' || url === undefined;
|
|
220
|
+
if (!this.useAirDistance) {
|
|
221
|
+
if (url.includes('gcstage')) {
|
|
222
|
+
url = url.replace('gcstage', 'gcdev');
|
|
223
|
+
}
|
|
224
|
+
if (url === '' ||
|
|
225
|
+
url === 'null' ||
|
|
226
|
+
url === undefined ||
|
|
227
|
+
url.includes('localhost')) {
|
|
228
|
+
url = 'http://mapbox-osrm-proxy';
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
if (road_network === undefined ||
|
|
232
|
+
road_network === '' ||
|
|
233
|
+
road_network === null ||
|
|
234
|
+
road_network === 'sgvan' ||
|
|
235
|
+
road_network === 'sghorrorvan' ||
|
|
236
|
+
road_network === 'sghorrorbus' ||
|
|
237
|
+
road_network === 'euclidean') {
|
|
238
|
+
road_network = 'van';
|
|
239
|
+
}
|
|
240
|
+
if (key === undefined || key === '' || key === 'token') {
|
|
241
|
+
key = process.env.NEXT_PUBLIC_ROUTING_ENGINE_DEFAULT_KEY || '';
|
|
242
|
+
}
|
|
243
|
+
if (url.endsWith('/')) {
|
|
244
|
+
url = url.slice(0, -1);
|
|
245
|
+
}
|
|
246
|
+
this.url = url;
|
|
247
|
+
if (road_network === 'driving') {
|
|
248
|
+
road_network = 'van';
|
|
249
|
+
}
|
|
250
|
+
this.road_network = road_network;
|
|
251
|
+
this.key = key;
|
|
252
|
+
this.requestCache = {};
|
|
253
|
+
}
|
|
254
|
+
getUrl() {
|
|
255
|
+
if (this.url === 'http://mapbox-osrm-proxy') {
|
|
256
|
+
if (this.default_backend === 'production') {
|
|
257
|
+
return domains_1.SGERP_DOMAINS.osrm.production;
|
|
258
|
+
}
|
|
259
|
+
else if (this.default_backend === 'tc') {
|
|
260
|
+
return domains_1.SGERP_DOMAINS.osrm.tc;
|
|
261
|
+
}
|
|
262
|
+
else if (this.default_backend === 'tcp') {
|
|
263
|
+
return domains_1.SGERP_DOMAINS.osrm.tcp;
|
|
264
|
+
}
|
|
265
|
+
else if (this.default_backend === 'ppe') {
|
|
266
|
+
return domains_1.SGERP_DOMAINS.osrm.ppe;
|
|
267
|
+
}
|
|
268
|
+
else {
|
|
269
|
+
return domains_1.SGERP_DOMAINS.osrm.development;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
return this.url;
|
|
273
|
+
}
|
|
274
|
+
async route(coords, curb, callback, airDistanceOnly = false) {
|
|
275
|
+
var _a;
|
|
276
|
+
const validCoords = coords.filter((coord) => !(coord[0] === 0 && coord[1] === 0));
|
|
277
|
+
if (validCoords.length < 2) {
|
|
278
|
+
callback(undefined, 'error', 'Not enough valid coordinates');
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
// Handle spheroid and euclidean routing engines - use straight-line distance
|
|
282
|
+
if (this.routing_engine_name === 'spheroid' || this.routing_engine_name === 'euclidean') {
|
|
283
|
+
try {
|
|
284
|
+
// Speed in m/s - default to 7 m/s if not specified
|
|
285
|
+
const speed = ((_a = this.settings) === null || _a === void 0 ? void 0 : _a.speed) || 7;
|
|
286
|
+
const spheroidLegs = [];
|
|
287
|
+
const allCoordinates = [];
|
|
288
|
+
for (let i = 0; i < validCoords.length - 1; i++) {
|
|
289
|
+
const start = validCoords[i];
|
|
290
|
+
const end = validCoords[i + 1];
|
|
291
|
+
// Calculate haversine distance
|
|
292
|
+
const distance = this.haversineDistance(start, end);
|
|
293
|
+
// Calculate duration based on speed (distance in meters, speed in m/s, result in seconds)
|
|
294
|
+
const duration = distance / speed;
|
|
295
|
+
const legKey = `${start.join(',')}-${end.join(',')}`;
|
|
296
|
+
// Create a step with straight line between points
|
|
297
|
+
const step = new Step(legKey, [[start[1], start[0]], [end[1], end[0]]], // Convert to [lon, lat]
|
|
298
|
+
duration, distance);
|
|
299
|
+
// Create leg
|
|
300
|
+
const leg = new Leg(legKey, [end[1], end[0]], // start in [lon, lat]
|
|
301
|
+
[end[1], end[0]], // end in [lon, lat]
|
|
302
|
+
[step], duration, distance);
|
|
303
|
+
spheroidLegs.push(leg);
|
|
304
|
+
allCoordinates.push([start[1], start[0]]);
|
|
305
|
+
}
|
|
306
|
+
// Add last coordinate
|
|
307
|
+
const lastCoord = validCoords[validCoords.length - 1];
|
|
308
|
+
allCoordinates.push([lastCoord[1], lastCoord[0]]);
|
|
309
|
+
const spheroidRoute = new Route(spheroidLegs, allCoordinates);
|
|
310
|
+
callback({ osrmRoute: spheroidRoute }, 'ok');
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
313
|
+
catch (error) {
|
|
314
|
+
console.error('Error in spheroid routing:', error);
|
|
315
|
+
callback(undefined, 'error', error.message);
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
const approach = curb ? 'curb' : 'unrestricted';
|
|
320
|
+
const lngLats = validCoords.map((coord) => `${coord[1]},${coord[0]}`).join(';');
|
|
321
|
+
const approaches = validCoords.map(() => approach).join(';');
|
|
322
|
+
let endpointUrl = `${this.getUrl()}/route/v1/${this.road_network}/${lngLats}?overview=full&alternatives=true&steps=true&approaches=${approaches}`;
|
|
323
|
+
if (this.key) {
|
|
324
|
+
endpointUrl += `&access_token=${this.key}`;
|
|
325
|
+
}
|
|
326
|
+
if (this.settings && this.settings.continue_straight != null) {
|
|
327
|
+
endpointUrl += `&continue_straight=${this.settings.continue_straight}`;
|
|
328
|
+
}
|
|
329
|
+
if (this.useAirDistance || !airDistanceOnly) {
|
|
330
|
+
try {
|
|
331
|
+
const data = (await fetchData(endpointUrl));
|
|
332
|
+
if (!data || !data.routes || data.routes.length === 0) {
|
|
333
|
+
callback(undefined, 'error', 'No routes returned from routing service');
|
|
334
|
+
return;
|
|
335
|
+
}
|
|
336
|
+
const osrmLegs = data.routes[0].legs.map((leg, index) => {
|
|
337
|
+
const steps = leg.steps.map((step) => {
|
|
338
|
+
const stepCoordinates = polyline_1.default
|
|
339
|
+
.decode(step.geometry)
|
|
340
|
+
.map((coord) => [coord[1], coord[0]]);
|
|
341
|
+
const firstCoord = stepCoordinates[0];
|
|
342
|
+
const lastCoord = stepCoordinates[stepCoordinates.length - 1];
|
|
343
|
+
const stepKey = `${firstCoord.join(',')}-${lastCoord.join(',')}`;
|
|
344
|
+
return new Step(stepKey, stepCoordinates, step.duration, step.distance);
|
|
345
|
+
});
|
|
346
|
+
const legKey = `${validCoords[index].join(',')}-${validCoords[index + 1].join(',')}`;
|
|
347
|
+
return new Leg(legKey, leg.steps[0].maneuver.location, leg.steps[leg.steps.length - 1].maneuver.location, steps, leg.duration, leg.distance);
|
|
348
|
+
});
|
|
349
|
+
const coordsLatLon = polyline_1.default.decode(data.routes[0].geometry);
|
|
350
|
+
const coordsLonLat = coordsLatLon.map((coord) => [coord[1], coord[0]]);
|
|
351
|
+
const osrmRoute = new Route(osrmLegs, coordsLonLat);
|
|
352
|
+
callback({ osrmRoute }, 'ok');
|
|
353
|
+
}
|
|
354
|
+
catch (error) {
|
|
355
|
+
console.error('Error in route processing:', error);
|
|
356
|
+
callback(undefined, 'error', error.message);
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
haversineDistance(coords1, coords2) {
|
|
361
|
+
const toRadians = (degree) => (degree * Math.PI) / 180;
|
|
362
|
+
const R = 6371e3; // Earth radius in meters
|
|
363
|
+
const lat1 = toRadians(coords1[0]);
|
|
364
|
+
const lat2 = toRadians(coords2[0]);
|
|
365
|
+
const deltaLat = lat2 - lat1;
|
|
366
|
+
const deltaLon = toRadians(coords2[1] - coords1[1]);
|
|
367
|
+
const a = Math.sin(deltaLat / 2) * Math.sin(deltaLat / 2) +
|
|
368
|
+
Math.cos(lat1) * Math.cos(lat2) * Math.sin(deltaLon / 2) * Math.sin(deltaLon / 2);
|
|
369
|
+
const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
|
|
370
|
+
return R * c; // Distance in meters
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
exports.RoutingEngine = RoutingEngine;
|