@wemap/providers 6.2.1 → 6.2.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.
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { Evented } from 'mapbox-gl';
|
|
2
|
+
import {
|
|
3
|
+
PositionSmoother, ProvidersInterface, EventType
|
|
4
|
+
} from '@wemap/providers';
|
|
5
|
+
|
|
6
|
+
export default class CustomMapProvider extends Evented {
|
|
7
|
+
|
|
8
|
+
attitudeProviderId = null;
|
|
9
|
+
positionProviderId = null;
|
|
10
|
+
smoother = null;
|
|
11
|
+
|
|
12
|
+
start() {
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Attitude
|
|
16
|
+
*/
|
|
17
|
+
this.attitudeProviderId = ProvidersInterface.addEventListener(
|
|
18
|
+
EventType.AbsoluteAttitude,
|
|
19
|
+
attitude => this.fire('heading.changed', { heading: attitude.headingDegrees })
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
// There is no sense to show the last known attitude on the map
|
|
23
|
+
// this.fire('heading.changed' : { heading: ProvidersInterface.getLastKnown(EventType.AbsoluteAttitude)});
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Position
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
this.smoother = new PositionSmoother(position => {
|
|
31
|
+
this.fire('position.changed', { position });
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
this.positionProviderId = ProvidersInterface.addEventListener(
|
|
35
|
+
EventType.AbsolutePosition,
|
|
36
|
+
position => this.smoother.feed(position)
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
const lastKnownPosition = ProvidersInterface.getLastKnown(EventType.AbsolutePosition);
|
|
40
|
+
if (lastKnownPosition) {
|
|
41
|
+
this.fire('position.changed', { position: lastKnownPosition });
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
stop() {
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Attitude
|
|
49
|
+
*/
|
|
50
|
+
|
|
51
|
+
ProvidersInterface.removeEventListener(this.attitudeProviderId);
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Position
|
|
56
|
+
*/
|
|
57
|
+
|
|
58
|
+
ProvidersInterface.removeEventListener(this.positionProviderId);
|
|
59
|
+
|
|
60
|
+
this.smoother.clear();
|
|
61
|
+
this.smoother = null;
|
|
62
|
+
}
|
|
63
|
+
}
|
package/package.json
CHANGED
|
@@ -9,16 +9,17 @@
|
|
|
9
9
|
],
|
|
10
10
|
"dependencies": {
|
|
11
11
|
"@wemap/camera": "^6.1.0",
|
|
12
|
-
"@wemap/geo": "^6.
|
|
12
|
+
"@wemap/geo": "^6.2.2",
|
|
13
13
|
"@wemap/geomagnetism": "^0.1.1",
|
|
14
14
|
"@wemap/logger": "^6.0.0",
|
|
15
|
-
"@wemap/map": "^6.
|
|
15
|
+
"@wemap/map": "^6.2.2",
|
|
16
16
|
"@wemap/maths": "^6.0.0",
|
|
17
|
-
"@wemap/osm": "^6.
|
|
17
|
+
"@wemap/osm": "^6.2.2",
|
|
18
18
|
"@wemap/utils": "^6.0.0"
|
|
19
19
|
},
|
|
20
20
|
"description": "A package using different geoloc systems",
|
|
21
21
|
"devDependencies": {
|
|
22
|
+
"map-gl-geolocation": "^0.3.0",
|
|
22
23
|
"mapbox-gl": "^1.11.1"
|
|
23
24
|
},
|
|
24
25
|
"homepage": "https://github.com/wemap/wemap-modules-js#readme",
|
|
@@ -40,6 +41,6 @@
|
|
|
40
41
|
"url": "git+https://github.com/wemap/wemap-modules-js.git"
|
|
41
42
|
},
|
|
42
43
|
"type": "module",
|
|
43
|
-
"version": "6.2.
|
|
44
|
-
"gitHead": "
|
|
44
|
+
"version": "6.2.2",
|
|
45
|
+
"gitHead": "ee717a21b2f01820472df0112da9373044f267f9"
|
|
45
46
|
}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { Vector3 } from '@wemap/maths';
|
|
2
|
-
|
|
3
1
|
class StepDetectionMinMaxPeaks2 {
|
|
4
2
|
|
|
5
3
|
// in seconds
|
|
@@ -16,11 +14,6 @@ class StepDetectionMinMaxPeaks2 {
|
|
|
16
14
|
static VERTICAL_ACC_POSITIVE_PEAK_THRESHOLD = 0.75;
|
|
17
15
|
static VERTICAL_ACC_NEGATIVE_PEAK_THRESHOLD = -0.3;
|
|
18
16
|
|
|
19
|
-
// in rad.s-1
|
|
20
|
-
static HIGH_ROTATION_THRESHOLD = 1.35
|
|
21
|
-
// in seconds
|
|
22
|
-
static HIGH_ROTATION_DURATION = 0.3
|
|
23
|
-
|
|
24
17
|
|
|
25
18
|
constructor() {
|
|
26
19
|
this.slidingWindow = [];
|
|
@@ -30,22 +23,14 @@ class StepDetectionMinMaxPeaks2 {
|
|
|
30
23
|
this.influence = 0.2;
|
|
31
24
|
}
|
|
32
25
|
|
|
33
|
-
_parseGyroscope(values, timestamp) {
|
|
34
|
-
const rotationSpeed = Vector3.norm(values);
|
|
35
|
-
if (rotationSpeed > StepDetectionMinMaxPeaks2.HIGH_ROTATION_THRESHOLD) {
|
|
36
|
-
this.lastHighRotation = timestamp;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
26
|
|
|
40
27
|
compute(timestamp, linearAcc, angularRate) {
|
|
41
28
|
|
|
42
|
-
this._parseGyroscope(angularRate, timestamp);
|
|
43
|
-
|
|
44
29
|
const verticalAcc = this.influence * (linearAcc[2] * 2) + (1 - this.influence) * this.previousVerticalAcc;
|
|
45
30
|
this.previousVerticalAcc = verticalAcc;
|
|
46
31
|
|
|
47
32
|
|
|
48
|
-
if (
|
|
33
|
+
if (Math.sqrt(angularRate[0] ** 2 + angularRate[1] ** 2 + angularRate[2] ** 2) > 0.75) {
|
|
49
34
|
return false;
|
|
50
35
|
}
|
|
51
36
|
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
import { Map } from 'mapbox-gl';
|
|
2
|
-
|
|
3
|
-
import { GeolocationLayer } from '@wemap/map';
|
|
4
|
-
import {
|
|
5
|
-
PositionSmoother, ProvidersInterface, EventType
|
|
6
|
-
} from '@wemap/providers';
|
|
7
|
-
import { TimeUtils } from '@wemap/utils';
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Create map.geolocation object
|
|
12
|
-
* @param {Map} map
|
|
13
|
-
*/
|
|
14
|
-
function addGeolocationOnMap(map) {
|
|
15
|
-
|
|
16
|
-
let smoother;
|
|
17
|
-
|
|
18
|
-
let attitudeProviderId;
|
|
19
|
-
let positionProviderId;
|
|
20
|
-
|
|
21
|
-
let isStarted = false;
|
|
22
|
-
|
|
23
|
-
Object.assign(map, { geolocation: new GeolocationLayer(map) });
|
|
24
|
-
|
|
25
|
-
Object.assign(map.geolocation, {
|
|
26
|
-
|
|
27
|
-
start: () => {
|
|
28
|
-
|
|
29
|
-
if (isStarted) {
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
isStarted = true;
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Attitude
|
|
36
|
-
*/
|
|
37
|
-
attitudeProviderId = ProvidersInterface.addEventListener(
|
|
38
|
-
EventType.AbsoluteAttitude,
|
|
39
|
-
attitude => map.geolocation.updateHeading(attitude.headingDegrees)
|
|
40
|
-
);
|
|
41
|
-
|
|
42
|
-
// There is no sense to show the last known attitude on the map
|
|
43
|
-
// map.geolocation.updateHeading(ProvidersInterface.getLastKnown(EventType.AbsoluteAttitude));
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Position
|
|
48
|
-
*/
|
|
49
|
-
|
|
50
|
-
const positionTransform = input => {
|
|
51
|
-
if (input === null) {
|
|
52
|
-
return null;
|
|
53
|
-
}
|
|
54
|
-
return Object.assign(input.clone(),
|
|
55
|
-
{ timestamp: TimeUtils.preciseTimeToUnixTimestamp(input.time * 1e3) }
|
|
56
|
-
);
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
smoother = new PositionSmoother(position => {
|
|
60
|
-
map.geolocation.updatePosition(positionTransform(position));
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
positionProviderId = ProvidersInterface.addEventListener(
|
|
64
|
-
EventType.AbsolutePosition,
|
|
65
|
-
position => smoother.feed(position)
|
|
66
|
-
);
|
|
67
|
-
|
|
68
|
-
const lastKnownPosition = ProvidersInterface.getLastKnown(EventType.AbsolutePosition);
|
|
69
|
-
if (lastKnownPosition) {
|
|
70
|
-
map.geolocation.updatePosition(positionTransform(lastKnownPosition));
|
|
71
|
-
}
|
|
72
|
-
},
|
|
73
|
-
|
|
74
|
-
stop: () => {
|
|
75
|
-
|
|
76
|
-
if (!isStarted) {
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Attitude
|
|
82
|
-
*/
|
|
83
|
-
|
|
84
|
-
ProvidersInterface.removeEventListener(attitudeProviderId);
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Position
|
|
89
|
-
*/
|
|
90
|
-
|
|
91
|
-
ProvidersInterface.removeEventListener(positionProviderId);
|
|
92
|
-
smoother.clear();
|
|
93
|
-
smoother = null;
|
|
94
|
-
|
|
95
|
-
isStarted = false;
|
|
96
|
-
}
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
map.geolocation.on('start.clicked', map.geolocation.start);
|
|
100
|
-
map.geolocation.on('stop.clicked', map.geolocation.stop);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
export default addGeolocationOnMap;
|