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 { TOOLBAR_POSITION } from '../../main/Constants.js'; |
26 | import BaseToolbar from '../baseToolbar/BaseToolbar.js'; |
27 | import theTravelNotesData from '../../data/TravelNotesData.js'; |
28 | import ToolbarItem from '../baseToolbar/ToolbarItem.js'; |
29 | import theConfig from '../../data/Config.js'; |
30 | import theMapLayersCollection from '../../data/MapLayersCollection.js'; |
31 | import theApiKeysManager from '../../core/ApiKeysManager.js'; |
32 | import theMapLayersManager from '../../core/MapLayersManager.js'; |
33 | import theTranslator from '../../core/uiLib/Translator.js'; |
34 | |
35 | /* ------------------------------------------------------------------------------------------------------------------------- */ |
36 | /** |
37 | This class is the map layers toolbar |
38 | */ |
39 | /* ------------------------------------------------------------------------------------------------------------------------- */ |
40 | |
41 | class MapLayersToolbar extends BaseToolbar { |
42 | |
43 | /** |
44 | The constructor |
45 | */ |
46 | |
47 | constructor ( ) { |
48 | super ( ); |
49 | } |
50 | |
51 | /** |
52 | Create the UI, adding buttons |
53 | */ |
54 | |
55 | createUI ( ) { |
56 | super.createUI ( theTranslator.getText ( 'MapLayersToolbar - Layers' ), TOOLBAR_POSITION.topLeft ); |
57 | this.addCssClass ( 'TravelNotes-MapLayersToolbar-ToolbarHTMLElement' ); |
58 | } |
59 | |
60 | /** |
61 | Add the ToolbarItems to the toolbar. Called by the #show ( ) method of the base class |
62 | */ |
63 | |
64 | addToolbarItems ( ) { |
65 | |
66 | // adding map layer buttons |
67 | theMapLayersCollection.forEach ( |
68 | mapLayer => { |
69 | if ( |
70 | ( mapLayer.providerKeyNeeded && theApiKeysManager.hasKey ( mapLayer.providerName.toLowerCase ( ) ) ) |
71 | || ! mapLayer.providerKeyNeeded |
72 | ) { |
73 | this.addToolbarItem ( |
74 | new ToolbarItem ( |
75 | mapLayer.toolbarButtonData.text, |
76 | mapLayer.name, |
77 | ( ) => { theMapLayersManager.setMapLayer ( mapLayer.name ); } |
78 | ) |
79 | ); |
80 | } |
81 | } |
82 | ); |
83 | |
84 | if ( theConfig.mapLayersToolbar?.theDevil?.addButton ) { |
85 | this.addToolbarItem ( |
86 | new ToolbarItem ( |
87 | '👿', |
88 | 'Reminder! The devil will know everything about you', |
89 | 'https://www.google.com/maps/@' + |
90 | theTravelNotesData.map.getCenter ( ).lat + |
91 | ',' + |
92 | theTravelNotesData.map.getCenter ( ).lng + |
93 | ',' + |
94 | theTravelNotesData.map.getZoom ( ) + |
95 | 'z' |
96 | ) |
97 | ); |
98 | } |
99 | } |
100 | } |
101 | |
102 | /* ------------------------------------------------------------------------------------------------------------------------- */ |
103 | /** |
104 | The one and only one instance of MapLayersToolbar class |
105 | @type {MapLayersToolbar} |
106 | */ |
107 | /* ------------------------------------------------------------------------------------------------------------------------- */ |
108 | |
109 | const theMapLayersToolbar = new MapLayersToolbar ( ); |
110 | |
111 | export default theMapLayersToolbar; |
112 | |
113 | /* --- End of file --------------------------------------------------------------------------------------------------------- */ |
114 |