File : main/travelNotesViewer/ViewerKeydownEL.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
import theViewerLayersToolbar from '../../toolbars/viewerLayersToolbar/ViewerLayersToolbar.js';
26
import theGeoLocator from '../../core/GeoLocator.js';
27
import Zoomer from '../../core/Zoomer.js';
28
29
import { ZERO } from '../Constants.js';
30
31
/* ------------------------------------------------------------------------------------------------------------------------- */
32
/**
33
keydown event listener, so we can use the keyboard for zoom on the travel, geolocator and maps
34
*/
35
/* ------------------------------------------------------------------------------------------------------------------------- */
36
37
class ViewerKeydownEL {
38
39
    /**
40
    The constructor
41
    */
42
43
    constructor ( ) {
44
        Object.freeze ( this );
45
    }
46
47
    /**
48
    Event listener method
49
    @param {Event} keyBoardEvent The event to handle
50
    */
51
52
    handleEvent ( keyBoardEvent ) {
53
        keyBoardEvent.stopPropagation ( );
54
        if ( 'Z' === keyBoardEvent.key || 'z' === keyBoardEvent.key ) {
55
            new Zoomer ( ).zoomToTravel ( );
56
        }
57
        else if ( 'G' === keyBoardEvent.key || 'g' === keyBoardEvent.key ) {
58
            theGeoLocator.switch ( );
59
        }
60
        else {
61
            const charCode = keyBoardEvent.key.charCodeAt ( ZERO );
62
            // eslint-disable-next-line no-magic-numbers
63
            if ( 47 < charCode && 58 > charCode ) {
64
                theViewerLayersToolbar.setMapLayer ( keyBoardEvent.key );
65
            }
66
        }
67
    }
68
}
69
70
export default ViewerKeydownEL;
71
72
/* --- End of file --------------------------------------------------------------------------------------------------------- */
73