@wemap/providers 3.1.22 → 3.2.1

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.
Files changed (74) hide show
  1. package/babel.config.json +16 -0
  2. package/debug/MainComponent.jsx +5 -5
  3. package/debug/components/AbsoluteAttitudeComponent.jsx +5 -5
  4. package/debug/components/AbsolutePositionComponent.jsx +7 -9
  5. package/debug/components/GnssWifiComponent.jsx +5 -5
  6. package/debug/components/ImuComponent.jsx +4 -4
  7. package/debug/components/InclinationComponent.jsx +4 -4
  8. package/debug/components/RelativeAttitudeComponent.jsx +4 -4
  9. package/debug/components/StepDetectionComponent.jsx +4 -4
  10. package/debug/components/Utils.js +1 -1
  11. package/debug/{Common.css → css/App.css} +0 -44
  12. package/debug/css/UserOnMapHandler.css +43 -0
  13. package/debug/details/DetailsAttitudeComponent.jsx +1 -1
  14. package/debug/details/DetailsComponent.jsx +4 -5
  15. package/debug/details/DetailsPositionComponent.jsx +2 -2
  16. package/debug/details/ItineraryComponent.jsx +10 -69
  17. package/debug/index.js +8 -8
  18. package/debug/map/MapComponent.jsx +23 -15
  19. package/debug/map/MapHandler.js +7 -16
  20. package/debug/map/helpers/ItineraryMapHandler.js +15 -16
  21. package/debug/map/helpers/MapClickHandler.js +9 -7
  22. package/debug/map/helpers/UserOnMapHandler.js +23 -417
  23. package/debug/stores/ItineraryStore.js +23 -48
  24. package/dist/assets/indoor-maps/bureaux-wemap-montpellier.geojson +339 -513
  25. package/dist/js/providers-components.js +2361 -0
  26. package/dist/logger.html +58 -0
  27. package/index.js +7 -5
  28. package/package.json +25 -21
  29. package/src/Providers.js +15 -15
  30. package/src/ProvidersInterface.js +7 -5
  31. package/src/errors/MissingAccelerometerError.js +2 -2
  32. package/src/errors/MissingGyroscopeError.js +2 -2
  33. package/src/errors/MissingMagnetometerError.js +1 -1
  34. package/src/events/ProviderEvent.js +1 -1
  35. package/src/events/{ProvidersLogger.js → ProvidersLoggerOld.js} +7 -7
  36. package/src/logger/NavigationLogger.js +131 -0
  37. package/src/logger/NavigationLoggerConverter.js +228 -0
  38. package/src/providers/FakeProvider.spec.js +3 -4
  39. package/src/providers/MetaProvider.js +3 -3
  40. package/src/providers/Provider.js +12 -11
  41. package/src/providers/Provider.spec.js +5 -7
  42. package/src/providers/attitude/EkfAttitude.spec.js +1 -1
  43. package/src/providers/attitude/absolute/AbsoluteAttitudeFromBrowserProvider.js +9 -6
  44. package/src/providers/attitude/absolute/AbsoluteAttitudeFromRelAttProvider.js +5 -6
  45. package/src/providers/attitude/absolute/AbsoluteAttitudeProvider.js +3 -3
  46. package/src/providers/attitude/relative/RelativeAttitudeFromBrowserProvider.js +5 -5
  47. package/src/providers/attitude/relative/RelativeAttitudeFromEkfProvider.js +5 -5
  48. package/src/providers/attitude/relative/RelativeAttitudeFromInertialProvider.js +3 -3
  49. package/src/providers/attitude/relative/RelativeAttitudeProvider.js +5 -4
  50. package/src/providers/imu/AccelerometerProvider.js +4 -4
  51. package/src/providers/imu/GyroscopeProvider.js +4 -4
  52. package/src/providers/imu/ImuProvider.js +4 -2
  53. package/src/providers/inclination/InclinationFromAccProvider.js +3 -3
  54. package/src/providers/inclination/InclinationFromRelativeAttitudeProvider.js +3 -3
  55. package/src/providers/inclination/InclinationProvider.js +3 -3
  56. package/src/providers/legacy/helpers/HeadingUnlocker.spec.js +1 -1
  57. package/src/providers/others/BarcodeProvider.js +3 -3
  58. package/src/providers/others/CameraNativeProvider.js +4 -4
  59. package/src/providers/others/CameraProjectionMatrixProvider.js +3 -3
  60. package/src/providers/position/absolute/AbsolutePositionFromRelProvider.js +4 -4
  61. package/src/providers/position/absolute/AbsolutePositionProvider.js +5 -5
  62. package/src/providers/position/absolute/GnssWifiProvider.js +9 -6
  63. package/src/providers/position/absolute/IpProvider.js +3 -3
  64. package/src/providers/position/relative/ArCoreProvider.js +5 -5
  65. package/src/providers/position/relative/GeoRelativePositionFromArCoreProvider.js +3 -3
  66. package/src/providers/position/relative/GeoRelativePositionProvider.js +3 -3
  67. package/src/providers/position/relative/PdrProvider.js +3 -3
  68. package/src/providers/steps/StepDetectionProvider.js +11 -4
  69. package/src/smoothers/PositionSmoother.spec.js +1 -1
  70. package/webpack/{webpack.common.js → webpack.common.cjs} +7 -1
  71. package/webpack/{webpack.dev.js → webpack.dev.cjs} +1 -7
  72. package/webpack/{webpack.prod.js → webpack.prod.cjs} +1 -1
  73. package/babel.config.js +0 -11
  74. package/debug/map/MapboxHelper.js +0 -50
@@ -1,9 +1,9 @@
1
- import mapboxgl from 'mapbox-gl';
1
+ import { Map } from 'mapbox-gl';
2
2
 
3
3
  import { Level } from '@wemap/geo';
4
+ import { MapboxUtils } from '@wemap/map';
4
5
 
5
- import MapboxHelper from '../MapboxHelper';
6
- import ItineraryStore from '../../stores/ItineraryStore';
6
+ import ItineraryStore from '../../stores/ItineraryStore.js';
7
7
 
8
8
  class ItineraryMapHandler {
9
9
 
@@ -20,7 +20,7 @@ class ItineraryMapHandler {
20
20
  };
21
21
 
22
22
  /**
23
- * @param {mapboxgl.Map} map
23
+ * @param {Map} map
24
24
  */
25
25
  constructor(map) {
26
26
  if (!map) {
@@ -55,8 +55,7 @@ class ItineraryMapHandler {
55
55
  });
56
56
 
57
57
  this.generateLayers(ItineraryMapHandler.SOURCE_ID).forEach(layer => {
58
- this.map.addLayer(layer);
59
- this.map.indoor.addLayerForFiltering(layer.id);
58
+ this.map.indoor._addLayerForFiltering(layer);
60
59
  });
61
60
  }
62
61
 
@@ -79,8 +78,8 @@ class ItineraryMapHandler {
79
78
  geometry: {
80
79
  type: 'LineString',
81
80
  coordinates: [
82
- MapboxHelper.coordsToLngLat(itinerary.start),
83
- MapboxHelper.coordsToLngLat(itinerary.nodes[0].coords)
81
+ MapboxUtils.coordsToLngLat(itinerary.start),
82
+ MapboxUtils.coordsToLngLat(itinerary.nodes[0].coords)
84
83
  ]
85
84
  }
86
85
  };
@@ -93,12 +92,12 @@ class ItineraryMapHandler {
93
92
  */
94
93
  const endFeature = {
95
94
  type: 'Feature',
96
- properties: { 'itinerary': 'start' },
95
+ properties: { 'itinerary': 'end' },
97
96
  geometry: {
98
97
  type: 'LineString',
99
98
  coordinates: [
100
- MapboxHelper.coordsToLngLat(itinerary.nodes[itinerary.nodes.length - 1].coords),
101
- MapboxHelper.coordsToLngLat(itinerary.end)
99
+ MapboxUtils.coordsToLngLat(itinerary.nodes[itinerary.nodes.length - 1].coords),
100
+ MapboxUtils.coordsToLngLat(itinerary.end)
102
101
  ]
103
102
  }
104
103
  };
@@ -111,7 +110,7 @@ class ItineraryMapHandler {
111
110
  const itineraryFeatures = itinerary.edges.reduce((acc, edge) => {
112
111
 
113
112
  if (!currentFeatureCoordinates || !Level.equalsTo(edge.level, previousEdgeLevel)) {
114
- currentFeatureCoordinates = [MapboxHelper.coordsToLngLat(edge.node1.coords)];
113
+ currentFeatureCoordinates = [MapboxUtils.coordsToLngLat(edge.node1.coords)];
115
114
  const feature = {
116
115
  type: 'Feature',
117
116
  properties: { 'itinerary': 'core' },
@@ -127,7 +126,7 @@ class ItineraryMapHandler {
127
126
  previousEdgeLevel = edge.level;
128
127
  }
129
128
 
130
- currentFeatureCoordinates.push(MapboxHelper.coordsToLngLat(edge.node2.coords));
129
+ currentFeatureCoordinates.push(MapboxUtils.coordsToLngLat(edge.node2.coords));
131
130
 
132
131
  return acc;
133
132
 
@@ -158,7 +157,7 @@ class ItineraryMapHandler {
158
157
  properties: { 'start': 'yes' },
159
158
  geometry: {
160
159
  type: 'Point',
161
- coordinates: MapboxHelper.coordsToLngLat(coordinates)
160
+ coordinates: MapboxUtils.coordsToLngLat(coordinates)
162
161
  }
163
162
  };
164
163
  if (coordinates.level !== null) {
@@ -185,7 +184,7 @@ class ItineraryMapHandler {
185
184
  properties: { 'end': 'yes' },
186
185
  geometry: {
187
186
  type: 'Point',
188
- coordinates: MapboxHelper.coordsToLngLat(coordinates)
187
+ coordinates: MapboxUtils.coordsToLngLat(coordinates)
189
188
  }
190
189
  };
191
190
  if (coordinates.level !== null) {
@@ -198,7 +197,7 @@ class ItineraryMapHandler {
198
197
  }
199
198
 
200
199
  /**
201
- * @returns {mapboxgl.Layer[]}
200
+ * @returns {Layer[]}
202
201
  */
203
202
  generateLayers(sourceId) {
204
203
  return [
@@ -1,16 +1,18 @@
1
- import mapboxgl from 'mapbox-gl';
1
+ import {
2
+ Map, Popup
3
+ } from 'mapbox-gl';
2
4
 
3
5
  import {
4
6
  Coordinates, Level
5
7
  } from '@wemap/geo';
6
8
 
7
- import ItineraryStore from '../../stores/ItineraryStore';
8
- import UserOnMapHandler from './UserOnMapHandler';
9
+ import ItineraryStore from '../../stores/ItineraryStore.js';
10
+ import UserOnMapHandler from './UserOnMapHandler.js';
9
11
 
10
12
  class MapClickHandler {
11
13
 
12
14
  /**
13
- * @param {mapboxgl.Map} map
15
+ * @param {Map} map
14
16
  * @param {UserOnMapHandler} userOnMapHandler
15
17
  */
16
18
  constructor(map, userOnMapHandler) {
@@ -39,15 +41,15 @@ class MapClickHandler {
39
41
 
40
42
  const coordinates = new Coordinates(e.lngLat.lat, e.lngLat.lng);
41
43
 
42
- this.popup = new mapboxgl.Popup()
44
+ this.popup = new Popup()
43
45
  .setLngLat(e.lngLat)
44
46
  .setDOMContent(this._generatePopupHtml(coordinates))
45
47
  .addTo(this.map);
46
48
  }
47
49
 
48
50
  _updateCoordinatesWithMapLevel(coordinates) {
49
- if (this.map.getLevel() !== null) {
50
- coordinates.level = new Level(this.map.getLevel());
51
+ if (this.map.indoor.getLevel() !== null) {
52
+ coordinates.level = new Level(this.map.indoor.getLevel());
51
53
  }
52
54
  }
53
55
 
@@ -1,94 +1,38 @@
1
- import mapboxgl from 'mapbox-gl';
2
-
3
- import {
4
- Attitude, UserPosition, Constants
5
- } from '@wemap/geo';
6
- import { deg2rad } from '@wemap/maths';
1
+ import { Map } from 'mapbox-gl';
2
+ import { GeolocationLayer } from '@wemap/map';
7
3
 
8
4
  import {
9
5
  PositionSmoother, ProvidersInterface, EventType
10
- } from '../../..';
11
-
12
- import ItineraryStore from '../../stores/ItineraryStore';
13
- import MapboxHelper from '../MapboxHelper';
6
+ } from '../../../index.js';
14
7
 
15
- /**
16
- * Minimum size of accuracy circle radius
17
- */
18
- const MIN_ACCURACY_CIRCLE_RADIUS = 18;
19
8
 
20
9
  class UserOnMapHandler {
21
10
 
22
- positioningStarted = false;
23
-
24
- trackUserLocation = true;
25
- trackUserLocationFirst = true;
26
-
27
- attitude = null;
28
- attitudeDirty = false;
29
- renderedAttitude = null;
30
-
31
- position = null;
32
- positionDirty = false;
33
- renderedPosition = null;
34
-
35
- positionAccuracy = null;
36
- positionAccuracyDirty = false;
37
- renderAccuracy = false;
38
-
39
- positionForCameraDirty = false;
40
- levelForPositionDirty = false;
11
+ smoother;
12
+ attitudeProviderId;
13
+ positionProviderId;
41
14
 
42
15
  /**
43
- * @param {mapboxgl.Map} map
44
- * @param {HTMLDivElement} mapContainer
16
+ * @param {Map} map
45
17
  */
46
- constructor(map, mapContainer) {
47
- if (!map) {
48
- throw new TypeError('map cannot be null');
49
- }
50
-
51
- this.map = map;
52
- this.mapContainer = mapContainer;
53
- this.itineraryStore = ItineraryStore.instance;
18
+ constructor(map) {
54
19
 
55
- map.on('zoom', () => (this.positionAccuracyDirty = true));
56
- map.on('dragstart', () => (this.trackUserLocation = false));
57
- map.on('level', () => (this.levelForPositionDirty = true));
20
+ this.geolocationLayer = new GeolocationLayer(map);
58
21
 
59
- this.createDomPosition();
60
- this.createButtons();
22
+ this.geolocationLayer.onStartButtonClicked = layer => this.start(layer);
23
+ this.geolocationLayer.onStopButtonClicked = layer => this.stop(layer);
61
24
  }
62
25
 
26
+ start() {
63
27
 
64
- componentDidMount() {
65
- this.renderLoop();
66
- }
67
-
68
- componentWillUnmount() {
69
- cancelAnimationFrame(this.renderLoopId);
70
- }
71
-
72
-
73
- /**
74
- * Geo location logic
75
- */
76
-
77
- startPositioning() {
78
-
79
- if (this.positioningStarted) {
80
- return;
81
- }
82
- this.positioningStarted = true;
83
-
28
+ this.geolocationLayer.startRenderLoop();
84
29
 
85
30
  /**
86
31
  * Attitude
87
32
  */
88
-
89
- this.attitudeProvidersId = ProvidersInterface.addEventListener(
33
+ this.attitudeProviderId = ProvidersInterface.addEventListener(
90
34
  EventType.AbsoluteAttitude,
91
- attitude => this.updateAttitude(attitude)
35
+ attitude => this.geolocationLayer.updateAttitude(attitude)
92
36
  );
93
37
 
94
38
  // There is no sense to show the last known attitude on the map
@@ -99,372 +43,34 @@ class UserOnMapHandler {
99
43
  * Position
100
44
  */
101
45
 
102
- this.smoother = new PositionSmoother(position => this.updatePosition(position));
103
-
104
- let firstPositionFound = false;
105
-
106
- const firstPositionFn = () => {
107
- this.buttonLocateMe.classList.remove('mapboxgl-ctrl-geolocate-waiting');
108
- this.blueDot.classList.remove('inaccurate');
109
- this.accuracyCircle.classList.remove('inaccurate');
110
- };
46
+ this.smoother = new PositionSmoother(position => this.geolocationLayer.updatePosition(position));
111
47
 
112
- this.positionProvidersId = ProvidersInterface.addEventListener(
48
+ this.positionProviderId = ProvidersInterface.addEventListener(
113
49
  EventType.AbsolutePosition,
114
- position => {
115
- this.smoother.feed(position);
116
-
117
- if (!firstPositionFound) {
118
- firstPositionFn();
119
- firstPositionFound = true;
120
- }
121
- }
50
+ position => this.smoother.feed(position)
122
51
  );
123
52
 
124
- this.updatePosition(ProvidersInterface.getLastKnown(EventType.AbsolutePosition));
125
-
126
-
127
- /**
128
- * Itinerary
129
- */
130
-
131
- this.onItineraryChanged = itinerary => {
132
- if (!itinerary) {
133
- this.stopPositioning();
134
- }
135
- };
136
- this.itineraryStore.on(ItineraryStore.Events.ItineraryChanged, this.onItineraryChanged);
137
-
138
-
139
- /**
140
- * UI
141
- */
142
-
143
- this.buttonLocateMe.classList.add('mapboxgl-ctrl-geolocate-active');
144
- this.buttonLocateMe.classList.add('mapboxgl-ctrl-geolocate-waiting');
145
- this.buttonStopNav.style.display = 'block';
146
-
147
- this.blueDot.classList.add('inaccurate');
148
- this.accuracyCircle.classList.add('inaccurate');
149
-
53
+ this.geolocationLayer.updatePosition(ProvidersInterface.getLastKnown(EventType.AbsolutePosition));
150
54
  }
151
55
 
152
- stopPositioning() {
153
-
154
- if (!this.positioningStarted) {
155
- return;
156
- }
157
- this.positioningStarted = false;
56
+ stop() {
158
57
 
58
+ this.geolocationLayer.stopRenderLoop();
159
59
 
160
60
  /**
161
61
  * Attitude
162
62
  */
163
63
 
164
- ProvidersInterface.removeEventListener(this.attitudeProvidersId);
64
+ ProvidersInterface.removeEventListener(this.attitudeProviderId);
165
65
 
166
66
 
167
67
  /**
168
68
  * Position
169
69
  */
170
70
 
171
- ProvidersInterface.removeEventListener(this.positionProvidersId);
71
+ ProvidersInterface.removeEventListener(this.positionProviderId);
172
72
  this.smoother.clear();
173
-
174
-
175
- /**
176
- * Itinerary
177
- */
178
-
179
- this.itineraryStore.off(ItineraryStore.Events.ItineraryChanged, this.onItineraryChanged);
180
-
181
-
182
- /**
183
- * UI
184
- */
185
-
186
- this.buttonLocateMe.classList.remove('mapboxgl-ctrl-geolocate-active');
187
- this.buttonLocateMe.classList.remove('mapboxgl-ctrl-geolocate-waiting');
188
-
189
- this.buttonStopNav.style.display = 'none';
190
-
191
- this.position = null;
192
- this.positionDirty = true;
193
- this.positionAccuracy = null;
194
- this.positionAccuracyDirty = true;
195
- this.attitude = null;
196
- this.attitudeDirty = true;
197
- this.renderPosition();
198
- this.renderOrientation();
199
- }
200
-
201
- /**
202
- * @param {UserPosition} position
203
- */
204
- updatePosition = position => {
205
-
206
- if (this.position === position) {
207
- return;
208
- }
209
-
210
- this.positionDirty = true;
211
- this.positionForCameraDirty = true;
212
- this.position = position;
213
-
214
- const newAccuracy = !position ? null : position.accuracy;
215
- if (this.positionAccuracy !== newAccuracy) {
216
- this.positionAccuracy = newAccuracy;
217
- this.positionAccuracyDirty = true;
218
- }
219
-
220
- }
221
-
222
- /**
223
- * @param {Attitude} attitude
224
- */
225
- updateAttitude = attitude => {
226
-
227
- if (this.attitude === attitude) {
228
- return;
229
- }
230
-
231
- this.attitudeDirty = true;
232
- this.attitude = attitude;
233
- }
234
-
235
-
236
- /**
237
- * Render loops
238
- */
239
-
240
- renderLoop = () => {
241
- this.renderPosition();
242
- this.renderPositionAccuracy();
243
- this.renderOrientation();
244
- this.renderCameraCenter();
245
- this.renderLoopId = requestAnimationFrame(this.renderLoop);
246
73
  }
247
74
 
248
- renderPosition() {
249
-
250
- if (!this.positionDirty && !this.levelForPositionDirty) {
251
- return;
252
- }
253
-
254
- let position;
255
- if (this.position !== null
256
- && (this.map.getLevel() === null
257
- || this.position.level === null
258
- || this.map.getLevel() === this.position.level.val
259
- )
260
- ) {
261
- position = this.position;
262
- } else {
263
- position = null;
264
- }
265
-
266
- if (position && !this.renderedPosition) {
267
-
268
- this.mapMarker = MapboxHelper.createMarker({
269
- dom: this.positionIcon,
270
- iconAnchor: [0, 0],
271
- latitude: position.lat,
272
- longitude: position.lng
273
- }).addTo(this.map);
274
-
275
- } else if (!position && this.renderPosition) {
276
- this.mapMarker.remove();
277
- } else if (position) {
278
- this.mapMarker.setLngLat([position.lng, position.lat]);
279
- }
280
-
281
- this.renderedPosition = position;
282
- this.positionDirty = false;
283
- this.levelForPositionDirty = false;
284
- }
285
-
286
- renderPositionAccuracy() {
287
-
288
- if (!this.positionAccuracyDirty) {
289
- return;
290
- }
291
-
292
- let accuracyToSmall = false;
293
- if (this.positionAccuracy !== null) {
294
-
295
- // https://wiki.openstreetmap.org/wiki/Zoom_levels
296
- const lengthOfATileInMeters = Constants.CIRCUMFERENCE * Math.cos(deg2rad(this.position.lat)) / (2 ** this.map.getZoom());
297
- const lengthOfAPixel = lengthOfATileInMeters / this.map.transform.tileSize;
298
- const radiusInPx = this.position.accuracy / lengthOfAPixel;
299
-
300
- if (radiusInPx < MIN_ACCURACY_CIRCLE_RADIUS) {
301
- accuracyToSmall = true;
302
- } else {
303
- this.accuracyCircle.style.width = `${radiusInPx * 2}px`;
304
- this.accuracyCircle.style.height = `${radiusInPx * 2}px`;
305
- this.accuracyCircle.style.top = `-${radiusInPx}px`;
306
- this.accuracyCircle.style.left = `-${radiusInPx}px`;
307
- }
308
- }
309
-
310
- const renderAccuracy = this.positionAccuracy !== null && !accuracyToSmall;
311
-
312
- if (renderAccuracy && !this.renderAccuracy) {
313
- this.positionIcon.appendChild(this.accuracyCircle);
314
- } else if (!renderAccuracy && this.renderAccuracy) {
315
- this.positionIcon.removeChild(this.accuracyCircle);
316
- }
317
-
318
- this.renderAccuracy = renderAccuracy;
319
- this.positionAccuracyDirty = false;
320
- }
321
-
322
- renderOrientation() {
323
-
324
- if (!this.attitudeDirty || !this.positionIcon) {
325
- return;
326
- }
327
-
328
- if (!this.renderedAttitude && this.attitude) {
329
- this.positionIcon.appendChild(this.compassIcon);
330
- } else if (this.renderedAttitude && !this.attitude) {
331
- this.positionIcon.removeChild(this.compassIcon);
332
- }
333
-
334
- if (this.attitude) {
335
- this.positionIcon.style.transform = 'rotate(' + this.attitude.headingDegrees + 'deg)';
336
- }
337
-
338
- this.renderedAttitude = this.attitude;
339
- this.attitudeDirty = false;
340
- }
341
-
342
- renderCameraCenter() {
343
-
344
- if (!this.positionForCameraDirty || !this.trackUserLocation || !this.position) {
345
- return;
346
- }
347
-
348
- const center = new mapboxgl.LngLat(this.position.lng, this.position.lat);
349
-
350
- let transform;
351
- if (this.trackUserLocationFirst) {
352
-
353
- transform = this.map.cameraForBounds(
354
- center.toBounds(this.position.accuracy),
355
- {
356
- bearing: this.map.getBearing(),
357
- maxZoom: 21,
358
- padding: 100
359
- }
360
- );
361
-
362
- this.trackUserLocationFirst = false;
363
-
364
- } else {
365
- transform = { center };
366
- }
367
-
368
- this.map.jumpTo(transform);
369
-
370
- if (this.position && this.position.level && !this.position.level.isRange
371
- && this.position.level.val !== this.map.getLevel()) {
372
- this.map.setLevel(this.position.level.val);
373
- }
374
-
375
- this.positionForCameraDirty = false;
376
- }
377
-
378
-
379
- /**
380
- * Styling
381
- */
382
-
383
- createDomPosition() {
384
-
385
- // Main element
386
- this.positionIcon = document.createElement('div');
387
-
388
- // Accuracy circle
389
- this.accuracyCircle = document.createElement('div');
390
- this.accuracyCircle.id = 'location-marker-accuracy';
391
- this.positionIcon.appendChild(this.accuracyCircle);
392
-
393
- // Blue dot
394
- this.blueDot = document.createElement('div');
395
- this.blueDot.id = 'location-marker';
396
- this.positionIcon.appendChild(this.blueDot);
397
-
398
- // Compass cone
399
- this.compassIcon = document.createElement('div');
400
- this.compassIcon.id = 'location-marker-compass';
401
-
402
- }
403
-
404
-
405
- createButtons() {
406
-
407
- const topRightContainer = document.getElementsByClassName('mapboxgl-ctrl-top-right')[0];
408
-
409
- const userLocationContainer = document.createElement('div');
410
- userLocationContainer.className = 'mapboxgl-ctrl mapboxgl-ctrl-group';
411
- userLocationContainer.id = 'user-location-container';
412
- topRightContainer.appendChild(userLocationContainer);
413
-
414
- this.createLocateMeButton(userLocationContainer);
415
- this.createStopNavButton(userLocationContainer);
416
- }
417
-
418
- /**
419
- * @param {HTMLDivElement} container
420
- */
421
- createLocateMeButton(container) {
422
-
423
- const buttonLocateMe = document.createElement('button');
424
- this.buttonLocateMe = buttonLocateMe;
425
-
426
- buttonLocateMe.type = 'button';
427
- buttonLocateMe.title = 'Find my location';
428
- buttonLocateMe.className = 'mapboxgl-ctrl-geolocate';
429
- container.appendChild(buttonLocateMe);
430
-
431
- const span = document.createElement('span');
432
- span.className = 'mapboxgl-ctrl-icon';
433
- buttonLocateMe.appendChild(span);
434
-
435
- buttonLocateMe.onclick = () => {
436
- this.trackUserLocation = true;
437
- this.positionForCameraDirty = true;
438
- this.trackUserLocationFirst = true;
439
- this.renderCameraCenter();
440
-
441
- if (!this.positioningStarted) {
442
- this.startPositioning();
443
- }
444
-
445
- };
446
- }
447
-
448
- /**
449
- * @param {HTMLDivElement} container
450
- */
451
- createStopNavButton(container) {
452
-
453
- const buttonStopNav = document.createElement('button');
454
- this.buttonStopNav = buttonStopNav;
455
- buttonStopNav.type = 'button';
456
- buttonStopNav.title = 'Remove my location';
457
- buttonStopNav.className = 'mapboxgl-ctrl-geolocate-remove';
458
- buttonStopNav.style.display = 'none';
459
- container.appendChild(buttonStopNav);
460
-
461
- const span = document.createElement('span');
462
- span.className = 'mapboxgl-ctrl-icon';
463
- buttonStopNav.appendChild(span);
464
-
465
- buttonStopNav.onclick = () => {
466
- this.stopPositioning();
467
- };
468
- }
469
75
  }
470
76
  export default UserOnMapHandler;