@de./sdk 1.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.
Files changed (74) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +4391 -0
  3. package/dist/allend/Access.d.ts +15 -0
  4. package/dist/allend/Access.js +164 -0
  5. package/dist/allend/Access.js.map +1 -0
  6. package/dist/allend/DAuth/index.d.ts +20 -0
  7. package/dist/allend/DAuth/index.js +92 -0
  8. package/dist/allend/DAuth/index.js.map +1 -0
  9. package/dist/allend/DClient/Client.d.ts +10 -0
  10. package/dist/allend/DClient/Client.js +144 -0
  11. package/dist/allend/DClient/Client.js.map +1 -0
  12. package/dist/allend/DClient/Event.d.ts +18 -0
  13. package/dist/allend/DClient/Event.js +100 -0
  14. package/dist/allend/DClient/Event.js.map +1 -0
  15. package/dist/allend/DClient/Order.d.ts +49 -0
  16. package/dist/allend/DClient/Order.js +601 -0
  17. package/dist/allend/DClient/Order.js.map +1 -0
  18. package/dist/allend/IoTClient.d.ts +29 -0
  19. package/dist/allend/IoTClient.js +59 -0
  20. package/dist/allend/IoTClient.js.map +1 -0
  21. package/dist/allend/MSI/Controls.d.ts +256 -0
  22. package/dist/allend/MSI/Controls.js +763 -0
  23. package/dist/allend/MSI/Controls.js.map +1 -0
  24. package/dist/allend/MSI/Handles.d.ts +88 -0
  25. package/dist/allend/MSI/Handles.js +445 -0
  26. package/dist/allend/MSI/Handles.js.map +1 -0
  27. package/dist/allend/MSI/Plugins.d.ts +22 -0
  28. package/dist/allend/MSI/Plugins.js +38 -0
  29. package/dist/allend/MSI/Plugins.js.map +1 -0
  30. package/dist/allend/MSI/index.d.ts +55 -0
  31. package/dist/allend/MSI/index.js +155 -0
  32. package/dist/allend/MSI/index.js.map +1 -0
  33. package/dist/allend/index.d.ts +12 -0
  34. package/dist/allend/index.js +18 -0
  35. package/dist/allend/index.js.map +1 -0
  36. package/dist/backend/Auth.d.ts +38 -0
  37. package/dist/backend/Auth.js +286 -0
  38. package/dist/backend/Auth.js.map +1 -0
  39. package/dist/baseUrl.d.ts +12 -0
  40. package/dist/baseUrl.js +16 -0
  41. package/dist/baseUrl.js.map +1 -0
  42. package/dist/bundle.js +1 -0
  43. package/dist/index.d.ts +13 -0
  44. package/dist/index.js +20 -0
  45. package/dist/index.js.map +1 -0
  46. package/dist/types/access.d.ts +8 -0
  47. package/dist/types/auth.d.ts +27 -0
  48. package/dist/types/index.d.ts +281 -0
  49. package/dist/utils/index.d.ts +5 -0
  50. package/dist/utils/index.js +8 -0
  51. package/dist/utils/index.js.map +1 -0
  52. package/dist/utils/stream.d.ts +20 -0
  53. package/dist/utils/stream.js +63 -0
  54. package/dist/utils/stream.js.map +1 -0
  55. package/package.json +66 -0
  56. package/src/allend/Access.ts +78 -0
  57. package/src/allend/DAuth/index.ts +39 -0
  58. package/src/allend/DClient/Client.ts +76 -0
  59. package/src/allend/DClient/Event.ts +76 -0
  60. package/src/allend/DClient/Order.ts +452 -0
  61. package/src/allend/IoTClient.ts +68 -0
  62. package/src/allend/MSI/Controls.ts +760 -0
  63. package/src/allend/MSI/Handles.ts +387 -0
  64. package/src/allend/MSI/Plugins.ts +52 -0
  65. package/src/allend/MSI/index.ts +160 -0
  66. package/src/allend/index.ts +18 -0
  67. package/src/backend/Auth.ts +201 -0
  68. package/src/baseUrl.ts +13 -0
  69. package/src/index.ts +19 -0
  70. package/src/types/access.d.ts +8 -0
  71. package/src/types/auth.d.ts +27 -0
  72. package/src/types/index.d.ts +281 -0
  73. package/src/utils/index.ts +4 -0
  74. package/src/utils/stream.ts +68 -0
@@ -0,0 +1,760 @@
1
+ import type {
2
+ RTLocation,
3
+ Coordinates,
4
+ MapLayerStyle,
5
+ Caption,
6
+ MapOptions,
7
+ SearchPlace,
8
+ EntitySpecs,
9
+ ActivePosition,
10
+ UserLocationOptions,
11
+ DragPickContentType,
12
+ DragPickContent,
13
+ MapWaypoint,
14
+ Journey,
15
+ RouteOptions,
16
+ RoutesFitBoundsOptions
17
+ } from '../../types'
18
+ import IOF, { Listener } from 'iframe.io'
19
+
20
+ const
21
+ FUNCTION_EVENT_TIMEOUT = 12000,
22
+ FUNCTION_EVENT_TIMEOUT_MESSAGE = 'Event timeout'
23
+
24
+ export default class Controls {
25
+ private options: MapOptions
26
+ private chn: IOF
27
+
28
+ constructor( chn: IOF, options: MapOptions ){
29
+ this.chn = chn
30
+ this.options = options
31
+ }
32
+
33
+ /**
34
+ * Listen to MSI events
35
+ */
36
+ on( event: string, listener: Listener ){
37
+ this.chn.on( event, listener )
38
+ }
39
+ /**
40
+ * Remove a listener of MSI events
41
+ */
42
+ off( event: string, listener: Listener ){
43
+ this.chn.off( event, listener )
44
+ }
45
+ /**
46
+ * Remove all listen of MSI events
47
+ */
48
+ removeListeners( listener: Listener ){
49
+ this.chn.removeListeners( listener )
50
+ }
51
+
52
+ /**
53
+ * Refresh access token to remove server
54
+ *
55
+ * @param token - Latest access token
56
+ */
57
+ refreshToken( token: string ){
58
+ if( !token ) return
59
+ this.options.accessToken = token
60
+ }
61
+
62
+ /**
63
+ * Update map style
64
+ *
65
+ * @param style - Map style ID
66
+ */
67
+ setMapStyle( style: MapLayerStyle ): Promise<void> {
68
+ return new Promise( ( resolve, reject ) => {
69
+ // Set timeout
70
+ const timeout = setTimeout( () => reject( FUNCTION_EVENT_TIMEOUT_MESSAGE ), FUNCTION_EVENT_TIMEOUT )
71
+ // Set style
72
+ this.chn.emit('set:map:style', style, ( error: string | boolean ) => {
73
+ if( error ) return reject( error )
74
+
75
+ clearTimeout( timeout )
76
+ resolve()
77
+ } )
78
+ })
79
+ }
80
+
81
+ /**
82
+ * @return - User's current GPS location
83
+ */
84
+ getCurrentLocation(): Promise<RTLocation | null> {
85
+ return new Promise( ( resolve, reject ) => {
86
+ // Set timeout
87
+ const timeout = setTimeout( () => reject( FUNCTION_EVENT_TIMEOUT_MESSAGE ), FUNCTION_EVENT_TIMEOUT )
88
+ // Get current location
89
+ this.chn.emit('get:current:location', ( error: string | boolean, location: RTLocation ) => {
90
+ if( error ) return reject( error )
91
+
92
+ clearTimeout( timeout )
93
+ resolve( location )
94
+ } )
95
+ } )
96
+ }
97
+ /**
98
+ * Pin user's current location on the current active map
99
+ *
100
+ * @return - User's current GPS location coordinates or `null` when it failed
101
+ */
102
+ pinCurrentLocation(): Promise<Coordinates | null> {
103
+ return new Promise( ( resolve, reject ) => {
104
+ // Set timeout
105
+ const timeout = setTimeout( () => reject( FUNCTION_EVENT_TIMEOUT_MESSAGE ), FUNCTION_EVENT_TIMEOUT )
106
+ // Pin user's current location on the map
107
+ this.chn.emit('pin:current:location', ( error: string | boolean, location: Coordinates | null ) => {
108
+ if( error ) return reject( error )
109
+
110
+ clearTimeout( timeout )
111
+ resolve( location )
112
+ } )
113
+ } )
114
+ }
115
+
116
+ /**
117
+ * Set live location tracking options
118
+ *
119
+ * @param options - User location tracking options
120
+ */
121
+ setLiveLocationOptions( options: UserLocationOptions ): Promise<void> {
122
+ return new Promise( ( resolve, reject ) => {
123
+ // Set timeout
124
+ const timeout = setTimeout( () => reject( FUNCTION_EVENT_TIMEOUT_MESSAGE ), FUNCTION_EVENT_TIMEOUT )
125
+ // Set live location options
126
+ this.chn.emit('set:live:options', options, ( error: string | boolean ) => {
127
+ if( error ) return reject( error )
128
+
129
+ clearTimeout( timeout )
130
+ resolve()
131
+ } )
132
+ } )
133
+ }
134
+ /**
135
+ * Start tracking user's live location
136
+ */
137
+ trackLiveLocation(): Promise<void> {
138
+ return new Promise( ( resolve, reject ) => {
139
+ // Set timeout
140
+ const timeout = setTimeout( () => reject( FUNCTION_EVENT_TIMEOUT_MESSAGE ), FUNCTION_EVENT_TIMEOUT )
141
+ // Start live location tracking
142
+ this.chn.emit('track:live:location', ( error: string | boolean ) => {
143
+ if( error ) return reject( error )
144
+
145
+ clearTimeout( timeout )
146
+ resolve()
147
+ } )
148
+ } )
149
+ }
150
+ /**
151
+ * Stop tracking user's live location
152
+ */
153
+ untrackLiveLocation(): Promise<void> {
154
+ return new Promise( ( resolve, reject ) => {
155
+ // Set timeout
156
+ const timeout = setTimeout( () => reject( FUNCTION_EVENT_TIMEOUT_MESSAGE ), FUNCTION_EVENT_TIMEOUT )
157
+ // Stop live location tracking
158
+ this.chn.emit('untrack:live:location', ( error: string | boolean ) => {
159
+ if( error ) return reject( error )
160
+
161
+ clearTimeout( timeout )
162
+ resolve()
163
+ } )
164
+ } )
165
+ }
166
+
167
+ /**
168
+ * Enable drag pick functionality
169
+ *
170
+ * @param location - (Optional) Initial location for drag pick
171
+ */
172
+ enableDragPickLocation( location: Coordinates ): Promise<void> {
173
+ return new Promise( ( resolve, reject ) => {
174
+ // Set timeout
175
+ const timeout = setTimeout( () => reject( FUNCTION_EVENT_TIMEOUT_MESSAGE ), FUNCTION_EVENT_TIMEOUT )
176
+ // Enable drag pick
177
+ this.chn.emit('enable:dragpick:location', location, ( error: string | boolean ) => {
178
+ if( error ) return reject( error )
179
+
180
+ clearTimeout( timeout )
181
+ resolve()
182
+ } )
183
+ } )
184
+ }
185
+ /**
186
+ * Disable drag pick functionality
187
+ */
188
+ disableDragPickLocation(): Promise<void> {
189
+ return new Promise( ( resolve, reject ) => {
190
+ // Set timeout
191
+ const timeout = setTimeout( () => reject( FUNCTION_EVENT_TIMEOUT_MESSAGE ), FUNCTION_EVENT_TIMEOUT )
192
+ // Disable drag pick
193
+ this.chn.emit('disable:dragpick:location', ( error: string | boolean ) => {
194
+ if( error ) return reject( error )
195
+
196
+ clearTimeout( timeout )
197
+ resolve()
198
+ } )
199
+ } )
200
+ }
201
+ /**
202
+ * Set drag pick content
203
+ *
204
+ * @param type - Content type for drag pick
205
+ * @param content - Content data for drag pick
206
+ */
207
+ setDragPickContent( type: DragPickContentType, content: DragPickContent ): Promise<void> {
208
+ return new Promise( ( resolve, reject ) => {
209
+ // Set timeout
210
+ const timeout = setTimeout( () => reject( FUNCTION_EVENT_TIMEOUT_MESSAGE ), FUNCTION_EVENT_TIMEOUT )
211
+ // Set drag pick content
212
+ this.chn.emit('set:dragpick:content', { type, content }, ( error: string | boolean ) => {
213
+ if( error ) return reject( error )
214
+
215
+ clearTimeout( timeout )
216
+ resolve()
217
+ } )
218
+ } )
219
+ }
220
+
221
+ /**
222
+ * Get a location coordinates of placed that matched this name
223
+ *
224
+ * @param name - Place name to resolve
225
+ * @return - Array list of coordinates
226
+ */
227
+ resolvePlace( name: string ): Promise<Coordinates | null> {
228
+ return new Promise( ( resolve, reject ) => {
229
+ // Set timeout
230
+ const timeout = setTimeout( () => reject( FUNCTION_EVENT_TIMEOUT_MESSAGE ), FUNCTION_EVENT_TIMEOUT )
231
+ // Get location coordinates from place name
232
+ this.chn.emit('resolve:place', name, ( error: string | boolean, data: any ) => {
233
+ if( error ) return reject( error )
234
+
235
+ clearTimeout( timeout )
236
+ resolve( data )
237
+ } )
238
+ } )
239
+ }
240
+ /**
241
+ * Get a location details of placed that matched this coordinates
242
+ *
243
+ * @param coords - Coordinates
244
+ * @return - Array list of geocoding data
245
+ */
246
+ resolveCoordinates( coords: Coordinates | string ): Promise<Coordinates | null> {
247
+ return new Promise( ( resolve, reject ) => {
248
+ // Set timeout
249
+ const timeout = setTimeout( () => reject( FUNCTION_EVENT_TIMEOUT_MESSAGE ), FUNCTION_EVENT_TIMEOUT )
250
+ // Get location place from coordinates
251
+ this.chn.emit('resolve:coordinates', coords, ( error: string | boolean, data: any ) => {
252
+ if( error ) return reject( error )
253
+
254
+ clearTimeout( timeout )
255
+ resolve( data )
256
+ } )
257
+ } )
258
+ }
259
+
260
+ /**
261
+ * Search a location or places
262
+ *
263
+ * @param input - Place in string
264
+ * @return - Autocompletion list matched places
265
+ */
266
+ searchQuery( input: string ): Promise<string[]> {
267
+ return new Promise( ( resolve, reject ) => {
268
+ // Set timeout
269
+ const timeout = setTimeout( () => reject( FUNCTION_EVENT_TIMEOUT_MESSAGE ), FUNCTION_EVENT_TIMEOUT )
270
+ // Launch search query
271
+ this.chn.emit('search:query', input, ( error: string | boolean, data: any ) => {
272
+ if( error ) return reject( error )
273
+
274
+ clearTimeout( timeout )
275
+ resolve( data )
276
+ } )
277
+ } )
278
+ }
279
+ /**
280
+ * Select a suggested place by the search
281
+ *
282
+ * @param index - Index of place in suggested list
283
+ * @return - More details of selected place
284
+ */
285
+ searchSelect( index: number ): Promise<SearchPlace | null> {
286
+ return new Promise( ( resolve, reject ) => {
287
+ // Set timeout
288
+ const timeout = setTimeout( () => reject( FUNCTION_EVENT_TIMEOUT_MESSAGE ), FUNCTION_EVENT_TIMEOUT )
289
+ // Get place's details
290
+ this.chn.emit('search:select', index, ( error: string | boolean, data: SearchPlace | null ) => {
291
+ if( error ) return reject( error )
292
+
293
+ clearTimeout( timeout )
294
+ resolve( data )
295
+ } )
296
+ } )
297
+ }
298
+
299
+ /**
300
+ * Show nearby entities around coordinates
301
+ *
302
+ * @param list - Array of entity specifications
303
+ */
304
+ showNearby( list: EntitySpecs[] ): Promise<void> {
305
+ return new Promise( ( resolve, reject ) => {
306
+ // Set timeout
307
+ const timeout = setTimeout( () => reject( FUNCTION_EVENT_TIMEOUT_MESSAGE ), FUNCTION_EVENT_TIMEOUT )
308
+ // Show nearby entities
309
+ this.chn.emit('show:nearby', list, ( error: string | boolean ) => {
310
+ if( error ) return reject( error )
311
+
312
+ clearTimeout( timeout )
313
+ resolve()
314
+ } )
315
+ } )
316
+ }
317
+ /**
318
+ * Remove all displaying nearby entities
319
+ */
320
+ removeNearby(): Promise<void> {
321
+ return new Promise( ( resolve, reject ) => {
322
+ // Set timeout
323
+ const timeout = setTimeout( () => reject( FUNCTION_EVENT_TIMEOUT_MESSAGE ), FUNCTION_EVENT_TIMEOUT )
324
+ // Remove nearby entities
325
+ this.chn.emit('remove:nearby', ( error: string | boolean ) => {
326
+ if( error ) return reject( error )
327
+
328
+ clearTimeout( timeout )
329
+ resolve()
330
+ } )
331
+ } )
332
+ }
333
+ /**
334
+ * Add a new nearby entity
335
+ *
336
+ * @param entity - Entity specification
337
+ */
338
+ addNearbyEntity( entity: EntitySpecs ): Promise<void> {
339
+ return new Promise( ( resolve, reject ) => {
340
+ // Set timeout
341
+ const timeout = setTimeout( () => reject( FUNCTION_EVENT_TIMEOUT_MESSAGE ), FUNCTION_EVENT_TIMEOUT )
342
+ // Add nearby entity
343
+ this.chn.emit('add:nearby:entity', entity, ( error: string | boolean ) => {
344
+ if( error ) return reject( error )
345
+
346
+ clearTimeout( timeout )
347
+ resolve()
348
+ } )
349
+ } )
350
+ }
351
+ /**
352
+ * Update a nearby entity position
353
+ *
354
+ * @param activePosition - Entity ID and new position
355
+ */
356
+ moveNearbyEntity( activePosition: ActivePosition ): Promise<void> {
357
+ return new Promise( ( resolve, reject ) => {
358
+ // Set timeout
359
+ const timeout = setTimeout( () => reject( FUNCTION_EVENT_TIMEOUT_MESSAGE ), FUNCTION_EVENT_TIMEOUT )
360
+ // Move nearby entity
361
+ this.chn.emit('move:nearby:entity', activePosition, ( error: string | boolean ) => {
362
+ if( error ) return reject( error )
363
+
364
+ clearTimeout( timeout )
365
+ resolve()
366
+ } )
367
+ } )
368
+ }
369
+ /**
370
+ * Remove a nearby entity
371
+ *
372
+ * @param id - Entity ID to remove
373
+ */
374
+ removeNearbyEntity( id: string ): Promise<void> {
375
+ return new Promise( ( resolve, reject ) => {
376
+ // Set timeout
377
+ const timeout = setTimeout( () => reject( FUNCTION_EVENT_TIMEOUT_MESSAGE ), FUNCTION_EVENT_TIMEOUT )
378
+ // Remove nearby entity
379
+ this.chn.emit('remove:nearby:entity', id, ( error: string | boolean ) => {
380
+ if( error ) return reject( error )
381
+
382
+ clearTimeout( timeout )
383
+ resolve()
384
+ } )
385
+ } )
386
+ }
387
+
388
+ /**
389
+ * Set complete route with journey specifications
390
+ *
391
+ * @param journey - Journey specifications including route ID, origin, destination, waypoints, and options
392
+ */
393
+ setRoute( journey: Journey ): Promise<void> {
394
+ return new Promise( ( resolve, reject ) => {
395
+ // Set timeout
396
+ const timeout = setTimeout( () => reject( FUNCTION_EVENT_TIMEOUT_MESSAGE ), FUNCTION_EVENT_TIMEOUT )
397
+ // Set route
398
+ this.chn.emit('set:route', journey, ( error: string | boolean ) => {
399
+ if( error ) return reject( error )
400
+
401
+ clearTimeout( timeout )
402
+ resolve()
403
+ } )
404
+ } )
405
+ }
406
+ /**
407
+ * Set route origin
408
+ *
409
+ * @param routeId - Route identifier
410
+ * @param point - Waypoint specification for origin
411
+ */
412
+ setRouteOrigin( routeId: string, point: MapWaypoint ): Promise<void> {
413
+ return new Promise( ( resolve, reject ) => {
414
+ // Set timeout
415
+ const timeout = setTimeout( () => reject( FUNCTION_EVENT_TIMEOUT_MESSAGE ), FUNCTION_EVENT_TIMEOUT )
416
+ // Set route origin
417
+ this.chn.emit('set:route:origin', { routeId, point }, ( error: string | boolean ) => {
418
+ if( error ) return reject( error )
419
+
420
+ clearTimeout( timeout )
421
+ resolve()
422
+ } )
423
+ } )
424
+ }
425
+ /**
426
+ * Remove route origin
427
+ *
428
+ * @param routeId - Route identifier
429
+ */
430
+ removeRouteOrigin( routeId: string ): Promise<void> {
431
+ return new Promise( ( resolve, reject ) => {
432
+ // Set timeout
433
+ const timeout = setTimeout( () => reject( FUNCTION_EVENT_TIMEOUT_MESSAGE ), FUNCTION_EVENT_TIMEOUT )
434
+ // Remove route origin
435
+ this.chn.emit('remove:route:origin', { routeId }, ( error: string | boolean ) => {
436
+ if( error ) return reject( error )
437
+
438
+ clearTimeout( timeout )
439
+ resolve()
440
+ } )
441
+ } )
442
+ }
443
+ /**
444
+ * Set route destination
445
+ *
446
+ * @param routeId - Route identifier
447
+ * @param point - Waypoint specification for destination
448
+ */
449
+ setRouteDestination( routeId: string, point: MapWaypoint ): Promise<void> {
450
+ return new Promise( ( resolve, reject ) => {
451
+ // Set timeout
452
+ const timeout = setTimeout( () => reject( FUNCTION_EVENT_TIMEOUT_MESSAGE ), FUNCTION_EVENT_TIMEOUT )
453
+ // Set route destination
454
+ this.chn.emit('set:route:destination', { routeId, point }, ( error: string | boolean ) => {
455
+ if( error ) return reject( error )
456
+
457
+ clearTimeout( timeout )
458
+ resolve()
459
+ } )
460
+ } )
461
+ }
462
+ /**
463
+ * Remove route destination
464
+ *
465
+ * @param routeId - Route identifier
466
+ */
467
+ removeRouteDestination( routeId: string ): Promise<void> {
468
+ return new Promise( ( resolve, reject ) => {
469
+ // Set timeout
470
+ const timeout = setTimeout( () => reject( FUNCTION_EVENT_TIMEOUT_MESSAGE ), FUNCTION_EVENT_TIMEOUT )
471
+ // Remove route destination
472
+ this.chn.emit('remove:route:destination', { routeId }, ( error: string | boolean ) => {
473
+ if( error ) return reject( error )
474
+
475
+ clearTimeout( timeout )
476
+ resolve()
477
+ } )
478
+ } )
479
+ }
480
+ /**
481
+ * Add a route waypoint
482
+ *
483
+ * @param routeId - Route identifier
484
+ * @param point - Waypoint specification
485
+ */
486
+ addRouteWaypoint( routeId: string, point: MapWaypoint ): Promise<void> {
487
+ return new Promise( ( resolve, reject ) => {
488
+ // Set timeout
489
+ const timeout = setTimeout( () => reject( FUNCTION_EVENT_TIMEOUT_MESSAGE ), FUNCTION_EVENT_TIMEOUT )
490
+ // Add route waypoint
491
+ this.chn.emit('add:route:waypoint', { routeId, point }, ( error: string | boolean ) => {
492
+ if( error ) return reject( error )
493
+
494
+ clearTimeout( timeout )
495
+ resolve()
496
+ } )
497
+ } )
498
+ }
499
+ /**
500
+ * Update a route waypoint
501
+ *
502
+ * @param routeId - Route identifier
503
+ * @param point - Waypoint specification with index
504
+ */
505
+ updateRouteWaypoint( routeId: string, point: MapWaypoint ): Promise<void> {
506
+ return new Promise( ( resolve, reject ) => {
507
+ // Set timeout
508
+ const timeout = setTimeout( () => reject( FUNCTION_EVENT_TIMEOUT_MESSAGE ), FUNCTION_EVENT_TIMEOUT )
509
+ // Update route waypoint
510
+ this.chn.emit('update:route:waypoint', { routeId, point }, ( error: string | boolean ) => {
511
+ if( error ) return reject( error )
512
+
513
+ clearTimeout( timeout )
514
+ resolve()
515
+ } )
516
+ } )
517
+ }
518
+ /**
519
+ * Remove a route waypoint
520
+ *
521
+ * @param routeId - Route identifier
522
+ * @param index - Waypoint index to remove
523
+ */
524
+ removeRouteWaypoint( routeId: string, index: number ): Promise<void> {
525
+ return new Promise( ( resolve, reject ) => {
526
+ // Set timeout
527
+ const timeout = setTimeout( () => reject( FUNCTION_EVENT_TIMEOUT_MESSAGE ), FUNCTION_EVENT_TIMEOUT )
528
+ // Remove route waypoint
529
+ this.chn.emit('remove:route:waypoint', { routeId, index }, ( error: string | boolean ) => {
530
+ if( error ) return reject( error )
531
+
532
+ clearTimeout( timeout )
533
+ resolve()
534
+ } )
535
+ } )
536
+ }
537
+
538
+ /**
539
+ * Fit route bounds
540
+ *
541
+ * @param routeId - Route identifier
542
+ * @param margin - Margin in px
543
+ */
544
+ fitRouteBounds( routeId: string, margin?: number ): Promise<void> {
545
+ return new Promise( ( resolve, reject ) => {
546
+ // Set timeout
547
+ const timeout = setTimeout( () => reject( FUNCTION_EVENT_TIMEOUT_MESSAGE ), FUNCTION_EVENT_TIMEOUT )
548
+
549
+ this.chn.emit('fit:route:bounds', { routeId, margin }, ( error: string | boolean ) => {
550
+ if( error ) return reject( error )
551
+
552
+ clearTimeout( timeout )
553
+ resolve()
554
+ } )
555
+ } )
556
+ }
557
+ /**
558
+ * Fit all/many routes bounds
559
+ *
560
+ * @param options - Routes fit bounds options
561
+ */
562
+ fitRoutesBounds( options: RoutesFitBoundsOptions ): Promise<void> {
563
+ return new Promise( ( resolve, reject ) => {
564
+ // Set timeout
565
+ const timeout = setTimeout( () => reject( FUNCTION_EVENT_TIMEOUT_MESSAGE ), FUNCTION_EVENT_TIMEOUT )
566
+
567
+ this.chn.emit('fit:routes:bounds', options, ( error: string | boolean ) => {
568
+ if( error ) return reject( error )
569
+
570
+ clearTimeout( timeout )
571
+ resolve()
572
+ } )
573
+ } )
574
+ }
575
+
576
+ /**
577
+ * Set waypoint caption
578
+ *
579
+ * @param routeId - Route identifier
580
+ * @param id - Waypoint identifier (string or number)
581
+ * @param caption - Caption information to set
582
+ */
583
+ setWaypointCaption( routeId: string, id: string | number, caption: Caption ): Promise<void> {
584
+ return new Promise( ( resolve, reject ) => {
585
+ // Set timeout
586
+ const timeout = setTimeout( () => reject( FUNCTION_EVENT_TIMEOUT_MESSAGE ), FUNCTION_EVENT_TIMEOUT )
587
+ // Set waypoint caption
588
+ this.chn.emit('set:waypoint:caption', { routeId, id, caption }, ( error: string | boolean ) => {
589
+ if( error ) return reject( error )
590
+
591
+ clearTimeout( timeout )
592
+ resolve()
593
+ } )
594
+ } )
595
+ }
596
+ /**
597
+ * Update waypoint caption
598
+ *
599
+ * @param routeId - Route identifier
600
+ * @param id - Waypoint identifier (string or number)
601
+ * @param caption - Caption information to update
602
+ */
603
+ updateWaypointCaption( routeId: string, id: string | number, caption: Caption ): Promise<void> {
604
+ return new Promise( ( resolve, reject ) => {
605
+ // Set timeout
606
+ const timeout = setTimeout( () => reject( FUNCTION_EVENT_TIMEOUT_MESSAGE ), FUNCTION_EVENT_TIMEOUT )
607
+ // Update waypoint caption
608
+ this.chn.emit('update:waypoint:caption', { routeId, id, caption }, ( error: string | boolean ) => {
609
+ if( error ) return reject( error )
610
+
611
+ clearTimeout( timeout )
612
+ resolve()
613
+ } )
614
+ } )
615
+ }
616
+ /**
617
+ * Remove waypoint caption
618
+ *
619
+ * @param routeId - Route identifier
620
+ * @param id - Waypoint identifier (string or number)
621
+ */
622
+ removeWaypointCaption( routeId: string, id: string | number ): Promise<void> {
623
+ return new Promise( ( resolve, reject ) => {
624
+ // Set timeout
625
+ const timeout = setTimeout( () => reject( FUNCTION_EVENT_TIMEOUT_MESSAGE ), FUNCTION_EVENT_TIMEOUT )
626
+ // Remove waypoint caption
627
+ this.chn.emit('remove:waypoint:caption', { routeId, id }, ( error: string | boolean ) => {
628
+ if( error ) return reject( error )
629
+
630
+ clearTimeout( timeout )
631
+ resolve()
632
+ } )
633
+ } )
634
+ }
635
+
636
+ /**
637
+ * Mount navigation route
638
+ *
639
+ * @param routeId - Route identifier for navigation
640
+ */
641
+ mountNavigation( routeId: string | number ): Promise<void> {
642
+ return new Promise( ( resolve, reject ) => {
643
+ // Set timeout
644
+ const timeout = setTimeout( () => reject( FUNCTION_EVENT_TIMEOUT_MESSAGE ), FUNCTION_EVENT_TIMEOUT )
645
+ // Mount navigation
646
+ this.chn.emit('mount:navigation', routeId, ( error: string | boolean ) => {
647
+ if( error ) return reject( error )
648
+
649
+ clearTimeout( timeout )
650
+ resolve()
651
+ } )
652
+ } )
653
+ }
654
+ /**
655
+ * Unmount navigation route
656
+ */
657
+ unmountNavigation(): Promise<void> {
658
+ return new Promise( ( resolve, reject ) => {
659
+ // Set timeout
660
+ const timeout = setTimeout( () => reject( FUNCTION_EVENT_TIMEOUT_MESSAGE ), FUNCTION_EVENT_TIMEOUT )
661
+ // Unmount navigation
662
+ this.chn.emit('unmount:navigation', ( error: string | boolean ) => {
663
+ if( error ) return reject( error )
664
+
665
+ clearTimeout( timeout )
666
+ resolve()
667
+ } )
668
+ } )
669
+ }
670
+ /**
671
+ * Load navigation direction
672
+ */
673
+ loadNavigation(): Promise<void> {
674
+ return new Promise( ( resolve, reject ) => {
675
+ // Set timeout
676
+ const timeout = setTimeout( () => reject( FUNCTION_EVENT_TIMEOUT_MESSAGE ), FUNCTION_EVENT_TIMEOUT )
677
+ // Load navigation
678
+ this.chn.emit('load:navigation', ( error: string | boolean ) => {
679
+ if( error ) return reject( error )
680
+
681
+ clearTimeout( timeout )
682
+ resolve()
683
+ } )
684
+ } )
685
+ }
686
+ /**
687
+ * Set initial navigation position
688
+ *
689
+ * @param position - Initial GPS location for navigation
690
+ */
691
+ setInitialNavigationPosition( position: RTLocation ): Promise<void> {
692
+ return new Promise( ( resolve, reject ) => {
693
+ // Set timeout
694
+ const timeout = setTimeout( () => reject( FUNCTION_EVENT_TIMEOUT_MESSAGE ), FUNCTION_EVENT_TIMEOUT )
695
+ // Set initial navigation position
696
+ this.chn.emit('initial:navigation:position', position, ( error: string | boolean ) => {
697
+ if( error ) return reject( error )
698
+
699
+ clearTimeout( timeout )
700
+ resolve()
701
+ } )
702
+ } )
703
+ }
704
+ /**
705
+ * Navigate to new position
706
+ *
707
+ * @param position - Current GPS location for navigation update
708
+ */
709
+ navigate( position: RTLocation ): Promise<void> {
710
+ return new Promise( ( resolve, reject ) => {
711
+ // Set timeout
712
+ const timeout = setTimeout( () => reject( FUNCTION_EVENT_TIMEOUT_MESSAGE ), FUNCTION_EVENT_TIMEOUT )
713
+ // Navigate
714
+ this.chn.emit('navigate:navigation:direction', position, ( error: string | boolean ) => {
715
+ if( error ) return reject( error )
716
+
717
+ clearTimeout( timeout )
718
+ resolve()
719
+ } )
720
+ } )
721
+ }
722
+ /**
723
+ * Upsert navigation direction data
724
+ *
725
+ * @param routeId - Route identifier for navigation
726
+ * @param direction - Direction data
727
+ * @param position - (Optional) Current GPS position
728
+ * @params options - Route options
729
+ */
730
+ casting( routeId: string | number, direction: any, position?: RTLocation, options?: RouteOptions ): Promise<void> {
731
+ return new Promise( ( resolve, reject ) => {
732
+
733
+ // Set timeout
734
+ const timeout = setTimeout( () => reject( FUNCTION_EVENT_TIMEOUT_MESSAGE ), FUNCTION_EVENT_TIMEOUT )
735
+ // Casting navigation direction
736
+ this.chn.emit('casting:navigation:direction', { routeId, direction, position, options }, ( error: string | boolean ) => {
737
+ if( error ) return reject( error )
738
+
739
+ clearTimeout( timeout )
740
+ resolve()
741
+ } )
742
+ } )
743
+ }
744
+ /**
745
+ * Dismiss navigation
746
+ */
747
+ dismissNavigation(): Promise<void> {
748
+ return new Promise( ( resolve, reject ) => {
749
+ // Set timeout
750
+ const timeout = setTimeout( () => reject( FUNCTION_EVENT_TIMEOUT_MESSAGE ), FUNCTION_EVENT_TIMEOUT )
751
+ // Dismiss navigation
752
+ this.chn.emit('dismiss:navigation', ( error: string | boolean ) => {
753
+ if( error ) return reject( error )
754
+
755
+ clearTimeout( timeout )
756
+ resolve()
757
+ } )
758
+ } )
759
+ }
760
+ }