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 | This program is distributed in the hope that it will be useful, |
9 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 | GNU General Public License for more details. |
12 | You should have received a copy of the GNU General Public License |
13 | along with this program; if not, write to the Free Software |
14 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
15 | */ |
16 | /* |
17 | Changes: |
18 | - v4.0.0: |
19 | - created from v3.6.0 |
20 | Doc reviewed 202208 |
21 | */ |
22 | |
23 | import Travel from '../data/Travel.js'; |
24 | import theUtilities from '../core/uiLib/Utilities.js'; |
25 | import TravelNotesDataRouting from './TravelNotesDataRouting.js'; |
26 | import { INVALID_OBJ_ID } from '../main/Constants.js'; |
27 | |
28 | /* ------------------------------------------------------------------------------------------------------------------------- */ |
29 | /** |
30 | Class used to store the data needed by TravelNotes |
31 | See theTravelNotesData for the one and only one instance of this class |
32 | */ |
33 | /* ------------------------------------------------------------------------------------------------------------------------- */ |
34 | |
35 | class TravelNotesData { |
36 | |
37 | /** |
38 | A JS map with the provider objects. Providers objects are created and added by the plugins |
39 | @type {Map.<BaseRouteProvider>} |
40 | */ |
41 | |
42 | #providers; |
43 | |
44 | /** |
45 | A JS map with all the Leaflet objects ordered by objId |
46 | @type {Map.Object} |
47 | */ |
48 | |
49 | #mapObjects; |
50 | |
51 | /** |
52 | An Object with the provider and transit mode used |
53 | @type {TravelNotesDataRouting} |
54 | */ |
55 | |
56 | #routing; |
57 | |
58 | /** |
59 | The UUID currently used |
60 | @type {String} |
61 | */ |
62 | |
63 | #UUID; |
64 | |
65 | /** |
66 | The Leaflet map object |
67 | @type {LeafletObject} |
68 | */ |
69 | |
70 | #map; |
71 | |
72 | /** |
73 | The one and only one object Travel |
74 | @type {Travel} |
75 | */ |
76 | |
77 | #travel; |
78 | |
79 | /** |
80 | The objId of the currently edited route or INVALID_OBJ_ID if none |
81 | @type {Number} |
82 | */ |
83 | |
84 | #editedRouteObjId; |
85 | |
86 | /** |
87 | The POI data found in OpenStreetMap |
88 | @type {Array.<Object>} |
89 | */ |
90 | |
91 | #searchData; |
92 | |
93 | /** |
94 | The constructor |
95 | */ |
96 | |
97 | constructor ( ) { |
98 | Object.freeze ( this ); |
99 | this.#providers = new Map ( ); |
100 | this.#mapObjects = new Map ( ); |
101 | this.#routing = new TravelNotesDataRouting ( ); |
102 | this.#UUID = theUtilities.UUID; |
103 | this.#map = null; |
104 | this.#travel = new Travel ( ); |
105 | this.#editedRouteObjId = INVALID_OBJ_ID; |
106 | this.#searchData = []; |
107 | } |
108 | |
109 | /** |
110 | The Leaflet map object |
111 | @type {LeafletObject} |
112 | */ |
113 | |
114 | get map ( ) { return this.#map; } |
115 | |
116 | set map ( map ) { |
117 | if ( ! this.#map ) { |
118 | this.#map = map; |
119 | } |
120 | } |
121 | |
122 | /** |
123 | The one and only one object Travel |
124 | @type {Travel} |
125 | */ |
126 | |
127 | get travel ( ) { return this.#travel; } |
128 | |
129 | /** |
130 | The objId of the currently edited route or INVALID_OBJ_ID if none |
131 | @type {Number} |
132 | */ |
133 | |
134 | get editedRouteObjId ( ) { return this.#editedRouteObjId; } |
135 | |
136 | set editedRouteObjId ( editedRouteObjId ) { |
137 | this.#editedRouteObjId = 'number' === typeof ( editedRouteObjId ) ? editedRouteObjId : INVALID_OBJ_ID; |
138 | } |
139 | |
140 | /** |
141 | The POI data found in OpenStreetMap |
142 | @type {Array.<Object>} |
143 | */ |
144 | |
145 | get searchData ( ) { return this.#searchData; } |
146 | |
147 | /** |
148 | A JS map with the provider objects. Providers objects are created and added by the plugins |
149 | @type {Map.<BaseRouteProvider>} |
150 | */ |
151 | |
152 | get providers ( ) { return this.#providers; } |
153 | |
154 | /** |
155 | A JS map with all the Leaflet objects ordered by objId |
156 | @type {Map.Object} |
157 | */ |
158 | |
159 | get mapObjects ( ) { return this.#mapObjects; } |
160 | |
161 | /** |
162 | An Object with the provider and transit mode used |
163 | @type {TravelNotesDataRouting} |
164 | */ |
165 | |
166 | get routing ( ) { return this.#routing; } |
167 | |
168 | /** |
169 | The UUID currently used |
170 | @type {String} |
171 | */ |
172 | |
173 | get UUID ( ) { return this.#UUID; } |
174 | } |
175 | |
176 | /* ------------------------------------------------------------------------------------------------------------------------- */ |
177 | /** |
178 | The one and only one instance of TravelNoteData class |
179 | @type {TravelNotesData} |
180 | */ |
181 | /* ------------------------------------------------------------------------------------------------------------------------- */ |
182 | |
183 | const theTravelNotesData = new TravelNotesData ( ); |
184 | |
185 | export default theTravelNotesData; |
186 | |
187 | /* --- End of file --------------------------------------------------------------------------------------------------------- */ |
188 |