File : main/Constants.js

1
/*
2
Copyright - 2017 2023 - wwwouaiebe - Contact: https://www.ouaie.be/
3
4
This  program is free software;
5
you can redistribute it and/or modify it under the terms of the
6
GNU General Public License as published by the Free Software Foundation;
7
either version 3 of the License, or any later version.
8
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
GNU General Public License for more details.
13
14
You should have received a copy of the GNU General Public License
15
along with this program; if not, write to the Free Software
16
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17
*/
18
/*
19
Changes:
20
    - v4.0.0:
21
        - created from v3.6.0
22
Doc reviewed 202208
23
 */
24
25
/* eslint-disable no-magic-numbers */
26
/* eslint-disable max-classes-per-file */
27
28
/* ------------------------------------------------------------------------------------------------------------------------- */
29
/**
30
Enum for angular operations
31
*/
32
/* ------------------------------------------------------------------------------------------------------------------------- */
33
34
class DEGREES {
35
36
    /**
37
38
    @type {Number}
39
    */
40
41
    static get d0 ( ) { return 0; }
42
43
    /**
44
    90°
45
    @type {Number}
46
    */
47
48
    static get d90 ( ) { return 90; }
49
50
    /**
51
    180°
52
    @type {Number}
53
    */
54
55
    static get d180 ( ) { return 180; }
56
57
    /**
58
    270°
59
    @type {Number}
60
    */
61
62
    static get d270 ( ) { return 270; }
63
64
    /**
65
    360°
66
    @type {Number}
67
    */
68
69
    static get d360 ( ) { return 360; }
70
71
    /**
72
    540°
73
    @type {Number}
74
    */
75
76
    static get d540 ( ) { return 540; }
77
78
    /**
79
    Conversion ° to radians
80
    @type {Number}
81
    */
82
83
    static get toRadians ( ) { return Math.PI / 180; }
84
85
    /**
86
    Conversion radians to °
87
    @type {Number}
88
    */
89
90
    static get fromRadians ( ) { return 180 / Math.PI; }
91
}
92
93
/* ------------------------------------------------------------------------------------------------------------------------- */
94
/**
95
Enum for distances
96
*/
97
/* ------------------------------------------------------------------------------------------------------------------------- */
98
99
class DISTANCE {
100
101
    /**
102
    The decimal length used for distances
103
    @type {Number}
104
    */
105
106
    static get fixed ( ) { return 2; }
107
108
    /**
109
    The distance is invalid
110
    @type {Number}
111
    */
112
113
    static get invalid ( ) { return -1; }
114
115
    /**
116
    Default value for distances
117
    @type {Number}
118
    */
119
120
    static get defaultValue ( ) { return 0; }
121
122
    /**
123
    Meters in one kilometer
124
    @type {Number}
125
    */
126
127
    static get metersInKm ( ) { return 1000; }
128
}
129
130
/* ------------------------------------------------------------------------------------------------------------------------- */
131
/**
132
Enum for elevations
133
*/
134
/* ------------------------------------------------------------------------------------------------------------------------- */
135
136
class ELEV {
137
138
    /**
139
    The decimal length used for elevation
140
    @type {Number}
141
    */
142
143
    static get fixed ( ) { return 2; }
144
145
    /**
146
    Default value for elevation
147
    @type {Number}
148
    */
149
150
    static get defaultValue ( ) { return 0; }
151
}
152
153
/* ------------------------------------------------------------------------------------------------------------------------- */
154
/**
155
Enum for geolocation status
156
*/
157
/* ------------------------------------------------------------------------------------------------------------------------- */
158
159
class GEOLOCATION_STATUS {
160
161
    /**
162
    The user don't accept to be localized
163
    @type {Number}
164
    */
165
166
    static get refusedByUser ( ) { return -1; }
167
168
    /**
169
    The geolocation is not available (disabled in the browser or unsecure context)
170
    @type {Number}
171
    */
172
173
    static get disabled ( ) { return 0; }
174
175
    /**
176
    The geolocation is inactive
177
    @type {Number}
178
    */
179
180
    static get inactive ( ) { return 1; }
181
182
    /**
183
    The geolocation is active
184
    @type {Number}
185
    */
186
187
    static get active ( ) { return 2; }
188
}
189
190
/* ------------------------------------------------------------------------------------------------------------------------- */
191
/**
192
Enum for default icon dimensions
193
*/
194
/* ------------------------------------------------------------------------------------------------------------------------- */
195
196
class ICON_DIMENSIONS {
197
198
    /**
199
    The default width
200
    @type {Number}
201
    */
202
203
    static get width ( ) { return 40; }
204
205
    /**
206
    The default height
207
    @type {Number}
208
    */
209
210
    static get height ( ) { return 40; }
211
212
    /**
213
    The viewbox size for svg icons
214
    @type {Number}
215
    */
216
217
    static get svgViewboxDim ( ) { return 200; }
218
}
219
220
/* ------------------------------------------------------------------------------------------------------------------------- */
221
/**
222
Enum for map svg icons
223
*/
224
/* ------------------------------------------------------------------------------------------------------------------------- */
225
226
class ICON_POSITION {
227
228
    /**
229
    The icon is on the start point
230
    @type {Number}
231
    */
232
233
    static get atStart ( ) { return -1; }
234
235
    /**
236
    The icon is between the start point and end point
237
    @type {Number}
238
    */
239
240
    static get onRoute ( ) { return 0; }
241
242
    /**
243
    The icon is on the end point
244
    @type {Number}
245
    */
246
247
    static get atEnd ( ) { return 1; }
248
}
249
250
/* ------------------------------------------------------------------------------------------------------------------------- */
251
/**
252
Enum for latitude and longitude
253
*/
254
/* ------------------------------------------------------------------------------------------------------------------------- */
255
256
class LAT_LNG {
257
258
    /**
259
    Default value for latitude and longitude
260
    @type {Number}
261
    */
262
263
    static get defaultValue ( ) { return 0; }
264
265
    /**
266
    The decimal length used for latitude and longitude
267
    @type {Number}
268
    */
269
270
    static get fixed ( ) { return 6; }
271
272
    /**
273
    The max possibe lat
274
    @type {Number}
275
    */
276
277
    static get maxLat ( ) { return 90; }
278
279
    /**
280
    The min possibe lat
281
    @type {Number}
282
    */
283
284
    static get minLat ( ) { return -90; }
285
286
    /**
287
    The max possibe lng
288
    @type {Number}
289
    */
290
291
    static get maxLng ( ) { return 180; }
292
293
    /**
294
    The min possibe lng
295
    @type {Number}
296
    */
297
298
    static get minLng ( ) { return -180; }
299
}
300
301
/* ------------------------------------------------------------------------------------------------------------------------- */
302
/**
303
Enum for edition status of a route
304
*/
305
/* ------------------------------------------------------------------------------------------------------------------------- */
306
307
class ROUTE_EDITION_STATUS {
308
309
    /**
310
    The route is currently not edited
311
    @type {Number}
312
    */
313
314
    static get notEdited ( ) { return 0; }
315
316
    /**
317
    The route is currently edited but without changes
318
    @type {Number}
319
    */
320
321
    static get editedNoChange ( ) { return 1; }
322
323
    /**
324
    The route is currently edited and changed
325
    @type {Number}
326
    */
327
328
    static get editedChanged ( ) { return 2; }
329
}
330
331
/* ------------------------------------------------------------------------------------------------------------------------- */
332
/**
333
Enum for the save status displayed with the coordinates and zoom values
334
*/
335
/* ------------------------------------------------------------------------------------------------------------------------- */
336
337
class SAVE_STATUS {
338
339
    /**
340
    The string to display when the travel is modified since more than 5 minutes
341
    @type {String}
342
    */
343
344
    static get notSaved ( ) { return '🔴'; }
345
346
    /**
347
    The string to display when the travel is modified since less than 5 minutes
348
    @type {String}
349
    */
350
351
    static get modified ( ) { return '🟡'; }
352
353
    /**
354
    The string to display when the travel is not modified
355
    @type {String}
356
    */
357
358
    static get saved ( ) { return '🟢'; }
359
}
360
361
/* ------------------------------------------------------------------------------------------------------------------------- */
362
/**
363
Enum for the toolbars position
364
*/
365
/* ------------------------------------------------------------------------------------------------------------------------- */
366
367
class TOOLBAR_POSITION {
368
369
    /**
370
    The toolbar will be displayed on the top left corner of the screen
371
    @type {String}
372
    */
373
374
    static get topLeft ( ) { return 'TravelNotes-BaseToolbar-TopLeft'; }
375
376
    /**
377
    The toolbar will be displayed on the top right corner of the screen
378
    @type {String}
379
    */
380
381
    static get topRight ( ) { return 'TravelNotes-BaseToolbar-TopRight'; }
382
383
    /**
384
    The toolbar will be displayed on the bottom left corner of the screen
385
    @type {String}
386
    */
387
388
    static get bottomLeft ( ) { return 'TravelNotes-BaseToolbar-BottomLeft'; }
389
390
    /**
391
    The toolbar will be displayed on the bottom right corner of the screen
392
    @type {String}
393
    */
394
395
    static get bottomRight ( ) { return 'TravelNotes-BaseToolbar-BottomRight'; }
396
397
}
398
399
/* ------------------------------------------------------------------------------------------------------------------------- */
400
/**
401
The margin around the map where drag of dialogs is not possible
402
@type {Number}
403
*/
404
/* ------------------------------------------------------------------------------------------------------------------------- */
405
406
const DIALOG_DRAG_MARGIN = 40;
407
408
/* ------------------------------------------------------------------------------------------------------------------------- */
409
/**
410
The max width of a dialog
411
@type {Number}
412
*/
413
/* ------------------------------------------------------------------------------------------------------------------------- */
414
415
const DIALOG_MAX_WIDTH = 800;
416
417
/* ------------------------------------------------------------------------------------------------------------------------- */
418
/**
419
The earth radius
420
@type {Number}
421
*/
422
/* ------------------------------------------------------------------------------------------------------------------------- */
423
424
const EARTH_RADIUS = 6371e3;
425
426
/* ------------------------------------------------------------------------------------------------------------------------- */
427
/**
428
A constant used to select the elev in arrays
429
@type {Number}
430
*/
431
/* ------------------------------------------------------------------------------------------------------------------------- */
432
433
const ELEVATION = 2;
434
435
/* ------------------------------------------------------------------------------------------------------------------------- */
436
/**
437
The hexadecimal format
438
@type {Number}
439
*/
440
/* ------------------------------------------------------------------------------------------------------------------------- */
441
442
const HEXADECIMAL = 16;
443
444
/* ------------------------------------------------------------------------------------------------------------------------- */
445
/**
446
The http status 200
447
@type {Number}
448
*/
449
/* ------------------------------------------------------------------------------------------------------------------------- */
450
451
const HTTP_STATUS_OK = 200;
452
453
/* ------------------------------------------------------------------------------------------------------------------------- */
454
/**
455
A constant used for invalid objId
456
@type {Number}
457
*/
458
/* ------------------------------------------------------------------------------------------------------------------------- */
459
460
const INVALID_OBJ_ID = -1;
461
462
/* ------------------------------------------------------------------------------------------------------------------------- */
463
/**
464
A constant used to select the lat in arrays
465
@type {Number}
466
*/
467
/* ------------------------------------------------------------------------------------------------------------------------- */
468
469
const LAT = 0;
470
471
/* ------------------------------------------------------------------------------------------------------------------------- */
472
/**
473
A constant used to select the lng in arrays
474
@type {Number}
475
*/
476
/* ------------------------------------------------------------------------------------------------------------------------- */
477
478
const LNG = 1;
479
480
/* ------------------------------------------------------------------------------------------------------------------------- */
481
/**
482
An array with correction factors to use in the wheel event (wheelEvent.deltaX and wheelEvent.deltaY are dependant of
483
wheelEvent.deltaMode and deltaMode is browser dependant...)
484
@type {Array.<Number>}
485
*/
486
/* ------------------------------------------------------------------------------------------------------------------------- */
487
488
const MOUSE_WHEEL_FACTORS = [ 0.3, 10, 1 ];
489
490
/* ------------------------------------------------------------------------------------------------------------------------- */
491
/**
492
A contant used to move in arrays
493
@type {Number}
494
*/
495
/* ------------------------------------------------------------------------------------------------------------------------- */
496
497
const NEXT = 1;
498
499
/* ------------------------------------------------------------------------------------------------------------------------- */
500
/**
501
Used to compare with some results of Array and String methods
502
@type {Number}
503
*/
504
/* ------------------------------------------------------------------------------------------------------------------------- */
505
506
const NOT_FOUND = -1;
507
508
/* ------------------------------------------------------------------------------------------------------------------------- */
509
/**
510
The number 1
511
@type {Number}
512
*/
513
/* ------------------------------------------------------------------------------------------------------------------------- */
514
515
const ONE = 1;
516
517
/* ------------------------------------------------------------------------------------------------------------------------- */
518
/**
519
The OSM country admin level
520
@type {Number}
521
*/
522
/* ------------------------------------------------------------------------------------------------------------------------- */
523
524
const OSM_COUNTRY_ADMIN_LEVEL = '2';
525
526
/* ------------------------------------------------------------------------------------------------------------------------- */
527
/**
528
A contant used to move in arrays
529
@type {Number}
530
*/
531
/* ------------------------------------------------------------------------------------------------------------------------- */
532
533
const PREVIOUS = -1;
534
535
/* ------------------------------------------------------------------------------------------------------------------------- */
536
/**
537
The svg namespace
538
@type {String}
539
*/
540
/* ------------------------------------------------------------------------------------------------------------------------- */
541
542
const SVG_NS = 'http://www.w3.org/2000/svg';
543
544
/* ------------------------------------------------------------------------------------------------------------------------- */
545
/**
546
The number 3
547
@type {Number}
548
*/
549
/* ------------------------------------------------------------------------------------------------------------------------- */
550
551
const THREE = 3;
552
553
/* ------------------------------------------------------------------------------------------------------------------------- */
554
/**
555
The number 2
556
@type {Number}
557
*/
558
/* ------------------------------------------------------------------------------------------------------------------------- */
559
560
const TWO = 2;
561
562
/* ------------------------------------------------------------------------------------------------------------------------- */
563
/**
564
The icon size for waypoints
565
@type {Number}
566
*/
567
/* ------------------------------------------------------------------------------------------------------------------------- */
568
569
const WAY_POINT_ICON_SIZE = 20;
570
571
/* ------------------------------------------------------------------------------------------------------------------------- */
572
/**
573
The number 0
574
@type {Number}
575
*/
576
/* ------------------------------------------------------------------------------------------------------------------------- */
577
578
const ZERO = 0;
579
580
/* ------------------------------------------------------------------------------------------------------------------------- */
581
582
/* eslint-enable no-magic-numbers */
583
/* eslint-enable max-classes-per-file */
584
585
export {
586
    DEGREES,
587
    DISTANCE,
588
    ELEV,
589
    GEOLOCATION_STATUS,
590
    ICON_DIMENSIONS,
591
    ICON_POSITION,
592
    LAT_LNG,
593
    ROUTE_EDITION_STATUS,
594
    SAVE_STATUS,
595
    TOOLBAR_POSITION,
596
    DIALOG_DRAG_MARGIN,
597
    DIALOG_MAX_WIDTH,
598
    EARTH_RADIUS,
599
    ELEVATION,
600
    HEXADECIMAL,
601
    HTTP_STATUS_OK,
602
    INVALID_OBJ_ID,
603
    LAT,
604
    LNG,
605
    MOUSE_WHEEL_FACTORS,
606
    NEXT,
607
    NOT_FOUND,
608
    ONE,
609
    OSM_COUNTRY_ADMIN_LEVEL,
610
    PREVIOUS,
611
    SVG_NS,
612
    THREE,
613
    TWO,
614
    WAY_POINT_ICON_SIZE,
615
    ZERO
616
};
617
618
/* --- End of file --------------------------------------------------------------------------------------------------------- */
619