@wemap/routers 10.5.0 → 10.5.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.
@@ -94,8 +94,7 @@ export default class InstructionManager {
94
94
  }
95
95
  }
96
96
 
97
-
98
- return '';
97
+ return 'Continue straight';
99
98
  }
100
99
 
101
100
 
package/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- import { Coordinates, GraphProjection, Network } from '@wemap/geo';
1
+ import { Coordinates, GraphEdge, GraphNode, GraphProjection, GraphRouter, Network } from '@wemap/geo';
2
+ import { OsmElement } from '@wemap/osm';
2
3
 
3
4
  declare module '@wemap/routers' {
4
5
 
@@ -53,7 +54,7 @@ declare module '@wemap/routers' {
53
54
 
54
55
  isPublicTransport(): boolean;
55
56
  equals(obj: Leg): boolean;
56
- toNetwork(): Network;
57
+ toNetwork(): Network<null>;
57
58
  toJson(): object;
58
59
 
59
60
  static equals(obj1: Leg, obj2: Leg): boolean;
@@ -74,13 +75,13 @@ declare module '@wemap/routers' {
74
75
  get mode(): ItineraryMode;
75
76
 
76
77
  equals(obj: Itinerary): boolean;
77
- toNetwork(): Network;
78
+ toNetwork(): Network<null>;
78
79
  toJson(): object;
79
80
 
80
81
  static equals(obj1: Itinerary, obj2: Itinerary): boolean;
81
82
  static fromItineraries(...itineraries: Itinerary[]): Itinerary;
82
83
  static fromOrderedPointsArray(points: number[][], from: Coordinates, to: Coordinates): Itinerary;
83
- static fromOrderedCoordinates(points: Coordinates[], from: Coordinates, to: Coordinates, mode: ItineraryMode = 'WALK'): Itinerary;
84
+ static fromOrderedCoordinates(points: Coordinates[], from: Coordinates, to: Coordinates, mode?: ItineraryMode): Itinerary;
84
85
  static fromJson(json: object): Itinerary;
85
86
  }
86
87
 
@@ -98,10 +99,10 @@ declare module '@wemap/routers' {
98
99
  static fromJson(json: object): RouterResponse;
99
100
  }
100
101
 
101
- export class ItineraryInfo {
102
+ export class ItineraryInfo<T> {
102
103
  nextStep: Step;
103
104
  previousStep: Step;
104
- projection: GraphProjection;
105
+ projection: GraphProjection<T>;
105
106
  leg: Leg;
106
107
  traveledDistance: number;
107
108
  traveledPercentage: number;
@@ -109,12 +110,56 @@ declare module '@wemap/routers' {
109
110
  remainingPercentage: number;
110
111
  }
111
112
 
112
- export class ItineraryInfoManager {
113
+ export class ItineraryInfoManager<T> {
113
114
  set itinerary(itinerary: Itinerary);
114
- getInfo(position: Coordinates): ItineraryInfo | null;
115
+ getInfo(position: Coordinates): ItineraryInfo<T> | null;
115
116
  }
116
117
 
117
- export function getDurationFromLength(length: number, speed: number = 5): number;
118
+ export class WemapRouterOptions {
119
+ static DEFAULT: WemapRouterOptions;
120
+ static get WITHOUT_STAIRS(): WemapRouterOptions;
121
+ static getDurationFromLength(length: number, speed?: number): number;
122
+
123
+ weightEdgeFn: (edge: GraphEdge<OsmElement>) => boolean;
124
+ }
125
+
126
+ export class WemapMetaRouterIOMap {
127
+ name: string | null;
128
+ network: Network<OsmElement>;
129
+ router: GraphRouter<OsmElement>;
130
+ bounds: [number, number][];
131
+ entryPoints: GraphNode<OsmElement>;
132
+ disabledWays: Set<number>;
133
+
134
+ constructor(
135
+ network: Network<OsmElement>,
136
+ entryPoints: GraphNode<OsmElement>[],
137
+ bounds?: Coordinates[] | null,
138
+ name?: string | null
139
+ );
140
+
141
+ disableWay(osmId: number): void;
142
+ enableWay(osmId: number): void;
143
+ getOrderedEntryPointsSortedByDistance(
144
+ start: Coordinates, end: Coordinates
145
+ ): GraphNode<OsmElement>[];
146
+ getBestItineraryFromEntryPointsToEnd(
147
+ start: Coordinates, end: Coordinates,
148
+ options: WemapRouterOptions
149
+ ): Itinerary[];
150
+ getBestItineraryFromStartToEntryPoints(
151
+ start: Coordinates, end: Coordinates,
152
+ options: WemapRouterOptions
153
+ ): Itinerary[];
154
+ getItineraryInsideMap(start: Coordinates, end: Coordinates,
155
+ options: WemapRouterOptions
156
+ ): Itinerary[] | null;
157
+ isPointInside(coordinates: Coordinates): boolean;
158
+
159
+ static fromOsmXml(osmXmlString: string, name?: string | null): WemapMetaRouterIOMap;
160
+ }
161
+
162
+ export function getDurationFromLength(length: number, speed?: number): number;
118
163
  export function multiplyLegLevel(leg: Leg, levelFactor: number): void;
119
164
  export function multiplyItineraryLevel(itinerary: Itinerary, levelFactor: number): void;
120
165
  export function multiplyRouterResponseLevel(routerResponse: RouterResponse, levelFactor: number): void;
package/package.json CHANGED
@@ -12,7 +12,7 @@
12
12
  "directory": "packages/routers"
13
13
  },
14
14
  "name": "@wemap/routers",
15
- "version": "10.5.0",
15
+ "version": "10.5.2",
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.5.0",
33
+ "@wemap/geo": "^10.5.1",
34
34
  "@wemap/logger": "^10.0.0",
35
35
  "@wemap/maths": "^10.3.1",
36
- "@wemap/osm": "^10.5.0"
36
+ "@wemap/osm": "^10.5.1"
37
37
  },
38
- "gitHead": "da571076de6bd9f4f2653d097763ff1244a36ebb"
38
+ "gitHead": "befe244ba1bc8d1761522e2458f611efe8cee598"
39
39
  }
package/src/Utils.js CHANGED
@@ -68,3 +68,31 @@ export function multiplyRouterResponseLevel(routerResponse, levelFactor) {
68
68
  }
69
69
 
70
70
 
71
+ /**
72
+ * @param {Itinerary} itinerary
73
+ * @param {number} levelFactor
74
+ */
75
+ export function forceUnknownItineraryLevelTo0(itinerary) {
76
+
77
+ itinerary.from.level ||= 0;
78
+ itinerary.to.level ||= 0;
79
+
80
+ for (const leg of itinerary.legs) {
81
+ leg.from.coords.level ||= 0;
82
+ leg.to.coords.level ||= 0;
83
+ for (const coords of leg.coords) {
84
+ coords.level ||= 0;
85
+ }
86
+ if (leg.steps) {
87
+ for (const step of leg.steps) {
88
+ step.coords.level ||= 0;
89
+ }
90
+ }
91
+ }
92
+
93
+ if (itinerary._coords) {
94
+ for (const coords of itinerary._coords) {
95
+ coords.level ||= 0;
96
+ }
97
+ }
98
+ }
@@ -1,5 +1,5 @@
1
1
  import { GraphItinerary } from '@wemap/geo';
2
- import { diffAngleLines, positiveMod, rad2deg } from '@wemap/maths';
2
+ import { diffAngle, rad2deg } from '@wemap/maths';
3
3
  import { OsmElement } from '@wemap/osm';
4
4
 
5
5
  import Constants from '../Constants.js';
@@ -56,18 +56,18 @@ export function getTurnInfoFromAngle(_angle) {
56
56
 
57
57
  let direction, directionExtra;
58
58
 
59
- const directionAngle = rad2deg(diffAngleLines(_angle, Math.PI));
60
- if (directionAngle <= 20) {
59
+ const directionAngle = rad2deg(diffAngle(_angle, Math.PI));
60
+ const directionAngleAbs = Math.abs(directionAngle);
61
+ if (directionAngleAbs <= 20) {
61
62
  direction = 'straight';
62
63
  } else {
63
- direction = positiveMod(_angle, 2 * Math.PI) > Math.PI ? 'left' : 'right';
64
- if (directionAngle < 55) {
64
+ direction = directionAngle > 0 ? 'left' : 'right';
65
+ if (directionAngleAbs < 55) {
65
66
  directionExtra = 'slight';
66
- } else if (directionAngle > 120) {
67
+ } else if (directionAngleAbs > 120) {
67
68
  directionExtra = 'sharp';
68
69
  }
69
70
  }
70
71
 
71
-
72
72
  return { direction, directionExtra };
73
73
  }
@@ -26,8 +26,8 @@ class IOMap {
26
26
  /** @type {!(GraphNode<OsmElement>[])} */
27
27
  entryPoints;
28
28
 
29
- /** @type {number[]} */
30
- disabledWays = [];
29
+ /** @type {Set<number>} */
30
+ disabledWays = new Set();
31
31
 
32
32
  /**
33
33
  * @param {Network} network The network of the map
@@ -198,13 +198,17 @@ class IOMap {
198
198
  }
199
199
 
200
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));
201
+ this.network.edges
202
+ .filter(edge => edge.builtFrom.id === osmId)
203
+ .forEach(e => this.router.disabledEdges.delete(e));
204
+ this.disabledWays.delete(osmId);
203
205
  }
204
206
 
205
207
  disableWay(osmId) {
206
- const edges = this.network.edges.filter(edge => edge.builtFrom.id === osmId);
207
- this.router.disabledEdges.push(...edges);
208
+ this.network.edges
209
+ .filter(edge => edge.builtFrom.id === osmId)
210
+ .forEach(e => this.router.disabledEdges.add(e));
211
+ this.disabledWays.add(osmId);
208
212
  }
209
213
  }
210
214