@wemap/routers 10.3.1 → 10.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,155 @@
1
+ import { roundFactor } from '@wemap/maths';
2
+ import ItineraryInfoManager from '../src/ItineraryInfoManager.js';
3
+ import Step from '../src/model/Step.js';
4
+ import { getTurnInfoFromAngle } from '../src/wemap/WemapRouterUtils.js';
5
+
6
+ export default class InstructionManager {
7
+
8
+ useProposals = false;
9
+
10
+ /**
11
+ * @param {Step} step
12
+ * @returns {{type: string, direction?: string}}
13
+ */
14
+ static getInfoFromStep(step) {
15
+
16
+ let type, direction, directionExtra, levelChange;
17
+
18
+ if (step.levelChange) {
19
+ type = 'level-change';
20
+ levelChange = step.levelChange;
21
+ } else {
22
+ type = 'turn';
23
+ const turnInfo = getTurnInfoFromAngle(step.angle);
24
+ direction = turnInfo.direction;
25
+ directionExtra = turnInfo.directionExtra;
26
+ }
27
+
28
+ return {
29
+ type,
30
+ direction,
31
+ directionExtra,
32
+ levelChange,
33
+ name: step.name,
34
+ indoor: step.coords.level !== null
35
+ };
36
+ }
37
+
38
+ /**
39
+ * @param {Step} step
40
+ * @returns {string}
41
+ */
42
+ // eslint-disable-next-line max-statements
43
+ static getInstructionFromStep(step) {
44
+
45
+ const { direction, directionExtra } = getTurnInfoFromAngle(step.angle);
46
+ const isTurn = direction !== 'straight';
47
+
48
+ if (step.lastStep) {
49
+ if (isTurn && direction === 'left') {
50
+ return 'Your destination is on your left';
51
+ } else if (isTurn && direction === 'right') {
52
+ return 'Your destination is on your right';
53
+ }
54
+ }
55
+
56
+ const suffix = step.name ? ` on ${step.name}` : '';
57
+
58
+ if (step.levelChange) {
59
+ if (step.levelChange.direction === 'up') {
60
+ if (step.levelChange.type === 'conveyor') {
61
+ return 'Go up the escalator';
62
+ }
63
+ if (step.levelChange.type === 'stairs') {
64
+ return 'Go up the stairs';
65
+ }
66
+ return 'Go up' + suffix;
67
+ }
68
+ if (step.levelChange.direction === 'down') {
69
+ if (step.levelChange.type === 'conveyor') {
70
+ return 'Go down the escalator';
71
+ }
72
+ if (step.levelChange.type === 'stairs') {
73
+ return 'Go down the stairs';
74
+ }
75
+ return 'Go down' + suffix;
76
+ }
77
+ if (step.extras.subwayEntrance) {
78
+ return `Take exit ${step.extras.subwayEntranceRef}`;
79
+ }
80
+ }
81
+
82
+ if (isTurn) {
83
+ if (direction === 'left') {
84
+ if (directionExtra === 'slight') {
85
+ return 'Turn slightly left' + suffix;
86
+ }
87
+ return 'Turn left' + suffix;
88
+ }
89
+ if (direction === 'right') {
90
+ if (directionExtra === 'slight') {
91
+ return 'Turn slightly right' + suffix;
92
+ }
93
+ return 'Turn right' + suffix;
94
+ }
95
+ }
96
+
97
+
98
+ return '';
99
+ }
100
+
101
+
102
+ /**
103
+ * @param {ItineraryInfoManager} itineraryInfoManager
104
+ * @param {Coordinates} position
105
+ * @returns {string | null}
106
+ */
107
+ static getInstructionFromPosition(itineraryInfoManager, position) {
108
+ const itineraryInfo = itineraryInfoManager.getInfo(position);
109
+ if (!itineraryInfo) {
110
+ return null;
111
+ }
112
+
113
+ // If distance between itinerary and position is too far,
114
+ // something went wrong. (mapmatching.maxDistance)
115
+ if (this.useProposals && itineraryInfo.projection.distanceFromNearestElement > 15) {
116
+ return 'It seems that we are a little bit lost, please start again the localization process';
117
+ }
118
+
119
+ const { nextStep } = itineraryInfo;
120
+ if (!nextStep) {
121
+ return 'You are arrived';
122
+ }
123
+
124
+ const distNextStep = position.distanceTo(nextStep.coords);
125
+ const distRounded = roundFactor(distNextStep, 5);
126
+
127
+ if (this.useProposals && distNextStep > 10) {
128
+ return `Continue straight for ${distRounded}m`;
129
+ }
130
+
131
+
132
+ let instruction = InstructionManager.getInstructionFromStep(nextStep);
133
+
134
+ const stepWithImportantInfo = itineraryInfoManager._steps.find(step =>
135
+ step.levelChange
136
+ && step.number > itineraryInfo.nextStep.number
137
+ && step.coords.distanceTo(itineraryInfo.nextStep.coords) < 10
138
+ ) || null;
139
+
140
+ if (stepWithImportantInfo && stepWithImportantInfo.levelChange) {
141
+ const nextBearing = nextStep.coords.bearingTo(stepWithImportantInfo.coords);
142
+ const { direction } = getTurnInfoFromAngle(nextBearing - itineraryInfo.nextStep.previousBearing);
143
+ instruction = direction === 'straight' ? 'Continue straight' : `Turn ${direction}`;
144
+ const { direction: levelDirection, type: levelType } = stepWithImportantInfo.levelChange;
145
+ instruction += ` and take the ${levelType} going ${levelDirection}`;
146
+ }
147
+
148
+ if (distNextStep >= 5) {
149
+ instruction += ` in ${distRounded}m`;
150
+ }
151
+
152
+ return instruction;
153
+ }
154
+
155
+ }
@@ -0,0 +1,104 @@
1
+ import ItineraryInfoManager from '../src/ItineraryInfoManager.js';
2
+ import Step from '../src/model/Step.js';
3
+ import OsrmRemoteRouter from '../src/remote/osrm/OsrmRemoteRouter.js';
4
+
5
+ export default class InstructionManagerV1 {
6
+
7
+ /**
8
+ * @param {Step} step
9
+ * @returns {string}
10
+ */
11
+ // eslint-disable-next-line max-statements, complexity
12
+ static getInstructionFromStep(step) {
13
+
14
+ const modifier = OsrmRemoteRouter.getModifierFromAngle(step.angle);
15
+ let direction, directionExtra;
16
+ if (modifier.includes('left')) {
17
+ direction = 'left';
18
+ } else if (modifier.includes('right')) {
19
+ direction = 'right';
20
+ }
21
+ if (modifier.includes('slight')) {
22
+ directionExtra = 'slight';
23
+ }
24
+ const isTurn = modifier !== 'straight';
25
+
26
+ if (step.lastStep) {
27
+ if (isTurn && direction === 'left') {
28
+ return 'Your destination is on your left';
29
+ } else if (isTurn && direction === 'right') {
30
+ return 'Your destination is on your right';
31
+ }
32
+ }
33
+
34
+ const suffix = step.name ? ` on ${step.name}` : '';
35
+
36
+ if (step.levelChange) {
37
+ if (step.levelChange.direction === 'up') {
38
+ if (step.levelChange.type === 'conveyor') {
39
+ return 'Go up the escalator';
40
+ }
41
+ if (step.levelChange.type === 'stairs') {
42
+ return 'Go up the stairs';
43
+ }
44
+ return 'Go up' + suffix;
45
+ }
46
+ if (step.levelChange.direction === 'down') {
47
+ if (step.levelChange.type === 'conveyor') {
48
+ return 'Go down the escalator';
49
+ }
50
+ if (step.levelChange.type === 'stairs') {
51
+ return 'Go down the stairs';
52
+ }
53
+ return 'Go down' + suffix;
54
+ }
55
+ if (step.extras.subwayEntrance) {
56
+ return `Take exit ${step.extras.subwayEntranceRef}`;
57
+ }
58
+ }
59
+
60
+ if (isTurn) {
61
+ if (direction === 'left') {
62
+ if (directionExtra === 'slight') {
63
+ return 'Turn slightly left' + suffix;
64
+ }
65
+ return 'Turn left' + suffix;
66
+ }
67
+ if (direction === 'right') {
68
+ if (directionExtra === 'slight') {
69
+ return 'Turn slightly right' + suffix;
70
+ }
71
+ return 'Turn right' + suffix;
72
+ }
73
+ }
74
+
75
+
76
+ return '';
77
+ }
78
+
79
+
80
+ /**
81
+ * @param {ItineraryInfoManager} itineraryInfoManager
82
+ * @param {Coordinates} position
83
+ * @returns {string | null}
84
+ */
85
+ static getInstructionFromPosition(itineraryInfoManager, position) {
86
+ const itineraryInfo = itineraryInfoManager.getInfo(position);
87
+ if (!itineraryInfo) {
88
+ return null;
89
+ }
90
+
91
+ const { nextStep } = itineraryInfo;
92
+ if (!nextStep) {
93
+ return null;
94
+ }
95
+
96
+ const distNextStep = position.distanceTo(nextStep.coords);
97
+ const nextStep2 = itineraryInfoManager._steps.find((step) => step.number > nextStep.number);
98
+ if (distNextStep < 3 && nextStep2) {
99
+ return InstructionManagerV1.getInstructionFromStep(nextStep2);
100
+ }
101
+
102
+ return InstructionManagerV1.getInstructionFromStep(nextStep);
103
+ }
104
+ }
package/package.json CHANGED
@@ -12,7 +12,7 @@
12
12
  "directory": "packages/routers"
13
13
  },
14
14
  "name": "@wemap/routers",
15
- "version": "10.3.1",
15
+ "version": "10.5.0",
16
16
  "bugs": {
17
17
  "url": "https://github.com/wemap/wemap-modules-js/issues"
18
18
  },
@@ -30,10 +30,10 @@
30
30
  "@turf/boolean-point-in-polygon": "^6.5.0",
31
31
  "@turf/convex": "^6.5.0",
32
32
  "@turf/helpers": "^6.5.0",
33
- "@wemap/geo": "^10.3.1",
33
+ "@wemap/geo": "^10.5.0",
34
34
  "@wemap/logger": "^10.0.0",
35
35
  "@wemap/maths": "^10.3.1",
36
- "@wemap/osm": "^10.3.1"
36
+ "@wemap/osm": "^10.5.0"
37
37
  },
38
- "gitHead": "e4775e59dd3db76cf7b3d1e63a3e2402bf5f0088"
38
+ "gitHead": "da571076de6bd9f4f2653d097763ff1244a36ebb"
39
39
  }
@@ -3,7 +3,7 @@ import convexHullFn from '@turf/convex';
3
3
  import { polygon as turfPolygon } from '@turf/helpers';
4
4
 
5
5
  import { Coordinates, GraphNode, GraphRouter, Network, NoRouteFoundError } from '@wemap/geo';
6
- import { OsmParser, OsmNetworkUtils } from '@wemap/osm';
6
+ import { OsmParser, OsmNetworkUtils, OsmElement } from '@wemap/osm';
7
7
  import { Itinerary, WemapRouterOptions, WemapRouterUtils } from '@wemap/routers';
8
8
 
9
9
  import Constants from '../Constants.js';
@@ -13,16 +13,22 @@ class IOMap {
13
13
  /** @type {?string} */
14
14
  name;
15
15
 
16
- /** @type {!GraphRouter} */
16
+ /** @type {!Network<OsmElement>} */
17
+ network;
18
+
19
+ /** @type {!GraphRouter<OsmElement>} */
17
20
  router;
18
21
 
19
22
  /** @type {!([number, number][])} */
20
23
  bounds;
21
24
 
22
25
 
23
- /** @type {!(GraphNode[])} */
26
+ /** @type {!(GraphNode<OsmElement>[])} */
24
27
  entryPoints;
25
28
 
29
+ /** @type {number[]} */
30
+ disabledWays = [];
31
+
26
32
  /**
27
33
  * @param {Network} network The network of the map
28
34
  * @param {GraphNode[]} entryPoints The map vertex that can be used to go inside / outside a IOMap
@@ -33,6 +39,7 @@ class IOMap {
33
39
  constructor(network, entryPoints, bounds = null, name = null) {
34
40
 
35
41
  this.name = name;
42
+ this.network = network;
36
43
  this.router = new GraphRouter(network);
37
44
 
38
45
  // Entry points
@@ -189,6 +196,16 @@ class IOMap {
189
196
  // Transform a network itinerary (nodes, edges...) to a router itinerary (legs, steps...)
190
197
  return WemapRouterUtils.createItineraryFromGraphItinerary(graphItinerary, Constants.ROUTING_MODE.WALK);
191
198
  }
199
+
200
+ enableWay(osmId) {
201
+ const edges = this.network.edges.filter(edge => edge.builtFrom.id === osmId);
202
+ this.router.disabledEdges = this.router.disabledEdges.filter(edge => !edges.includes(edge));
203
+ }
204
+
205
+ disableWay(osmId) {
206
+ const edges = this.network.edges.filter(edge => edge.builtFrom.id === osmId);
207
+ this.router.disabledEdges.push(...edges);
208
+ }
192
209
  }
193
210
 
194
211
  export default IOMap;