@wemap/providers 4.0.15 → 5.0.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.
@@ -1,9 +1,8 @@
1
1
  import React from 'react'; // eslint-disable-line no-unused-vars
2
2
 
3
- import {
4
- AbsoluteHeading, UserPosition, Level, Itinerary
5
- } from '@wemap/geo';
3
+ import { AbsoluteHeading, UserPosition, Level, Coordinates } from '@wemap/geo';
6
4
  import { deg2rad } from '@wemap/maths';
5
+ import { Itinerary } from '@wemap/osm';
7
6
  import { TimeUtils } from '@wemap/utils';
8
7
 
9
8
  const datasets = {};
@@ -94,14 +93,17 @@ class NavigationConfig {
94
93
  this.dataset = dataset;
95
94
  }
96
95
 
96
+ /** @type {Coordinates} */
97
97
  static get INITIAL_POSITION() {
98
98
  return this.dataset.initialPosition;
99
99
  }
100
100
 
101
+ /** @type {AbsoluteHeading} */
101
102
  static get INITIAL_HEADING() {
102
103
  return this.dataset.initialHeading;
103
104
  }
104
105
 
106
+ /** @type {Itinerary} */
105
107
  static get ITINERARY() {
106
108
  return this.dataset.itinerary;
107
109
  }
package/package.json CHANGED
@@ -8,16 +8,16 @@
8
8
  "Guillaume Pannetier <guillaume.pannetier@getwemap.com>"
9
9
  ],
10
10
  "dependencies": {
11
- "@wemap/geo": "^4.0.14",
11
+ "@wemap/geo": "^5.0.0",
12
12
  "@wemap/geomagnetism": "^0.1.1",
13
- "@wemap/logger": "^4.0.0",
14
- "@wemap/map": "^4.0.14",
15
- "@wemap/maths": "^4.0.3",
16
- "@wemap/utils": "^4.0.0"
13
+ "@wemap/logger": "^5.0.0",
14
+ "@wemap/map": "^5.0.0",
15
+ "@wemap/maths": "^5.0.0",
16
+ "@wemap/utils": "^5.0.0"
17
17
  },
18
18
  "description": "A package using different geoloc systems",
19
19
  "devDependencies": {
20
- "@wemap/osm": "^4.0.15",
20
+ "@wemap/osm": "^5.0.0",
21
21
  "mapbox-gl": "^1.11.1"
22
22
  },
23
23
  "homepage": "https://github.com/wemap/wemap-modules-js#readme",
@@ -39,6 +39,6 @@
39
39
  "url": "git+https://github.com/wemap/wemap-modules-js.git"
40
40
  },
41
41
  "type": "module",
42
- "version": "4.0.15",
43
- "gitHead": "eaaaf8ba0d4ba7e2d1de5a8910f7cf8e0ad8aaf1"
42
+ "version": "5.0.0",
43
+ "gitHead": "73607e294f29d3f9a41673bfc25ad9489a1da7f4"
44
44
  }
@@ -9,6 +9,7 @@ import {
9
9
  } from './Providers.js';
10
10
  import ProvidersLoggerOld from './events/ProvidersLoggerOld.js';
11
11
  import MapMatchingHandler from './mapmatching/MapMatchingHandler.js';
12
+ import { Itinerary } from '@wemap/osm';
12
13
 
13
14
  class ProvidersInterface {
14
15
 
@@ -51,6 +52,10 @@ class ProvidersInterface {
51
52
  MapMatchingHandler.network = data;
52
53
  return;
53
54
  }
55
+ if (eventType === EventType.Itinerary) {
56
+ MapMatchingHandler.itinerary = data;
57
+ return;
58
+ }
54
59
  this._getProviderFromEventType(eventType).feed(data, eventType);
55
60
  }
56
61
 
@@ -121,6 +126,11 @@ class ProvidersInterface {
121
126
  throw errorFn('Network');
122
127
  }
123
128
  break;
129
+ case EventType.Itinerary:
130
+ if (!(data instanceof Itinerary || data === null)) {
131
+ throw errorFn('Itinerary');
132
+ }
133
+ break;
124
134
  default:
125
135
  throw new Error(`Unable to deal with this event type: ${eventType}`);
126
136
  }
@@ -1,8 +1,9 @@
1
1
  /* eslint-disable max-statements */
2
2
  import {
3
- AbsoluteHeading, Edge, Itinerary, MapMatching, Network, Projection, UserPosition
3
+ AbsoluteHeading, GraphEdge, MapMatching, Network, GraphProjection, UserPosition
4
4
  } from '@wemap/geo';
5
5
  import { deg2rad, diffAngle, diffAngleLines } from '@wemap/maths';
6
+ import { Itinerary } from '@wemap/osm';
6
7
  import { TimeUtils } from '@wemap/utils';
7
8
 
8
9
  import EventType from '../events/EventType.js';
@@ -69,13 +70,13 @@ class MapMatchingHandler extends Provider {
69
70
  /** @type {number?} */
70
71
  _stepDetectorProviderId;
71
72
 
72
- /** @type {Projection[]} */
73
+ /** @type {GraphProjection[]} */
73
74
  _projectionsWithAbsAndWithoutRelAttitudeInARow = [];
74
75
 
75
76
  /** @type {number} */
76
77
  _countStepsFromLastMatching = 0;
77
78
 
78
- /** @type {Projection[]} */
79
+ /** @type {GraphProjection[]} */
79
80
  _lastProjections = [];
80
81
 
81
82
 
@@ -142,12 +143,12 @@ class MapMatchingHandler extends Provider {
142
143
  return ProvidersOptions.useMapMatching;
143
144
  }
144
145
 
145
- /** @type {Network} */
146
+ /** @type {?Network} */
146
147
  get network() {
147
148
  return this._mapMatching.network;
148
149
  }
149
150
 
150
- /** @type {Network} */
151
+ /** @type {?Network} */
151
152
  set network(network) {
152
153
 
153
154
  this._mapMatching.network = network;
@@ -156,7 +157,21 @@ class MapMatchingHandler extends Provider {
156
157
  this._manageStartStop();
157
158
 
158
159
  if (this.canUseMapMatching()) {
159
- this._notifyPositionFromNetworkInput(network);
160
+ // TODO if necessary
161
+ // this._notifyPositionFromNetworkInput(network);
162
+ }
163
+ }
164
+
165
+ /** @type {?Itinerary} */
166
+ set itinerary(itinerary) {
167
+
168
+ this._mapMatching.network = itinerary ? itinerary.toNetwork() : null;
169
+ this.notify(this.createEvent(EventType.Itinerary, itinerary));
170
+
171
+ this._manageStartStop();
172
+
173
+ if (this.canUseMapMatching()) {
174
+ this._notifyPositionFromItineraryInput(itinerary);
160
175
  }
161
176
  }
162
177
 
@@ -168,9 +183,13 @@ class MapMatchingHandler extends Provider {
168
183
  }
169
184
 
170
185
  /**
171
- * @param {Network} network
186
+ * @param {Itinerary} itinerary
172
187
  */
173
- _notifyPositionFromNetworkInput(network) {
188
+ _notifyPositionFromItineraryInput(itinerary) {
189
+
190
+ if (!MapMatchingHandler.USE_ITINERARY_START_AS_POSITION || itinerary.start) {
191
+ return;
192
+ }
174
193
 
175
194
  const lastEvent = AbsolutePosition.lastEvent;
176
195
  const lastPosition = lastEvent ? lastEvent.data : null;
@@ -183,46 +202,36 @@ class MapMatchingHandler extends Provider {
183
202
  AbsolutePosition.notify(newEvent);
184
203
  };
185
204
 
186
- let newPosition;
187
- if (MapMatchingHandler.USE_ITINERARY_START_AS_POSITION
188
- && network instanceof Itinerary && network.start) {
189
-
190
- // In case of an itinerary, use itinerary start as new position,
191
- // but add the distance between lastPosition and itinerary start for the accuracy
192
- newPosition = UserPosition.fromCoordinates(network.start);
193
-
194
- if (lastPosition) {
195
- newPosition.alt = lastPosition.alt;
196
- newPosition.time = lastPosition.time;
197
- newPosition.accuracy = lastPosition.accuracy + newPosition.distanceTo(lastPosition);
198
- newPosition.bearing = lastPosition.bearing;
199
- } else {
200
- newPosition.alt = Constants.DEFAULT_ALTITUDE;
201
- newPosition.time = TimeUtils.preciseTime();
202
- newPosition.accuracy = 0;
203
- newPosition.bearing = network.edges[0].bearing;
204
- }
205
-
206
- // if the distance between itinerary.start and itinerary.nodes[0] is less than MM_MAX_DIST,
207
- // projection.projection is itinerary.nodes[0]
208
- const projection = this.getProjection(newPosition, true);
209
- if (projection) {
210
- notify(projection.projection);
211
- // Do not notify for attitude projection because bearing has not been used.
212
- } else {
213
- // This means the first position is far from the network and the user has
214
- // to reach itinerary.nodes[0] before to continue
215
- notify(newPosition);
216
- }
205
+ // In case of an itinerary, use itinerary start as new position,
206
+ // but add the distance between lastPosition and itinerary start for the accuracy
207
+ const newPosition = UserPosition.fromCoordinates(itinerary.from);
208
+
209
+ if (lastPosition) {
210
+ newPosition.alt = lastPosition.alt;
211
+ newPosition.time = lastPosition.time;
212
+ newPosition.accuracy = lastPosition.accuracy + newPosition.distanceTo(lastPosition);
213
+ newPosition.bearing = lastPosition.bearing;
214
+ } else if (itinerary.coords >= 2) {
215
+ newPosition.alt = Constants.DEFAULT_ALTITUDE;
216
+ newPosition.time = TimeUtils.preciseTime();
217
+ newPosition.accuracy = 0;
218
+ newPosition.bearing = itinerary.coords[0].bearingTo(itinerary.coords[1]);
219
+ } else {
217
220
  return;
218
221
  }
219
222
 
220
- if (!lastPosition) {
221
- return;
223
+ // if the distance between itinerary.start and itinerary.nodes[0] is less than MM_MAX_DIST,
224
+ // projection.projection is itinerary.nodes[0]
225
+ const projection = this.getProjection(newPosition, true);
226
+ if (projection) {
227
+ notify(projection.projection);
228
+ // Do not notify for attitude projection because bearing has not been used.
229
+ } else {
230
+ // This means the first position is far from the network and the user has
231
+ // to reach itinerary.nodes[0] before to continue
232
+ notify(newPosition);
222
233
  }
223
-
224
- newPosition = lastPosition.clone();
225
- // TODO in function of the lastEvent, if it is from relative or absolute
234
+ return;
226
235
  }
227
236
 
228
237
  /**
@@ -422,7 +431,7 @@ class MapMatchingHandler extends Provider {
422
431
 
423
432
  const firstProjection = this._lastProjections[0];
424
433
  return !this._lastProjections.some(projection =>
425
- !(projection.nearestElement instanceof Edge)
434
+ !(projection.nearestElement instanceof GraphEdge)
426
435
  || (diffAngleLines(projection.nearestElement.bearing, firstProjection.nearestElement.bearing)
427
436
  > MapMatchingHandler.LAST_PROJECTIONS_EDGE_ANGLE_THRESHOLD)
428
437
  );
@@ -444,7 +453,7 @@ class MapMatchingHandler extends Provider {
444
453
  }
445
454
 
446
455
  const { nearestElement, origin } = projection;
447
- if (!(nearestElement instanceof Edge)) {
456
+ if (!(nearestElement instanceof GraphEdge)) {
448
457
  return;
449
458
  }
450
459