@wemap/routers 10.4.0 → 10.5.1

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/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.4.0",
15
+ "version": "10.5.1",
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.1",
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.1"
37
37
  },
38
- "gitHead": "00c259754b234de1d75a307f543badda8f6f0771"
38
+ "gitHead": "ce2d0e4a541b521098e5382bd665dc54805f1c27"
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 {Set<number>} */
30
+ disabledWays = new Set();
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,20 @@ 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
+ this.network.edges
202
+ .filter(edge => edge.builtFrom.id === osmId)
203
+ .forEach(e => this.router.disabledEdges.delete(e));
204
+ this.disabledWays.delete(osmId);
205
+ }
206
+
207
+ disableWay(osmId) {
208
+ this.network.edges
209
+ .filter(edge => edge.builtFrom.id === osmId)
210
+ .forEach(e => this.router.disabledEdges.add(e));
211
+ this.disabledWays.add(osmId);
212
+ }
192
213
  }
193
214
 
194
215
  export default IOMap;