@wemap/routers 12.4.0 → 12.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.
- package/dist/index.js +20 -20
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +20 -20
- package/dist/index.mjs.map +1 -1
- package/index.ts +2 -2
- package/package.json +2 -2
- package/src/graph/GraphRouter.spec.ts +8 -1
- package/src/graph/GraphRouter.ts +1 -1
- package/src/wemap-multi/{CustomNetworkMap.spec.ts → CustomGraphMap.spec.ts} +8 -8
- package/src/wemap-multi/{CustomNetworkMap.ts → CustomGraphMap.ts} +2 -4
- package/src/wemap-multi/{CustomNetworkMapTester.spec.ts → CustomGraphMapTester.spec.ts} +3 -3
- package/src/wemap-multi/{CustomNetworkMapTester.ts → CustomGraphMapTester.ts} +13 -14
- package/src/wemap-multi/WemapMultiRouter.spec.ts +3 -3
- package/src/wemap-multi/WemapMultiRouter.ts +6 -6
package/index.ts
CHANGED
|
@@ -24,8 +24,8 @@ export { default as NoRouteFoundError } from './src/graph/NoRouteFoundError.js';
|
|
|
24
24
|
/* Wemap Router */
|
|
25
25
|
export { default as OsmGraphUtils } from './src/wemap-osm/OsmGraphUtils.js';
|
|
26
26
|
export { default as WemapMultiRouter } from './src/wemap-multi/WemapMultiRouter.js';
|
|
27
|
-
export { default as
|
|
28
|
-
export { default as
|
|
27
|
+
export { default as CustomGraphMap } from './src/wemap-multi/CustomGraphMap.js';
|
|
28
|
+
export { default as CustomGraphMapTester, type Report as CustomGraphMapTesterReport } from './src/wemap-multi/CustomGraphMapTester.js';
|
|
29
29
|
|
|
30
30
|
/* Other Routers */
|
|
31
31
|
export { default as OsrmRemoteRouter } from './src/remote/osrm/OsrmRemoteRouter.js';
|
package/package.json
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"directory": "packages/routers"
|
|
13
13
|
},
|
|
14
14
|
"name": "@wemap/routers",
|
|
15
|
-
"version": "12.
|
|
15
|
+
"version": "12.5.0",
|
|
16
16
|
"bugs": {
|
|
17
17
|
"url": "https://github.com/wemap/wemap-modules-js/issues"
|
|
18
18
|
},
|
|
@@ -52,5 +52,5 @@
|
|
|
52
52
|
},
|
|
53
53
|
"./helpers/*": "./helpers/*"
|
|
54
54
|
},
|
|
55
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "bf83b03a33aad6df5a09ce47b27bf4c6e9e53033"
|
|
56
56
|
}
|
|
@@ -293,7 +293,7 @@ describe('GraphRouter - Start and End projection on the same edge', () => {
|
|
|
293
293
|
];
|
|
294
294
|
|
|
295
295
|
const edges = [
|
|
296
|
-
new Edge(vertices[0], vertices[1], { name: 'e0' }),
|
|
296
|
+
new Edge(vertices[0], vertices[1], { name: 'e0', isOneway: true }),
|
|
297
297
|
];
|
|
298
298
|
|
|
299
299
|
const graph = new Graph(vertices, edges);
|
|
@@ -307,4 +307,11 @@ describe('GraphRouter - Start and End projection on the same edge', () => {
|
|
|
307
307
|
expect(route.hasRoute).is.true;
|
|
308
308
|
expect(route.edges.length).equals(1)
|
|
309
309
|
});
|
|
310
|
+
|
|
311
|
+
it('take shortest path oneway reverse', () => {
|
|
312
|
+
const router = new GraphRouter(graph);
|
|
313
|
+
const route = getShortestRoute(router, end, start);
|
|
314
|
+
expect(route.hasRoute).is.false;
|
|
315
|
+
expect(route.edges.length).equals(0)
|
|
316
|
+
});
|
|
310
317
|
});
|
package/src/graph/GraphRouter.ts
CHANGED
|
@@ -154,7 +154,7 @@ class GraphRouter extends GraphRouterEngine {
|
|
|
154
154
|
const distVertexAVertex1 = vertexA.distanceTo(edge.vertex1)
|
|
155
155
|
for (let j = i + 1; j < vertices.length; j++) {
|
|
156
156
|
const vertexB = vertices[j];
|
|
157
|
-
const distVertexBVertex1 =
|
|
157
|
+
const distVertexBVertex1 = vertexB.distanceTo(edge.vertex1)
|
|
158
158
|
const reverse = distVertexBVertex1 < distVertexAVertex1;
|
|
159
159
|
const newEdge = !reverse
|
|
160
160
|
? new Edge(vertexA, vertexB, newEdgesOptions)
|
|
@@ -3,7 +3,7 @@ import fs from 'fs';
|
|
|
3
3
|
import path from 'path';
|
|
4
4
|
import { fileURLToPath } from 'url';
|
|
5
5
|
|
|
6
|
-
import
|
|
6
|
+
import CustomGraphMap from './CustomGraphMap.js';
|
|
7
7
|
|
|
8
8
|
const { expect } = chai;
|
|
9
9
|
|
|
@@ -16,24 +16,24 @@ function getMapNameAndContents(assetName: string) {
|
|
|
16
16
|
return [mapName, osmXmlString];
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
describe('
|
|
19
|
+
describe('CustomGraphMap', () => {
|
|
20
20
|
|
|
21
21
|
|
|
22
22
|
it('fromOsmXml - biocbon-bergere-rdc-network', async () => {
|
|
23
23
|
|
|
24
24
|
const [mapName, mapContents] = getMapNameAndContents('biocbon-bergere-rdc-network.osm');
|
|
25
|
-
const
|
|
26
|
-
expect(
|
|
27
|
-
expect(
|
|
25
|
+
const customGraphMap = CustomGraphMap.fromOsmXml(mapContents, mapName)!;
|
|
26
|
+
expect(customGraphMap.entryPoints.length).equal(1);
|
|
27
|
+
expect(customGraphMap.graph.edges).is.not.empty;
|
|
28
28
|
|
|
29
29
|
});
|
|
30
30
|
|
|
31
31
|
it('fromOsmXml - gare-de-lest-network-pp-bounds', async () => {
|
|
32
32
|
|
|
33
33
|
const [mapName, mapContents] = getMapNameAndContents('gare-de-lest-network-pp-bounds.osm');
|
|
34
|
-
const
|
|
35
|
-
expect(
|
|
36
|
-
expect(
|
|
34
|
+
const customGraphMap = CustomGraphMap.fromOsmXml(mapContents, mapName)!;
|
|
35
|
+
expect(customGraphMap.entryPoints.length).equal(4);
|
|
36
|
+
expect(customGraphMap.graph.edges).is.not.empty;
|
|
37
37
|
|
|
38
38
|
});
|
|
39
39
|
|
|
@@ -18,7 +18,7 @@ export type ParsingErrors = {
|
|
|
18
18
|
routingBoundsNotFound: boolean
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
class
|
|
21
|
+
export default class CustomGraphMap {
|
|
22
22
|
|
|
23
23
|
name: string | null;
|
|
24
24
|
graph: Graph;
|
|
@@ -115,7 +115,7 @@ class CustomNetworkMap {
|
|
|
115
115
|
errors.routingBoundsNotFound = true;
|
|
116
116
|
}
|
|
117
117
|
callbackErrors?.(errors);
|
|
118
|
-
return new
|
|
118
|
+
return new CustomGraphMap(graph, entryPoints, bounds, name);
|
|
119
119
|
}
|
|
120
120
|
|
|
121
121
|
isPointInside(coordinates: Coordinates) {
|
|
@@ -211,5 +211,3 @@ class CustomNetworkMap {
|
|
|
211
211
|
}
|
|
212
212
|
|
|
213
213
|
}
|
|
214
|
-
|
|
215
|
-
export default CustomNetworkMap;
|
|
@@ -3,7 +3,7 @@ import fs from 'fs';
|
|
|
3
3
|
import path from 'path';
|
|
4
4
|
import { fileURLToPath } from 'url';
|
|
5
5
|
|
|
6
|
-
import
|
|
6
|
+
import CustomGraphMapTester from './CustomGraphMapTester.js';
|
|
7
7
|
|
|
8
8
|
const { expect } = chai;
|
|
9
9
|
|
|
@@ -12,10 +12,10 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
|
12
12
|
function createReport(fileName: string) {
|
|
13
13
|
const filePath = path.resolve(__dirname, '../../assets/' + fileName);
|
|
14
14
|
const osmXmlString = fs.readFileSync(filePath, 'utf8');
|
|
15
|
-
return
|
|
15
|
+
return CustomGraphMapTester.createReport(osmXmlString);
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
describe('
|
|
18
|
+
describe('CustomGraphMapTester', () => {
|
|
19
19
|
|
|
20
20
|
|
|
21
21
|
it('multiple-graph-components', async () => {
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
|
|
2
2
|
import { OsmNode } from '@wemap/osm';
|
|
3
3
|
|
|
4
|
-
import
|
|
4
|
+
import CustomGraphMap, { type ParsingErrors } from './CustomGraphMap.js';
|
|
5
5
|
import Vertex from '../graph/Vertex.js';
|
|
6
|
-
import Graph from '../graph/Graph.js';
|
|
7
6
|
|
|
8
7
|
export type Report = {
|
|
9
|
-
|
|
10
|
-
errors: Error[]
|
|
8
|
+
customGraphMap?: CustomGraphMap,
|
|
9
|
+
errors: Error[],
|
|
11
10
|
}
|
|
12
11
|
|
|
13
12
|
export type Error = CouldNotParseFileError
|
|
@@ -33,46 +32,46 @@ export type RoutingIoNotOnGraphError = {
|
|
|
33
32
|
data: OsmNode[]
|
|
34
33
|
}
|
|
35
34
|
|
|
36
|
-
export default class
|
|
35
|
+
export default class CustomGraphMapTester {
|
|
37
36
|
|
|
38
37
|
static createReport(osmXmlString: string): Report {
|
|
39
38
|
|
|
40
|
-
let
|
|
41
|
-
const
|
|
39
|
+
let customGraphMapErrors: ParsingErrors | undefined;
|
|
40
|
+
const customGraphMap = CustomGraphMap.fromOsmXml(osmXmlString, null, e => (customGraphMapErrors = e));
|
|
42
41
|
const errors: Error[] = [];
|
|
43
42
|
|
|
44
|
-
if (
|
|
43
|
+
if (customGraphMapErrors?.couldNotParseFile || !customGraphMap) {
|
|
45
44
|
errors.push({
|
|
46
45
|
type: 'could-not-parse-file'
|
|
47
46
|
});
|
|
48
47
|
return { errors };
|
|
49
48
|
}
|
|
50
49
|
|
|
51
|
-
const components =
|
|
50
|
+
const components = customGraphMap.router.calculateComponents();
|
|
52
51
|
if (components.length > 1) {
|
|
53
52
|
errors.push({
|
|
54
53
|
type: 'multiple-graph-components',
|
|
55
54
|
data: components
|
|
56
55
|
});
|
|
57
56
|
}
|
|
58
|
-
if (
|
|
57
|
+
if (customGraphMapErrors?.routingBoundsNotFound) {
|
|
59
58
|
errors.push({
|
|
60
59
|
type: 'routing-bounds-not-found'
|
|
61
60
|
});
|
|
62
61
|
}
|
|
63
|
-
if (
|
|
62
|
+
if (customGraphMapErrors?.routingIoNotFound?.length) {
|
|
64
63
|
errors.push({
|
|
65
64
|
type: 'routing-io-not-on-graph',
|
|
66
|
-
data:
|
|
65
|
+
data: customGraphMapErrors.routingIoNotFound
|
|
67
66
|
});
|
|
68
67
|
}
|
|
69
68
|
|
|
70
|
-
return {
|
|
69
|
+
return { customGraphMap, errors };
|
|
71
70
|
}
|
|
72
71
|
|
|
73
72
|
static reportToJson(report: Report) {
|
|
74
73
|
return {
|
|
75
|
-
graph: report.graph?.toCompressedJson(),
|
|
74
|
+
graph: report.customGraphMap?.graph?.toCompressedJson(),
|
|
76
75
|
errors: report.errors.map(error => {
|
|
77
76
|
if (error.type === 'multiple-graph-components') {
|
|
78
77
|
return { type: error.type, data: error.data.map(c => c.map(v => v.id)) };
|
|
@@ -6,7 +6,7 @@ import fetchMock from 'fetch-mock';
|
|
|
6
6
|
|
|
7
7
|
import { Coordinates } from '@wemap/geo';
|
|
8
8
|
|
|
9
|
-
import
|
|
9
|
+
import CustomGraphMap from './CustomGraphMap.js';
|
|
10
10
|
import WemapMultiRouter from './WemapMultiRouter.js';
|
|
11
11
|
import OsrmRemoteRouter from '../remote/osrm/OsrmRemoteRouter.js';
|
|
12
12
|
import { type RouterRequest } from '../model/RouterRequest.js';
|
|
@@ -30,14 +30,14 @@ function createIOMapFromAsset(assetName: string) {
|
|
|
30
30
|
const filePath = path.resolve(__dirname, '../../assets/' + assetName);
|
|
31
31
|
const osmXmlString = fs.readFileSync(filePath, 'utf8');
|
|
32
32
|
const mapName = path.parse(assetName).name;
|
|
33
|
-
return
|
|
33
|
+
return CustomGraphMap.fromOsmXml(osmXmlString, mapName)!;
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
describe('WemapMultiRouter', () => {
|
|
37
37
|
|
|
38
38
|
|
|
39
39
|
let router: WemapMultiRouter;
|
|
40
|
-
let garedelestMap:
|
|
40
|
+
let garedelestMap: CustomGraphMap, biocbonMap: CustomGraphMap;
|
|
41
41
|
const travelMode = 'WALK';
|
|
42
42
|
const fallbackStrategy: RoutingFallbackStrategy = [{
|
|
43
43
|
name: OsrmRemoteRouter.rname,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* eslint-disable complexity */
|
|
2
2
|
/* eslint-disable max-statements */
|
|
3
3
|
|
|
4
|
-
import
|
|
4
|
+
import CustomGraphMap from './CustomGraphMap.js';
|
|
5
5
|
import RemoteRouterManager, { type RoutingFallbackStrategy } from '../remote/RemoteRouterManager.js';
|
|
6
6
|
import Itinerary from '../model/Itinerary.js';
|
|
7
7
|
import WemapMultiRemoteRouter from '../remote/wemap-multi/WemapMultiRemoteRouter.js';
|
|
@@ -13,18 +13,18 @@ import { RemoteRoutingError, WemapMultiRoutingError } from '../RoutingError.js';
|
|
|
13
13
|
|
|
14
14
|
class WemapMultiRouter {
|
|
15
15
|
|
|
16
|
-
maps:
|
|
16
|
+
maps: CustomGraphMap[] = [];
|
|
17
17
|
|
|
18
18
|
get rname() {
|
|
19
19
|
return 'wemap-multi';
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
addIOMap(
|
|
23
|
-
this.maps.push(
|
|
22
|
+
addIOMap(customGraphMap: CustomGraphMap) {
|
|
23
|
+
this.maps.push(customGraphMap);
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
removeIOMap(
|
|
27
|
-
this.maps = this.maps.filter(map => map !==
|
|
26
|
+
removeIOMap(customGraphMap: CustomGraphMap) {
|
|
27
|
+
this.maps = this.maps.filter(map => map !== customGraphMap);
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
removeAllMaps() {
|