incyclist-services 1.9.11 → 1.9.12
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/lib/cjs/maps/MapArea/options.js +2 -3
- package/lib/cjs/ride/route/FreeRideDisplayService.js +36 -5
- package/lib/cjs/routes/free-ride/option-labels.js +141 -0
- package/lib/cjs/routes/free-ride/service.js +217 -117
- package/lib/esm/maps/MapArea/options.js +2 -3
- package/lib/esm/ride/route/FreeRideDisplayService.js +36 -5
- package/lib/esm/routes/free-ride/service.js +217 -117
- package/lib/types/maps/MapArea/types.d.ts +1 -0
- package/lib/types/ride/base/types.d.ts +2 -1
- package/lib/types/ride/route/FreeRideDisplayService.d.ts +4 -1
- package/lib/types/routes/free-ride/service.d.ts +18 -2
- package/lib/types/routes/list/types.d.ts +11 -0
- package/package.json +1 -1
|
@@ -9,6 +9,7 @@ const clone_1 = __importDefault(require("../../utils/clone"));
|
|
|
9
9
|
const utils_1 = require("./utils");
|
|
10
10
|
const geo_1 = require("../../utils/geo");
|
|
11
11
|
const utils_2 = require("../../utils");
|
|
12
|
+
const option_labels_1 = require("../../routes/free-ride/option-labels");
|
|
12
13
|
class OptionManager {
|
|
13
14
|
service;
|
|
14
15
|
map;
|
|
@@ -108,9 +109,7 @@ class OptionManager {
|
|
|
108
109
|
const currentDirection = this.map?.getHeading(way, 'end') ?? 0;
|
|
109
110
|
options.forEach((option) => {
|
|
110
111
|
const direction = this.map?.getHeading(option, 'start') ?? 0;
|
|
111
|
-
option.direction = direction - currentDirection;
|
|
112
|
-
if (option.direction > 180)
|
|
113
|
-
option.direction = option.direction - 360;
|
|
112
|
+
option.direction = (0, option_labels_1.normalizeAngle)(direction - currentDirection);
|
|
114
113
|
});
|
|
115
114
|
if (props?.minDistance) {
|
|
116
115
|
await this.checkMinDistance(options, props.minDistance);
|
|
@@ -72,6 +72,7 @@ let FreeRideDisplayService = (() => {
|
|
|
72
72
|
prevViewport;
|
|
73
73
|
tsLastOptionChange;
|
|
74
74
|
optionsVisible;
|
|
75
|
+
lastLoggedButtons;
|
|
75
76
|
mapProps;
|
|
76
77
|
distanceRemaining;
|
|
77
78
|
timeRemaining;
|
|
@@ -105,7 +106,7 @@ let FreeRideDisplayService = (() => {
|
|
|
105
106
|
}
|
|
106
107
|
selectOption(option) {
|
|
107
108
|
try {
|
|
108
|
-
this.getFreeRideService().
|
|
109
|
+
this.getFreeRideService().selectOptionByUser(option);
|
|
109
110
|
return this.getFreeRideService().buildUIOptions(this.currentOptions);
|
|
110
111
|
}
|
|
111
112
|
catch (err) {
|
|
@@ -226,7 +227,8 @@ let FreeRideDisplayService = (() => {
|
|
|
226
227
|
optionsId: this.getOptionsId(),
|
|
227
228
|
distance,
|
|
228
229
|
isNearby: this.isNearbyOption && distance !== undefined,
|
|
229
|
-
turn: this.isTurnEnabled
|
|
230
|
+
turn: this.isTurnEnabled,
|
|
231
|
+
optionsState: this.getOptionsState()
|
|
230
232
|
};
|
|
231
233
|
return {
|
|
232
234
|
...routeProps,
|
|
@@ -282,6 +284,7 @@ let FreeRideDisplayService = (() => {
|
|
|
282
284
|
mode: 'free ride',
|
|
283
285
|
rideView,
|
|
284
286
|
lat, lng,
|
|
287
|
+
startSource: this.getFreeRideService().getStartSource(),
|
|
285
288
|
...bikeProps
|
|
286
289
|
};
|
|
287
290
|
return props;
|
|
@@ -291,6 +294,28 @@ let FreeRideDisplayService = (() => {
|
|
|
291
294
|
return {};
|
|
292
295
|
}
|
|
293
296
|
}
|
|
297
|
+
getOptionsState() {
|
|
298
|
+
const options = this.getFreeRideService().getOptions();
|
|
299
|
+
if (this.isStarting || options === undefined)
|
|
300
|
+
return 'loading';
|
|
301
|
+
if (options.length > 0)
|
|
302
|
+
return 'ready';
|
|
303
|
+
return this.getFreeRideService().isLastQueryValid() ? 'none' : 'failed';
|
|
304
|
+
}
|
|
305
|
+
getButtonsLogInfo() {
|
|
306
|
+
try {
|
|
307
|
+
return this.getFreeRideService().buildUIOptions(this.currentOptions ?? []).map(o => {
|
|
308
|
+
let marker;
|
|
309
|
+
if (o.selected)
|
|
310
|
+
marker = o.selectedBy === 'user' ? 'NEXT' : 'AUTO';
|
|
311
|
+
return [o.index, o.maneuverText, o.roadLabel, marker].filter(v => v !== undefined).join('·');
|
|
312
|
+
}).join('|');
|
|
313
|
+
}
|
|
314
|
+
catch (err) {
|
|
315
|
+
this.logError(err, 'getButtonsLogInfo');
|
|
316
|
+
return '';
|
|
317
|
+
}
|
|
318
|
+
}
|
|
294
319
|
getOptionsId() {
|
|
295
320
|
if (!this.currentOptions?.length)
|
|
296
321
|
return 'none';
|
|
@@ -479,11 +504,17 @@ let FreeRideDisplayService = (() => {
|
|
|
479
504
|
const { lat, lng } = this.currentOptions[0].path[0];
|
|
480
505
|
return { lat, lng };
|
|
481
506
|
}
|
|
482
|
-
onOptionsVisibleChanged(visible) {
|
|
483
|
-
|
|
507
|
+
onOptionsVisibleChanged(visible, reason) {
|
|
508
|
+
const changed = visible !== this.optionsVisible;
|
|
509
|
+
const buttons = visible ? this.getButtonsLogInfo() : undefined;
|
|
510
|
+
if (!changed && (!visible || buttons === this.lastLoggedButtons))
|
|
484
511
|
return;
|
|
485
|
-
}
|
|
486
512
|
this.optionsVisible = visible;
|
|
513
|
+
this.lastLoggedButtons = visible ? buttons : undefined;
|
|
514
|
+
const props = { visible, count: this.currentOptions?.length ?? 0, reason: reason ?? 'unknown', pinned: this.isNearbyOption };
|
|
515
|
+
if (buttons !== undefined)
|
|
516
|
+
props.buttons = buttons;
|
|
517
|
+
this.logEvent({ message: 'free ride options visibility', ...props });
|
|
487
518
|
}
|
|
488
519
|
emitRouteUpdate() {
|
|
489
520
|
const options = this.getFreeRideService().buildUIOptions(this.currentOptions);
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getLayoutOrder = exports.buildOptionLabels = exports.getRoadLabel = exports.deriveManeuvers = exports.getCompassWord = exports.normalizeAngle = exports.FALLBACK_LABEL = exports.MANEUVER_TEXT = void 0;
|
|
4
|
+
exports.MANEUVER_TEXT = {
|
|
5
|
+
'straight': 'Straight',
|
|
6
|
+
'slight-left': 'Slight left',
|
|
7
|
+
'slight-right': 'Slight right',
|
|
8
|
+
'left': 'Left',
|
|
9
|
+
'right': 'Right',
|
|
10
|
+
'sharp-left': 'Sharp left',
|
|
11
|
+
'sharp-right': 'Sharp right',
|
|
12
|
+
'keep-left': 'Keep left',
|
|
13
|
+
'keep-right': 'Keep right',
|
|
14
|
+
'u-turn': 'Turn around',
|
|
15
|
+
'roundabout': 'Roundabout',
|
|
16
|
+
'unknown': 'Road'
|
|
17
|
+
};
|
|
18
|
+
const COMPASS_WORDS = ['North', 'Northeast', 'East', 'Southeast', 'South', 'Southwest', 'West', 'Northwest'];
|
|
19
|
+
exports.FALLBACK_LABEL = {
|
|
20
|
+
roundabout: 'Roundabout',
|
|
21
|
+
slip: 'Slip road',
|
|
22
|
+
unnamed: 'Unnamed road'
|
|
23
|
+
};
|
|
24
|
+
const normalizeAngle = (angle) => {
|
|
25
|
+
if (!Number.isFinite(angle))
|
|
26
|
+
return angle;
|
|
27
|
+
let a = angle % 360;
|
|
28
|
+
if (a > 180)
|
|
29
|
+
a -= 360;
|
|
30
|
+
if (a <= -180)
|
|
31
|
+
a += 360;
|
|
32
|
+
return a;
|
|
33
|
+
};
|
|
34
|
+
exports.normalizeAngle = normalizeAngle;
|
|
35
|
+
const getCompassWord = (heading) => {
|
|
36
|
+
if (!Number.isFinite(heading))
|
|
37
|
+
return undefined;
|
|
38
|
+
const normalized = ((heading % 360) + 360) % 360;
|
|
39
|
+
return COMPASS_WORDS[Math.round(normalized / 45) % 8];
|
|
40
|
+
};
|
|
41
|
+
exports.getCompassWord = getCompassWord;
|
|
42
|
+
const bucket = (angle) => {
|
|
43
|
+
const abs = Math.abs(angle);
|
|
44
|
+
const right = angle > 0;
|
|
45
|
+
if (abs <= 20)
|
|
46
|
+
return 'straight';
|
|
47
|
+
if (abs <= 60)
|
|
48
|
+
return right ? 'slight-right' : 'slight-left';
|
|
49
|
+
if (abs <= 135)
|
|
50
|
+
return right ? 'right' : 'left';
|
|
51
|
+
if (abs <= 170)
|
|
52
|
+
return right ? 'sharp-right' : 'sharp-left';
|
|
53
|
+
return 'u-turn';
|
|
54
|
+
};
|
|
55
|
+
const deriveManeuvers = (options) => {
|
|
56
|
+
const result = options.map(o => {
|
|
57
|
+
if (o.roundabout)
|
|
58
|
+
return 'roundabout';
|
|
59
|
+
if (!Number.isFinite(o.direction))
|
|
60
|
+
return 'unknown';
|
|
61
|
+
return bucket(o.direction);
|
|
62
|
+
});
|
|
63
|
+
const groups = new Map();
|
|
64
|
+
result.forEach((m, idx) => {
|
|
65
|
+
if (m === 'roundabout' || m === 'unknown' || m === 'u-turn')
|
|
66
|
+
return;
|
|
67
|
+
groups.set(m, [...(groups.get(m) ?? []), idx]);
|
|
68
|
+
});
|
|
69
|
+
groups.forEach(indexes => {
|
|
70
|
+
if (indexes.length < 2)
|
|
71
|
+
return;
|
|
72
|
+
const sorted = [...indexes].sort((a, b) => options[a].direction - options[b].direction);
|
|
73
|
+
result[sorted[0]] = 'keep-left';
|
|
74
|
+
result[sorted.at(-1)] = 'keep-right';
|
|
75
|
+
});
|
|
76
|
+
return result;
|
|
77
|
+
};
|
|
78
|
+
exports.deriveManeuvers = deriveManeuvers;
|
|
79
|
+
const getRoadLabel = (tags) => {
|
|
80
|
+
const roadName = tags?.name || tags?.ref || undefined;
|
|
81
|
+
if (roadName)
|
|
82
|
+
return { roadName, roadLabel: roadName };
|
|
83
|
+
if (tags?.junction === 'roundabout')
|
|
84
|
+
return { roadLabel: exports.FALLBACK_LABEL.roundabout };
|
|
85
|
+
if (tags?.highway?.endsWith('_link'))
|
|
86
|
+
return { roadLabel: exports.FALLBACK_LABEL.slip };
|
|
87
|
+
return { roadLabel: exports.FALLBACK_LABEL.unnamed };
|
|
88
|
+
};
|
|
89
|
+
exports.getRoadLabel = getRoadLabel;
|
|
90
|
+
const getDegradedText = (compass, idx) => compass ? `Heading ${compass.toLowerCase()}` : `Road ${idx + 1}`;
|
|
91
|
+
const FORK_SIDES = {
|
|
92
|
+
2: ['left fork', 'right fork'],
|
|
93
|
+
3: ['left fork', 'middle fork', 'right fork']
|
|
94
|
+
};
|
|
95
|
+
const buildOptionLabels = (options) => {
|
|
96
|
+
const maneuvers = (0, exports.deriveManeuvers)(options);
|
|
97
|
+
const labels = options.map((o, idx) => {
|
|
98
|
+
const maneuver = maneuvers[idx];
|
|
99
|
+
const degraded = maneuver === 'unknown';
|
|
100
|
+
const { roadName, roadLabel } = (0, exports.getRoadLabel)(o.tags);
|
|
101
|
+
return {
|
|
102
|
+
maneuver,
|
|
103
|
+
maneuverText: degraded ? getDegradedText(o.compass, idx) : exports.MANEUVER_TEXT[maneuver],
|
|
104
|
+
roadName,
|
|
105
|
+
roadLabel,
|
|
106
|
+
compass: o.compass,
|
|
107
|
+
degraded
|
|
108
|
+
};
|
|
109
|
+
});
|
|
110
|
+
const key = (l) => `${l.maneuverText}|${l.roadLabel}`;
|
|
111
|
+
const collisions = () => {
|
|
112
|
+
const groups = new Map();
|
|
113
|
+
labels.forEach((l, idx) => groups.set(key(l), [...(groups.get(key(l)) ?? []), idx]));
|
|
114
|
+
return [...groups.values()].filter(g => g.length > 1);
|
|
115
|
+
};
|
|
116
|
+
collisions().forEach(group => {
|
|
117
|
+
const compasses = group.map(idx => labels[idx].compass);
|
|
118
|
+
if (compasses.some(c => !c) || new Set(compasses).size !== group.length)
|
|
119
|
+
return;
|
|
120
|
+
group.forEach(idx => { labels[idx].roadLabel = `${labels[idx].roadLabel}, ${labels[idx].compass?.toLowerCase()}`; });
|
|
121
|
+
});
|
|
122
|
+
collisions().forEach(group => {
|
|
123
|
+
const sides = FORK_SIDES[group.length];
|
|
124
|
+
if (!sides || group.some(idx => !Number.isFinite(options[idx].direction)))
|
|
125
|
+
return;
|
|
126
|
+
const sorted = [...group].sort((a, b) => options[a].direction - options[b].direction);
|
|
127
|
+
sorted.forEach((idx, i) => { labels[idx].roadLabel = `${labels[idx].roadLabel}, ${sides[i]}`; });
|
|
128
|
+
});
|
|
129
|
+
return labels;
|
|
130
|
+
};
|
|
131
|
+
exports.buildOptionLabels = buildOptionLabels;
|
|
132
|
+
const getLayoutOrder = (options) => {
|
|
133
|
+
const indexes = options.map((_o, idx) => idx);
|
|
134
|
+
if (options.some(o => o.roundabout))
|
|
135
|
+
return indexes;
|
|
136
|
+
const valid = (idx) => Number.isFinite(options[idx].direction);
|
|
137
|
+
const withAngle = indexes.filter(valid).sort((a, b) => options[a].direction - options[b].direction);
|
|
138
|
+
const withoutAngle = indexes.filter(idx => !valid(idx));
|
|
139
|
+
return [...withAngle, ...withoutAngle];
|
|
140
|
+
};
|
|
141
|
+
exports.getLayoutOrder = getLayoutOrder;
|