@wemap/osm 3.2.14 → 3.2.16
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.js +6 -0
- package/package.json +5 -5
- package/src/model/OsmElement.js +10 -3
- package/src/model/OsmModel.js +29 -0
- package/src/model/OsmNode.js +17 -0
- package/src/model/OsmParser.js +8 -4
- package/src/model/OsmWay.js +30 -0
- package/src/network/OsmNetwork.js +24 -2
- package/src/network/OsmRouter.js +20 -2
- package/src/network/OsmRouter.spec.js +1 -1
- package/src/osrm/OsrmUtils.js +7 -3
package/index.js
CHANGED
|
@@ -1,13 +1,19 @@
|
|
|
1
|
+
import OsmElement from './src/model/OsmElement.js';
|
|
1
2
|
import OsmModel from './src/model/OsmModel.js';
|
|
2
3
|
import OsmNetwork from './src/network/OsmNetwork.js';
|
|
4
|
+
import OsmNode from './src/model/OsmNode.js';
|
|
3
5
|
import OsmParser from './src/model/OsmParser.js';
|
|
4
6
|
import OsmRouter from './src/network/OsmRouter.js';
|
|
7
|
+
import OsmWay from './src/model/OsmWay.js';
|
|
5
8
|
import OsrmUtils from './src/osrm/OsrmUtils.js';
|
|
6
9
|
|
|
7
10
|
export {
|
|
11
|
+
OsmElement,
|
|
8
12
|
OsmModel,
|
|
9
13
|
OsmNetwork,
|
|
14
|
+
OsmNode,
|
|
10
15
|
OsmParser,
|
|
11
16
|
OsmRouter,
|
|
17
|
+
OsmWay,
|
|
12
18
|
OsrmUtils
|
|
13
19
|
};
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"directory": "packages/osm"
|
|
12
12
|
},
|
|
13
13
|
"name": "@wemap/osm",
|
|
14
|
-
"version": "3.2.
|
|
14
|
+
"version": "3.2.16",
|
|
15
15
|
"bugs": {
|
|
16
16
|
"url": "https://github.com/wemap/wemap-modules-js/issues"
|
|
17
17
|
},
|
|
@@ -25,11 +25,11 @@
|
|
|
25
25
|
],
|
|
26
26
|
"license": "ISC",
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@wemap/geo": "^3.2.
|
|
29
|
-
"@wemap/graph": "^3.2.
|
|
28
|
+
"@wemap/geo": "^3.2.16",
|
|
29
|
+
"@wemap/graph": "^3.2.16",
|
|
30
30
|
"@wemap/logger": "^3.2.3",
|
|
31
|
-
"@wemap/maths": "^3.2.
|
|
31
|
+
"@wemap/maths": "^3.2.15",
|
|
32
32
|
"sax": "^1.2.4"
|
|
33
33
|
},
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "01e6c2ed3b4f24b230cb6a774fe159e7b20b810a"
|
|
35
35
|
}
|
package/src/model/OsmElement.js
CHANGED
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
class OsmElement {
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
/** @type {number|null} */
|
|
4
|
+
id;
|
|
5
|
+
|
|
6
|
+
/** @type {object} */
|
|
4
7
|
tags;
|
|
5
8
|
|
|
6
|
-
|
|
9
|
+
/**
|
|
10
|
+
* @param {number} id
|
|
11
|
+
* @param {object} tags
|
|
12
|
+
*/
|
|
13
|
+
constructor(id, tags) {
|
|
7
14
|
this.id = id;
|
|
8
|
-
this.tags = tags;
|
|
15
|
+
this.tags = tags || {};
|
|
9
16
|
}
|
|
10
17
|
}
|
|
11
18
|
|
package/src/model/OsmModel.js
CHANGED
|
@@ -1,23 +1,52 @@
|
|
|
1
|
+
import OsmNode from './OsmNode.js';
|
|
2
|
+
import OsmWay from './OsmWay.js';
|
|
3
|
+
|
|
1
4
|
class OsmModel {
|
|
2
5
|
|
|
6
|
+
/** @type {OsmNode[]} */
|
|
7
|
+
nodes;
|
|
8
|
+
|
|
9
|
+
/** @type {OsmWay[]} */
|
|
10
|
+
ways;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @param {OsmNode[]|undefined} nodes
|
|
14
|
+
* @param {OsmWay[]|undefined} ways
|
|
15
|
+
*/
|
|
3
16
|
constructor(nodes, ways) {
|
|
4
17
|
this.nodes = nodes || [];
|
|
5
18
|
this.ways = ways || [];
|
|
6
19
|
}
|
|
7
20
|
|
|
21
|
+
/**
|
|
22
|
+
* @param {number} id
|
|
23
|
+
* @returns {OsmNode|null}
|
|
24
|
+
*/
|
|
8
25
|
getNodeById(id) {
|
|
9
26
|
return this.nodes.find(node => node.id === id) || null;
|
|
10
27
|
}
|
|
11
28
|
|
|
29
|
+
/**
|
|
30
|
+
* @param {string} name
|
|
31
|
+
* @returns {OsmNode|null}
|
|
32
|
+
*/
|
|
12
33
|
getNodeByName(name) {
|
|
13
34
|
return this.nodes.find(node => node.tags.name === name) || null;
|
|
14
35
|
}
|
|
15
36
|
|
|
16
37
|
|
|
38
|
+
/**
|
|
39
|
+
* @param {number} id
|
|
40
|
+
* @returns {OsmWay|null}
|
|
41
|
+
*/
|
|
17
42
|
getWayById(id) {
|
|
18
43
|
return this.ways.find(way => way.id === id) || null;
|
|
19
44
|
}
|
|
20
45
|
|
|
46
|
+
/**
|
|
47
|
+
* @param {string} name
|
|
48
|
+
* @returns {OsmWay|null}
|
|
49
|
+
*/
|
|
21
50
|
getWayByName(name) {
|
|
22
51
|
return this.ways.find(way => way.tags.name === name) || null;
|
|
23
52
|
}
|
package/src/model/OsmNode.js
CHANGED
|
@@ -1,19 +1,36 @@
|
|
|
1
|
+
import { Coordinates } from '@wemap/geo';
|
|
2
|
+
|
|
1
3
|
import OsmElement from './OsmElement.js';
|
|
4
|
+
import OsmWay from './OsmWay.js';
|
|
2
5
|
|
|
3
6
|
class OsmNode extends OsmElement {
|
|
4
7
|
|
|
8
|
+
/** @type {Coordinates} */
|
|
5
9
|
coords = null;
|
|
10
|
+
|
|
11
|
+
/** @type {OsmWay[]} */
|
|
6
12
|
ways = [];
|
|
7
13
|
|
|
14
|
+
/**
|
|
15
|
+
* @param {number} id
|
|
16
|
+
* @param {Coordinates} coords
|
|
17
|
+
* @param {object} tags
|
|
18
|
+
*/
|
|
8
19
|
constructor(id, coords, tags) {
|
|
9
20
|
super(id, tags);
|
|
10
21
|
this.coords = coords;
|
|
11
22
|
}
|
|
12
23
|
|
|
24
|
+
/**
|
|
25
|
+
* @returns {boolean}
|
|
26
|
+
*/
|
|
13
27
|
get isElevator() {
|
|
14
28
|
return this.tags.highway === 'elevator';
|
|
15
29
|
}
|
|
16
30
|
|
|
31
|
+
/**
|
|
32
|
+
* @returns {boolean}
|
|
33
|
+
*/
|
|
17
34
|
get isConveying() {
|
|
18
35
|
return this.isElevator;
|
|
19
36
|
}
|
package/src/model/OsmParser.js
CHANGED
|
@@ -11,6 +11,10 @@ import OsmWay from './OsmWay.js';
|
|
|
11
11
|
|
|
12
12
|
class OsmParser {
|
|
13
13
|
|
|
14
|
+
/**
|
|
15
|
+
* @param {string} osmXmlString
|
|
16
|
+
* @returns {OsmModel}
|
|
17
|
+
*/
|
|
14
18
|
static parseOsmXmlString(osmXmlString) {
|
|
15
19
|
|
|
16
20
|
const model = new OsmModel();
|
|
@@ -28,7 +32,7 @@ class OsmParser {
|
|
|
28
32
|
buffer = null;
|
|
29
33
|
break;
|
|
30
34
|
}
|
|
31
|
-
const osmNode = this.
|
|
35
|
+
const osmNode = this._parseNode(node.attributes);
|
|
32
36
|
buffer = osmNode;
|
|
33
37
|
model.nodes.push(osmNode);
|
|
34
38
|
break;
|
|
@@ -38,7 +42,7 @@ class OsmParser {
|
|
|
38
42
|
buffer = null;
|
|
39
43
|
break;
|
|
40
44
|
}
|
|
41
|
-
const osmWay = this.
|
|
45
|
+
const osmWay = this._parseWay(node.attributes);
|
|
42
46
|
buffer = osmWay;
|
|
43
47
|
model.ways.push(osmWay);
|
|
44
48
|
break;
|
|
@@ -83,13 +87,13 @@ class OsmParser {
|
|
|
83
87
|
}
|
|
84
88
|
|
|
85
89
|
|
|
86
|
-
static
|
|
90
|
+
static _parseNode(attr) {
|
|
87
91
|
return new OsmNode(
|
|
88
92
|
Number(attr.id),
|
|
89
93
|
new Coordinates(Number(attr.lat), Number(attr.lon)));
|
|
90
94
|
}
|
|
91
95
|
|
|
92
|
-
static
|
|
96
|
+
static _parseWay(attr) {
|
|
93
97
|
return new OsmWay(Number(attr.id));
|
|
94
98
|
}
|
|
95
99
|
}
|
package/src/model/OsmWay.js
CHANGED
|
@@ -1,29 +1,59 @@
|
|
|
1
|
+
import { Level } from '@wemap/geo';
|
|
2
|
+
|
|
1
3
|
import OsmElement from './OsmElement.js';
|
|
4
|
+
import OsmNode from './OsmNode.js';
|
|
2
5
|
|
|
3
6
|
class OsmWay extends OsmElement {
|
|
4
7
|
|
|
8
|
+
/** @type {OsmNode[]} */
|
|
5
9
|
nodes = [];
|
|
10
|
+
|
|
11
|
+
/** @type {Level} */
|
|
6
12
|
level = null;
|
|
7
13
|
|
|
14
|
+
/**
|
|
15
|
+
* @param {number} id
|
|
16
|
+
* @param {object} tags
|
|
17
|
+
*/
|
|
8
18
|
constructor(id, tags) {
|
|
9
19
|
super(id, tags);
|
|
10
20
|
}
|
|
11
21
|
|
|
22
|
+
/**
|
|
23
|
+
* @returns {boolean}
|
|
24
|
+
*/
|
|
12
25
|
get areStairs() {
|
|
13
26
|
return this.tags.highway === 'steps';
|
|
14
27
|
}
|
|
15
28
|
|
|
29
|
+
/**
|
|
30
|
+
* @returns {boolean}
|
|
31
|
+
*/
|
|
16
32
|
get isConveying() {
|
|
17
33
|
return this.tags.hasOwnProperty('conveying');
|
|
18
34
|
}
|
|
19
35
|
|
|
36
|
+
/**
|
|
37
|
+
* @returns {boolean}
|
|
38
|
+
*/
|
|
20
39
|
get isEscalator() {
|
|
21
40
|
return this.areStairs && this.isConveying;
|
|
22
41
|
}
|
|
23
42
|
|
|
43
|
+
/**
|
|
44
|
+
* @returns {boolean}
|
|
45
|
+
*/
|
|
24
46
|
get isMovingWalkway() {
|
|
25
47
|
return !this.areStairs && this.isConveying;
|
|
26
48
|
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* @returns {boolean}
|
|
52
|
+
*/
|
|
53
|
+
get isArea() {
|
|
54
|
+
// That is not the real definition for OSM
|
|
55
|
+
return this.nodes[0] === this.nodes[this.nodes.length - 1];
|
|
56
|
+
}
|
|
27
57
|
}
|
|
28
58
|
|
|
29
59
|
export default OsmWay;
|
|
@@ -3,6 +3,8 @@ import {
|
|
|
3
3
|
Edge, Node, Network
|
|
4
4
|
} from '@wemap/graph';
|
|
5
5
|
|
|
6
|
+
import OsmModel from '../model/OsmModel.js';
|
|
7
|
+
|
|
6
8
|
const HIGHWAYS_PEDESTRIANS = ['footway', 'steps', 'pedestrian', 'living_street', 'path', 'track', 'sidewalk'];
|
|
7
9
|
const DEFAULT_WAY_SELECTOR = way => HIGHWAYS_PEDESTRIANS.includes(way.tags.highway) || way.tags.footway === 'sidewalk';
|
|
8
10
|
|
|
@@ -11,6 +13,11 @@ const DEFAULT_WAY_SELECTOR = way => HIGHWAYS_PEDESTRIANS.includes(way.tags.highw
|
|
|
11
13
|
*/
|
|
12
14
|
class OsmNetwork extends Network {
|
|
13
15
|
|
|
16
|
+
/**
|
|
17
|
+
* @param {OsmModel} osmModel
|
|
18
|
+
* @param {function} _waySelectionFilter
|
|
19
|
+
* @returns {OsmNetwork}
|
|
20
|
+
*/
|
|
14
21
|
static fromOsmModel(osmModel, _waySelectionFilter) {
|
|
15
22
|
|
|
16
23
|
const waySelectionFilter = _waySelectionFilter || DEFAULT_WAY_SELECTOR;
|
|
@@ -48,7 +55,7 @@ class OsmNetwork extends Network {
|
|
|
48
55
|
networkModel.nodes.forEach(node => {
|
|
49
56
|
if (node.data.tags.highway === 'elevator') {
|
|
50
57
|
// We have to clone this node for each connected edge
|
|
51
|
-
OsmNetwork.
|
|
58
|
+
OsmNetwork._createNodesAndEdgesFromElevator(networkModel, node);
|
|
52
59
|
}
|
|
53
60
|
});
|
|
54
61
|
|
|
@@ -57,7 +64,7 @@ class OsmNetwork extends Network {
|
|
|
57
64
|
return networkModel;
|
|
58
65
|
}
|
|
59
66
|
|
|
60
|
-
static
|
|
67
|
+
static _createNodesAndEdgesFromElevator(networkModel, node) {
|
|
61
68
|
|
|
62
69
|
const createdNodes = [];
|
|
63
70
|
const isLevelAlreadyCreated = level => createdNodes.some(
|
|
@@ -110,18 +117,33 @@ class OsmNetwork extends Network {
|
|
|
110
117
|
);
|
|
111
118
|
}
|
|
112
119
|
|
|
120
|
+
/**
|
|
121
|
+
* @param {number} id
|
|
122
|
+
* @returns {Node}
|
|
123
|
+
*/
|
|
113
124
|
getNodeById(id) {
|
|
114
125
|
return this.nodes.find(node => node.data.id === id);
|
|
115
126
|
}
|
|
116
127
|
|
|
128
|
+
/**
|
|
129
|
+
* @param {name} name
|
|
130
|
+
* @returns {Node}
|
|
131
|
+
*/
|
|
117
132
|
getNodeByName(name) {
|
|
118
133
|
return this.nodes.find(node => node.data.tags.name === name);
|
|
119
134
|
}
|
|
120
135
|
|
|
136
|
+
/**
|
|
137
|
+
* @param {number} id
|
|
138
|
+
* @returns {Edge[]}
|
|
139
|
+
*/
|
|
121
140
|
getEdgesById(id) {
|
|
122
141
|
return this.edges.filter(edge => edge.data.id === id);
|
|
123
142
|
}
|
|
124
143
|
|
|
144
|
+
/**
|
|
145
|
+
* @returns {string}
|
|
146
|
+
*/
|
|
125
147
|
toDetailedString() {
|
|
126
148
|
return super.toDetailedString(
|
|
127
149
|
node => node.data.tags.name,
|
package/src/network/OsmRouter.js
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
1
|
+
import { Coordinates } from '@wemap/geo';
|
|
1
2
|
import {
|
|
2
|
-
GraphRouter, Utils
|
|
3
|
+
Edge, GraphRouter, Node, Utils
|
|
3
4
|
} from '@wemap/graph';
|
|
4
5
|
|
|
5
6
|
const DEFAULT_OPTIONS = { useStairs: true };
|
|
6
7
|
|
|
7
8
|
class OsmRouter extends GraphRouter {
|
|
8
9
|
|
|
10
|
+
/**
|
|
11
|
+
* @param {Node|Coordinates} start
|
|
12
|
+
* @param {Node|Coordinates} end
|
|
13
|
+
* @param {object} _options
|
|
14
|
+
*/
|
|
9
15
|
getShortestPath(start, end, _options) {
|
|
10
16
|
|
|
11
17
|
const options = Object.assign({}, DEFAULT_OPTIONS, _options);
|
|
@@ -18,8 +24,11 @@ class OsmRouter extends GraphRouter {
|
|
|
18
24
|
);
|
|
19
25
|
}
|
|
20
26
|
|
|
27
|
+
/**
|
|
28
|
+
* @param {Edge} edge
|
|
29
|
+
* @returns {boolean}
|
|
30
|
+
*/
|
|
21
31
|
static edgeSelectionFilter = edge => {
|
|
22
|
-
|
|
23
32
|
return !edge.data || !edge.data.tags
|
|
24
33
|
|| (
|
|
25
34
|
edge.data.tags.stairs !== 'yes'
|
|
@@ -27,6 +36,10 @@ class OsmRouter extends GraphRouter {
|
|
|
27
36
|
);
|
|
28
37
|
}
|
|
29
38
|
|
|
39
|
+
/**
|
|
40
|
+
* @param {Edge} edge
|
|
41
|
+
* @returns {boolean}
|
|
42
|
+
*/
|
|
30
43
|
static edgeWeightFn = edge => {
|
|
31
44
|
if (edge.data.tags.highway === 'elevator') {
|
|
32
45
|
return 30;
|
|
@@ -34,6 +47,11 @@ class OsmRouter extends GraphRouter {
|
|
|
34
47
|
return Utils.getDurationFromLength(edge.length);
|
|
35
48
|
};
|
|
36
49
|
|
|
50
|
+
/**
|
|
51
|
+
* @param {Edge} edge
|
|
52
|
+
* @param {boolean} reversed
|
|
53
|
+
* @returns {boolean}
|
|
54
|
+
*/
|
|
37
55
|
static acceptOneWayFn = (edge, reversed) => {
|
|
38
56
|
const {
|
|
39
57
|
oneway, highway, conveying
|
|
@@ -80,7 +80,7 @@ describe('OsmRouter - Multi-level itinerary', () => {
|
|
|
80
80
|
it('router returns shortest path 2', () => {
|
|
81
81
|
|
|
82
82
|
const start = new Coordinates(43.609219, 3.8841743, null, new Level(2));
|
|
83
|
-
const end = new Coordinates(43.
|
|
83
|
+
const end = new Coordinates(43.60917216742, 3.8842355275, null, new Level(2));
|
|
84
84
|
const itinerary2 = router.getShortestPath(start, end);
|
|
85
85
|
|
|
86
86
|
expect(itinerary2.nodes.length).equal(3);
|
package/src/osrm/OsrmUtils.js
CHANGED
|
@@ -15,6 +15,10 @@ import OsmWay from '../model/OsmWay.js';
|
|
|
15
15
|
|
|
16
16
|
class OsrmUtils {
|
|
17
17
|
|
|
18
|
+
/**
|
|
19
|
+
* @param {Itinerary} itinerary
|
|
20
|
+
* @returns {object}
|
|
21
|
+
*/
|
|
18
22
|
static itineraryToOsrmJson(itinerary) {
|
|
19
23
|
|
|
20
24
|
const itinerarySteps = itinerary.steps;
|
|
@@ -114,7 +118,7 @@ class OsrmUtils {
|
|
|
114
118
|
|
|
115
119
|
/**
|
|
116
120
|
* Generate Itinerary from OSRM JSON, start and end.
|
|
117
|
-
* @param {
|
|
121
|
+
* @param {object} json JSON file provided by OSRM.
|
|
118
122
|
* @param {Coordinates} start itinerary start
|
|
119
123
|
* @param {Coordinates} end itinerary end
|
|
120
124
|
*/
|
|
@@ -148,13 +152,13 @@ class OsrmUtils {
|
|
|
148
152
|
|
|
149
153
|
if (legs && legs[0]) {
|
|
150
154
|
const { steps } = legs[0];
|
|
151
|
-
OsrmUtils.
|
|
155
|
+
OsrmUtils._parseSteps(itinerary, steps);
|
|
152
156
|
}
|
|
153
157
|
|
|
154
158
|
return itinerary;
|
|
155
159
|
}
|
|
156
160
|
|
|
157
|
-
static
|
|
161
|
+
static _parseSteps(itinerary, jsonSteps) {
|
|
158
162
|
|
|
159
163
|
itinerary._steps = [];
|
|
160
164
|
itinerary._nextStepsIndexes = [];
|