@wemap/positioning 2.4.0 → 2.4.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.
- package/package.json +4 -6
- package/src/components/PositioningPoseComponent.jsx +8 -0
- package/src/components/Utils.js +33 -0
- package/src/providers/ProvidersLogger.js +1 -1
- package/src/providers/others/MapMatchingProvider.js +7 -66
- package/src/providers/pose/GnssWifiPdrProvider.js +5 -7
- package/src/providers/pose/pdr/PdrProvider.js +1 -1
package/package.json
CHANGED
|
@@ -8,14 +8,12 @@
|
|
|
8
8
|
"Guillaume Pannetier <guillaume.pannetier@getwemap.com>"
|
|
9
9
|
],
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"@wemap/geo": "^0.
|
|
11
|
+
"@wemap/geo": "^0.3.1",
|
|
12
12
|
"@wemap/logger": "^0.1.5",
|
|
13
|
-
"@wemap/maths": "^0.2.
|
|
14
|
-
"@wemap/osm": "^0.
|
|
13
|
+
"@wemap/maths": "^0.2.1",
|
|
14
|
+
"@wemap/osm": "^0.2.1",
|
|
15
15
|
"@wemap/utils": "^0.1.2",
|
|
16
|
-
"file-saver": "^2.0.2",
|
|
17
16
|
"geomagnetism": "^0.1.0",
|
|
18
|
-
"jszip": "^3.2.2",
|
|
19
17
|
"lodash.isempty": "^4.4.0",
|
|
20
18
|
"lodash.isnumber": "^3.0.3",
|
|
21
19
|
"lodash.noop": "^3.0.1"
|
|
@@ -82,5 +80,5 @@
|
|
|
82
80
|
"lint": "eslint --ext .js,.jsx --quiet src",
|
|
83
81
|
"test": "mocha -r esm \"src/**/*.spec.js\""
|
|
84
82
|
},
|
|
85
|
-
"version": "2.4.
|
|
83
|
+
"version": "2.4.2"
|
|
86
84
|
}
|
|
@@ -83,6 +83,12 @@ class PositioningPoseComponent extends React.Component {
|
|
|
83
83
|
const attitudeRender = Utils.renderAttitude(this.state.attitude);
|
|
84
84
|
const positionRender = Utils.renderPosition(this.state.position);
|
|
85
85
|
|
|
86
|
+
const itineraryRender = Utils.renderItineraryInfo(
|
|
87
|
+
this.state.position && !(this.state.position instanceof Error)
|
|
88
|
+
? Utils.ITINERARY.getInfo(this.state.position)
|
|
89
|
+
: null
|
|
90
|
+
);
|
|
91
|
+
|
|
86
92
|
return (
|
|
87
93
|
<div>
|
|
88
94
|
<StartStopComponent
|
|
@@ -98,6 +104,8 @@ class PositioningPoseComponent extends React.Component {
|
|
|
98
104
|
<h3>Map</h3>
|
|
99
105
|
<MapComponent ref={map => (this.map = map)}
|
|
100
106
|
network={Utils.ITINERARY} />
|
|
107
|
+
<h3>ItineraryInfo</h3>
|
|
108
|
+
{itineraryRender}
|
|
101
109
|
</div>
|
|
102
110
|
);
|
|
103
111
|
}
|
package/src/components/Utils.js
CHANGED
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
Itinerary, WGS84UserPosition
|
|
5
5
|
} from '@wemap/geo';
|
|
6
6
|
import { rad2deg } from '@wemap/maths';
|
|
7
|
+
import { OsrmUtils } from '@wemap/osm';
|
|
7
8
|
|
|
8
9
|
const NOT_AVAILABLE_STR = 'Not available';
|
|
9
10
|
|
|
@@ -92,6 +93,38 @@ class Utils {
|
|
|
92
93
|
|
|
93
94
|
}
|
|
94
95
|
|
|
96
|
+
static renderItineraryInfo(info) {
|
|
97
|
+
|
|
98
|
+
if (!info) {
|
|
99
|
+
return <p>Waiting</p>;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const step = info.nextStep;
|
|
103
|
+
let nextStepStr = '[' + step.number + '] ';
|
|
104
|
+
if (step.firstStep) {
|
|
105
|
+
nextStepStr += 'Depart';
|
|
106
|
+
} else if (step.lastStep) {
|
|
107
|
+
nextStepStr += 'Arrive';
|
|
108
|
+
} else {
|
|
109
|
+
nextStepStr += 'Turn '
|
|
110
|
+
+ OsrmUtils.getModifierFromAngle(step.angle);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
return (
|
|
115
|
+
<p>
|
|
116
|
+
projection: {info.projection.nearestElement.constructor.name}<br />
|
|
117
|
+
distanceOfProjection: {info.projection.distanceFromNearestElement.toFixed(1)}m<br />
|
|
118
|
+
traveledDistance: {info.traveledDistance.toFixed(1)}m
|
|
119
|
+
({(info.traveledPercentage * 100).toFixed(1)}%)<br />
|
|
120
|
+
remainingDistance: {info.remainingDistance.toFixed(1)}m
|
|
121
|
+
({(info.remainingPercentage * 100).toFixed(1)}%)<br />
|
|
122
|
+
nextStep: {nextStepStr}
|
|
123
|
+
</p>
|
|
124
|
+
);
|
|
125
|
+
|
|
126
|
+
}
|
|
127
|
+
|
|
95
128
|
static renderInclination(inclination) {
|
|
96
129
|
if (inclination === null) {
|
|
97
130
|
return 'Waiting';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import Provider from '../Provider';
|
|
2
2
|
import {
|
|
3
|
-
|
|
3
|
+
Itinerary, MapMatching, Network, WGS84
|
|
4
4
|
} from '@wemap/geo';
|
|
5
5
|
|
|
6
6
|
class MapMatchingProvider extends Provider {
|
|
@@ -46,29 +46,6 @@ class MapMatchingProvider extends Provider {
|
|
|
46
46
|
return this.mapMatching !== null;
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
/**
|
|
50
|
-
* Returns projection of a position on network
|
|
51
|
-
* @param {WGS84} position if position is null, projection of this.position is used
|
|
52
|
-
* @returns The projected position {WGS84} or null.
|
|
53
|
-
* @public
|
|
54
|
-
*/
|
|
55
|
-
getProjectionOnNetwork(position = null) {
|
|
56
|
-
|
|
57
|
-
if (!this.mapMatching) {
|
|
58
|
-
return null;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
let positionToProject = position;
|
|
62
|
-
if (!position) {
|
|
63
|
-
positionToProject = this.position;
|
|
64
|
-
}
|
|
65
|
-
if (!positionToProject) {
|
|
66
|
-
return null;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
return this.mapMatching.getProjection(positionToProject, false, false);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
49
|
|
|
73
50
|
/**
|
|
74
51
|
* Itinerary
|
|
@@ -87,60 +64,24 @@ class MapMatchingProvider extends Provider {
|
|
|
87
64
|
this.itinerary = itinerary;
|
|
88
65
|
}
|
|
89
66
|
|
|
90
|
-
|
|
91
67
|
/**
|
|
92
68
|
* Returns projection and itinerary info of a position on network
|
|
93
|
-
* @param {WGS84} position if position is null, projection of this.position is used
|
|
69
|
+
* @param {WGS84} position if position is null/undefined, projection of this.position is used
|
|
94
70
|
* @returns An object of the projected position and itinerary info or null.
|
|
95
71
|
* @public
|
|
96
72
|
*/
|
|
97
|
-
getItineraryInfo(position
|
|
73
|
+
getItineraryInfo(position) {
|
|
98
74
|
|
|
99
75
|
if (!this.itinerary) {
|
|
100
76
|
throw new Error('No itinerary found');
|
|
101
77
|
}
|
|
102
|
-
const projection = this.getProjectionOnNetwork(position);
|
|
103
|
-
if (!projection) {
|
|
104
|
-
return null;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
const totalDistance = this.itinerary.distance;
|
|
108
|
-
let traveledDistance = 0;
|
|
109
|
-
const edges = this.itinerary.edges;
|
|
110
78
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
const edge = edges[i];
|
|
115
|
-
if (edge.node1.equalsTo(projection.nearestElement)) {
|
|
116
|
-
break;
|
|
117
|
-
}
|
|
118
|
-
traveledDistance += edge.length;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
} else if (projection.nearestElement instanceof Edge) {
|
|
123
|
-
|
|
124
|
-
for (let i = 0; i < edges.length; i++) {
|
|
125
|
-
const edge = edges[i];
|
|
126
|
-
if (edge.equalsTo(projection.nearestElement)) {
|
|
127
|
-
traveledDistance += edge.node1.distanceTo(projection.projection);
|
|
128
|
-
break;
|
|
129
|
-
}
|
|
130
|
-
traveledDistance += edge.length;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
} else {
|
|
134
|
-
throw new Error('No projection found');
|
|
79
|
+
const _position = position || this.position;
|
|
80
|
+
if (!_position) {
|
|
81
|
+
return null;
|
|
135
82
|
}
|
|
136
83
|
|
|
137
|
-
return
|
|
138
|
-
projection: projection,
|
|
139
|
-
traveledDistance,
|
|
140
|
-
traveledPercentage: traveledDistance / totalDistance,
|
|
141
|
-
remainingDistance: totalDistance - traveledDistance,
|
|
142
|
-
remainingPercentage: 1 - traveledDistance / totalDistance
|
|
143
|
-
};
|
|
84
|
+
return this.itinerary.getInfo(position || this.position);
|
|
144
85
|
}
|
|
145
86
|
}
|
|
146
87
|
|
|
@@ -117,7 +117,7 @@ class GnssWifiPdrProvider extends MapMatchingProvider {
|
|
|
117
117
|
} else {
|
|
118
118
|
|
|
119
119
|
this.gnssPosition.bearing = this.attitude.headingDegrees;
|
|
120
|
-
const projection = this.mapMatching.getProjection(this.gnssPosition);
|
|
120
|
+
const projection = this.mapMatching.getProjection(this.gnssPosition, true, true);
|
|
121
121
|
|
|
122
122
|
if (projection && projection.projection) {
|
|
123
123
|
|
|
@@ -192,13 +192,11 @@ class GnssWifiPdrProvider extends MapMatchingProvider {
|
|
|
192
192
|
console.warn('Itinerary has not been calculated from GnssWifiPdrProvider and these is not recommanded');
|
|
193
193
|
}
|
|
194
194
|
|
|
195
|
-
|
|
196
|
-
if (
|
|
197
|
-
|
|
198
|
-
} else {
|
|
199
|
-
startEdge = itinerary.secondEdge;
|
|
195
|
+
const startEdge = itinerary.getEdgeAt(MM_GNSS_DIST);
|
|
196
|
+
if (!startEdge) {
|
|
197
|
+
return;
|
|
200
198
|
}
|
|
201
|
-
const startPoint = WGS84UserPosition.fromWGS84(startEdge.node1);
|
|
199
|
+
const startPoint = WGS84UserPosition.fromWGS84(startEdge.node1.coords);
|
|
202
200
|
startPoint.alt = Constants.DEFAULT_ALTITUDE;
|
|
203
201
|
this.pdrProvider.setPosition(startPoint);
|
|
204
202
|
this.pdrProvider.setStepDetectionLockerOrientation(startEdge.bearing);
|
|
@@ -255,7 +255,7 @@ class PdrProvider extends MapMatchingProvider {
|
|
|
255
255
|
return newPositionWithoutMM;
|
|
256
256
|
}
|
|
257
257
|
|
|
258
|
-
const projection = this.mapMatching.getProjection(newPositionWithoutMM);
|
|
258
|
+
const projection = this.mapMatching.getProjection(newPositionWithoutMM, true, true);
|
|
259
259
|
|
|
260
260
|
if (!projection || !projection.projection) {
|
|
261
261
|
return newPositionWithoutMM;
|