@wemap/routers 11.0.0-alpha.15 → 11.0.0-alpha.18
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 +23 -7
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +25 -9
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -6
- package/src/wemap-multi/CustomNetworkMap.ts +29 -8
- package/src/wemap-multi/WemapMultiRouter.ts +1 -1
package/package.json
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"directory": "packages/routers"
|
|
13
13
|
},
|
|
14
14
|
"name": "@wemap/routers",
|
|
15
|
-
"version": "11.0.0-alpha.
|
|
15
|
+
"version": "11.0.0-alpha.18",
|
|
16
16
|
"bugs": {
|
|
17
17
|
"url": "https://github.com/wemap/wemap-modules-js/issues"
|
|
18
18
|
},
|
|
@@ -34,10 +34,10 @@
|
|
|
34
34
|
"@turf/convex": "^6.5.0",
|
|
35
35
|
"@turf/helpers": "^6.5.0",
|
|
36
36
|
"@types/mapbox__polyline": "^1.0.2",
|
|
37
|
-
"@wemap/geo": "^11.0.0-alpha.
|
|
38
|
-
"@wemap/logger": "^11.0.0-alpha.
|
|
39
|
-
"@wemap/maths": "^11.0.0-alpha.
|
|
40
|
-
"@wemap/osm": "^11.0.0-alpha.
|
|
37
|
+
"@wemap/geo": "^11.0.0-alpha.16",
|
|
38
|
+
"@wemap/logger": "^11.0.0-alpha.16",
|
|
39
|
+
"@wemap/maths": "^11.0.0-alpha.16",
|
|
40
|
+
"@wemap/osm": "^11.0.0-alpha.18"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@types/fetch-mock": "^7.3.5",
|
|
@@ -50,5 +50,5 @@
|
|
|
50
50
|
"require": "./dist/index.js"
|
|
51
51
|
}
|
|
52
52
|
},
|
|
53
|
-
"gitHead": "
|
|
53
|
+
"gitHead": "46bef48dec0bce16030ab353c300db8d0f649bd1"
|
|
54
54
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import pointInPolygon from '@turf/boolean-point-in-polygon';
|
|
2
2
|
import convexHullFn from '@turf/convex';
|
|
3
|
-
import {
|
|
3
|
+
import { Position, MultiPolygon } from '@turf/helpers';
|
|
4
4
|
|
|
5
5
|
import { Coordinates, NoRouteFoundError } from '@wemap/geo';
|
|
6
6
|
import { OsmParser, OsmNetworkUtils, OsmNetwork, OsmGraphNode } from '@wemap/osm';
|
|
@@ -13,14 +13,14 @@ class CustomNetworkMap {
|
|
|
13
13
|
name: string | null;
|
|
14
14
|
network: OsmNetwork;
|
|
15
15
|
router: WemapOsmRouter;
|
|
16
|
-
bounds:
|
|
16
|
+
bounds: MultiPolygon;
|
|
17
17
|
entryPoints: OsmGraphNode[];
|
|
18
18
|
disabledWays = new Set<number>();
|
|
19
19
|
|
|
20
20
|
constructor(
|
|
21
21
|
network: OsmNetwork,
|
|
22
22
|
entryPoints: OsmGraphNode[],
|
|
23
|
-
bounds:
|
|
23
|
+
bounds: MultiPolygon | null = null,
|
|
24
24
|
name: string | null = null) {
|
|
25
25
|
|
|
26
26
|
this.name = name;
|
|
@@ -37,14 +37,17 @@ class CustomNetworkMap {
|
|
|
37
37
|
|
|
38
38
|
// Bounds
|
|
39
39
|
if (bounds) {
|
|
40
|
-
this.bounds =
|
|
40
|
+
this.bounds = bounds;
|
|
41
41
|
} else {
|
|
42
42
|
const polygon = [network.nodes.map(node => [node.coords.lng, node.coords.lat] as Position)];
|
|
43
43
|
const convexHull = convexHullFn({ type: 'polygon', coordinates: polygon });
|
|
44
44
|
if (!convexHull) {
|
|
45
45
|
throw new Error(`Cannot calculate convexHull of network "${name}"`);
|
|
46
46
|
}
|
|
47
|
-
this.bounds =
|
|
47
|
+
this.bounds = {
|
|
48
|
+
type: 'MultiPolygon',
|
|
49
|
+
coordinates: [convexHull.geometry.coordinates]
|
|
50
|
+
};
|
|
48
51
|
}
|
|
49
52
|
}
|
|
50
53
|
|
|
@@ -63,11 +66,29 @@ class CustomNetworkMap {
|
|
|
63
66
|
throw new Error('Cannot parse wemap:routing-io correctly');
|
|
64
67
|
}
|
|
65
68
|
|
|
66
|
-
const
|
|
67
|
-
|
|
69
|
+
const bounds: MultiPolygon = {
|
|
70
|
+
type: 'MultiPolygon',
|
|
71
|
+
coordinates: []
|
|
72
|
+
};
|
|
73
|
+
osmModel.ways
|
|
74
|
+
.filter(({ tags }) => tags['wemap:routing-bounds'])
|
|
75
|
+
.forEach(way => {
|
|
76
|
+
bounds.coordinates.push([way.nodes.reduce((acc, node) => {
|
|
77
|
+
acc.push([node.coords.lng, node.coords.lat]);
|
|
78
|
+
return acc;
|
|
79
|
+
}, [] as Position[])
|
|
80
|
+
]);
|
|
81
|
+
});
|
|
82
|
+
osmModel.relations
|
|
83
|
+
.filter(rel => rel.tags['wemap:routing-bounds'] && rel.isMultipolygon())
|
|
84
|
+
.forEach(rel => {
|
|
85
|
+
const polygon = rel.getGeoJsonPolygon();
|
|
86
|
+
polygon && bounds.coordinates.push(polygon.coordinates);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
if (!bounds.coordinates.length) {
|
|
68
90
|
throw new Error('Search bounds is undefined. Please use OSM tag : "wemap:routing-bounds=yes"');
|
|
69
91
|
}
|
|
70
|
-
const bounds = wayBounds.nodes.map(node => node.coords);
|
|
71
92
|
return new CustomNetworkMap(network, entryPoints, bounds, name);
|
|
72
93
|
}
|
|
73
94
|
|
|
@@ -124,7 +124,7 @@ class WemapMultiRouter {
|
|
|
124
124
|
const mapWithStart = ioMapsToTest.find(map => map.isPointInside(start));
|
|
125
125
|
|
|
126
126
|
// Create WemapOsmRouterOptions from WemapMultiRouterOptions
|
|
127
|
-
const wemapOsmRouterOptions = !options || !('useStairs' in options)
|
|
127
|
+
const wemapOsmRouterOptions = !options || !('useStairs' in options) || options.useStairs
|
|
128
128
|
? WemapOsmRouterOptions.DEFAULT
|
|
129
129
|
: WemapOsmRouterOptions.WITHOUT_STAIRS;
|
|
130
130
|
|