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 theEventDispatcher from './lib/EventDispatcher.js'; |
26 | import theDataSearchEngine from '../data/DataSearchEngine.js'; |
27 | import theTravelNotesData from '../data/TravelNotesData.js'; |
28 | import { INVALID_OBJ_ID } from '../main/Constants.js'; |
29 | |
30 | /* ------------------------------------------------------------------------------------------------------------------------- */ |
31 | /** |
32 | This class implements a zoom command on multiple objects |
33 | */ |
34 | /* ------------------------------------------------------------------------------------------------------------------------- */ |
35 | |
36 | class Zoomer { |
37 | |
38 | /** |
39 | An array with the lat and lng of all the objects on witch the zoom have to be performed |
40 | @type {Array.<Array.<Number>>} |
41 | */ |
42 | |
43 | #geometry = []; |
44 | |
45 | /** |
46 | This method push the latitude and longitude of a note in the #geometry array |
47 | @param {Note} note the note to push |
48 | */ |
49 | |
50 | #pushNoteGeometry ( note ) { |
51 | this.#geometry.push ( note.latLng ); |
52 | this.#geometry.push ( note.iconLatLng ); |
53 | } |
54 | |
55 | /** |
56 | This method push the latitude and longitude of a route in the #geometry array |
57 | @param {Route} route the route to push |
58 | */ |
59 | |
60 | #pushRouteGeometry ( route ) { |
61 | route.itinerary.itineraryPoints.forEach ( itineraryPoint => this.#geometry.push ( itineraryPoint.latLng ) ); |
62 | route.notes.forEach ( |
63 | note => this.#pushNoteGeometry ( note ) |
64 | ); |
65 | } |
66 | |
67 | /** |
68 | The constructor |
69 | */ |
70 | |
71 | constructor ( ) { |
72 | Object.freeze ( this ); |
73 | } |
74 | |
75 | /** |
76 | Performs a zoom on a point |
77 | @param {Array.<Number>} latLng The latitude and longitude of the point |
78 | */ |
79 | |
80 | zoomToLatLng ( latLng ) { |
81 | theEventDispatcher.dispatch ( 'zoomto', { latLng : latLng } ); |
82 | } |
83 | |
84 | /** |
85 | Performs a zoom on a note |
86 | @param {Number} noteObjId the objId of the note on witch the zoom must be performed |
87 | */ |
88 | |
89 | zoomToNote ( noteObjId ) { |
90 | this.#geometry = []; |
91 | this.#pushNoteGeometry ( theDataSearchEngine.getNoteAndRoute ( noteObjId ).note ); |
92 | theEventDispatcher.dispatch ( |
93 | 'zoomto', |
94 | { |
95 | geometry : [ this.#geometry ] |
96 | } |
97 | ); |
98 | } |
99 | |
100 | /** |
101 | Performs a zoom on a route |
102 | @param {Number} routeObjId the objId of the route on witch the zoom must be performed |
103 | */ |
104 | |
105 | zoomToRoute ( routeObjId ) { |
106 | this.#geometry = []; |
107 | |
108 | this.#pushRouteGeometry ( theDataSearchEngine.getRoute ( routeObjId ) ); |
109 | |
110 | theEventDispatcher.dispatch ( |
111 | 'zoomto', |
112 | { |
113 | geometry : [ this.#geometry ] |
114 | } |
115 | ); |
116 | } |
117 | |
118 | /** |
119 | Performs a zoom on a complete travel |
120 | */ |
121 | |
122 | zoomToTravel ( ) { |
123 | this.#geometry = []; |
124 | theTravelNotesData.travel.routes.forEach ( |
125 | route => this.#pushRouteGeometry ( route ) |
126 | ); |
127 | if ( INVALID_OBJ_ID !== theTravelNotesData.travel.editedRouteObjId ) { |
128 | this.#pushRouteGeometry ( theTravelNotesData.travel.editedRoute ); |
129 | } |
130 | theTravelNotesData.travel.notes.forEach ( |
131 | note => this.#pushNoteGeometry ( note ) |
132 | ); |
133 | theEventDispatcher.dispatch ( |
134 | 'zoomto', |
135 | { |
136 | geometry : [ this.#geometry ] |
137 | } |
138 | ); |
139 | } |
140 | |
141 | /** |
142 | Performs a zoom on a poi (point of interest = a search result from osm) |
143 | @param {PoiData} poi Poi on witch the zoom must be performed |
144 | */ |
145 | |
146 | zoomToPoi ( poi ) { |
147 | theEventDispatcher.dispatch ( 'zoomto', poi ); |
148 | } |
149 | } |
150 | |
151 | export default Zoomer; |
152 | |
153 | /* --- End of file --------------------------------------------------------------------------------------------------------- */ |
154 |