| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 | |
| 19 | |
| 20 | |
| 21 | |
| 22 | |
| 23 | |
| 24 | |
| 25 | import theConfig from '../../data/Config.js'; |
| 26 | import theTravelNotesData from '../../data/TravelNotesData.js'; |
| 27 | import theRouteEditor from '../../core/RouteEditor.js'; |
| 28 | import theApiKeysManager from '../../core/ApiKeysManager.js'; |
| 29 | import Travel from '../../data/Travel.js'; |
| 30 | import ViewerFileLoader from '../../core/ViewerFileLoader.js'; |
| 31 | import { theAppVersion } from '../../data/Version.js'; |
| 32 | import theEventDispatcher from '../../core/lib/EventDispatcher.js'; |
| 33 | import theMapLayersManager from '../../core/MapLayersManager.js'; |
| 34 | import theMapLayersToolbar from '../../toolbars/mapLayersToolbar/MapLayersToolbar.js'; |
| 35 | import theMouseUI from '../../uis/mouseUI/MouseUI.js'; |
| 36 | import theAttributionsUI from '../../uis/attributionsUI/AttributionsUI.js'; |
| 37 | import theTravelNotesToolbar from '../../toolbars/travelNotesToolbar/TravelNotesToolbar.js'; |
| 38 | import theErrorsUI from '../../uis/errorsUI/ErrorsUI.js'; |
| 39 | import theTranslator from '../../core/uiLib/Translator.js'; |
| 40 | import theFullScreenUI from '../../uis/fullScreenUI/FullScreenUI.js'; |
| 41 | import theProvidersToolbar from '../../toolbars/providersToolbar/ProvidersToolbar.js'; |
| 42 | import MapMouseELs from '../../core/mapEditor/mapMouseELs/MapMouseELs.js'; |
| 43 | import { LAT_LNG, TWO, SAVE_STATUS, HTTP_STATUS_OK } from '../Constants.js'; |
| 44 | import theNoteEditor from '../../core/NoteEditor.js'; |
| 45 | |
| 46 | |
| 47 | |
| 48 | |
| 49 | |
| 50 | |
| 51 | |
| 52 | |
| 53 | |
| 54 | class TravelNotes { |
| 55 | |
| 56 | |
| 57 | |
| 58 | |
| 59 | |
| 60 | |
| 61 | #travelNotesLoaded = false; |
| 62 | |
| 63 | |
| 64 | |
| 65 | |
| 66 | |
| 67 | constructor ( ) { |
| 68 | Object.freeze ( this ); |
| 69 | } |
| 70 | |
| 71 | |
| 72 | |
| 73 | |
| 74 | |
| 75 | |
| 76 | |
| 77 | async addReadOnlyTravel ( travelUrl ) { |
| 78 | |
| 79 | if ( this.#travelNotesLoaded ) { |
| 80 | return; |
| 81 | } |
| 82 | |
| 83 | this.#travelNotesLoaded = true; |
| 84 | |
| 85 | theAttributionsUI.createUI ( ); |
| 86 | theMapLayersManager.setMapLayer ( 'OSM - Color' ); |
| 87 | const travelResponse = await fetch ( travelUrl ); |
| 88 | if ( HTTP_STATUS_OK === travelResponse.status && travelResponse.ok ) { |
| 89 | new ViewerFileLoader ( ).openDistantFile ( await travelResponse.json ( ) ); |
| 90 | } |
| 91 | else { |
| 92 | theTravelNotesData.map.setView ( [ LAT_LNG.defaultValue, LAT_LNG.defaultValue ], TWO ); |
| 93 | document.title = 'Travel & Notes'; |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | |
| 98 | |
| 99 | |
| 100 | |
| 101 | |
| 102 | |
| 103 | |
| 104 | addToolbarsMenusUIs ( latUrl, lonUrl ) { |
| 105 | |
| 106 | if ( this.#travelNotesLoaded ) { |
| 107 | return; |
| 108 | } |
| 109 | |
| 110 | this.#travelNotesLoaded = true; |
| 111 | |
| 112 | |
| 113 | document.title = 'Travel & Notes'; |
| 114 | theTravelNotesData.map.on ( 'contextmenu', MapMouseELs.handleContextMenuEvent ); |
| 115 | theTravelNotesData.map.on ( 'click', MapMouseELs.handleClickEvent ); |
| 116 | theTravelNotesData.map.setView ( [ theConfig.map.center.lat, theConfig.map.center.lng ], theConfig.map.zoom ); |
| 117 | |
| 118 | |
| 119 | theAttributionsUI.createUI ( ); |
| 120 | |
| 121 | |
| 122 | theMouseUI.createUI ( ); |
| 123 | theMouseUI.saveStatus = SAVE_STATUS.saved; |
| 124 | |
| 125 | |
| 126 | theErrorsUI.showHelp ( |
| 127 | '<p>' + theTranslator.getText ( 'Help - Continue with interface1' ) + '</p>' + |
| 128 | '<p>' + theTranslator.getText ( 'Help - Continue with interface2' ) + '</p>' |
| 129 | ); |
| 130 | |
| 131 | |
| 132 | theMapLayersToolbar.createUI ( ); |
| 133 | theMapLayersManager.setMapLayer ( 'OSM - Color' ); |
| 134 | |
| 135 | |
| 136 | theTravelNotesToolbar.createUI ( ); |
| 137 | |
| 138 | |
| 139 | theProvidersToolbar.createUI ( ); |
| 140 | |
| 141 | |
| 142 | theApiKeysManager.setKeysFromServerFile ( ); |
| 143 | |
| 144 | |
| 145 | theTravelNotesData.travel.jsonObject = new Travel ( ).jsonObject; |
| 146 | |
| 147 | |
| 148 | if ( theConfig.travelNotes.startupRouteEdition ) { |
| 149 | theRouteEditor.editRoute ( theTravelNotesData.travel.routes.first.objId ); |
| 150 | } |
| 151 | |
| 152 | |
| 153 | theEventDispatcher.dispatch ( 'updatetravelproperties' ); |
| 154 | theEventDispatcher.dispatch ( 'updateroadbook' ); |
| 155 | |
| 156 | |
| 157 | theFullScreenUI.show ( ); |
| 158 | |
| 159 | if ( latUrl && lonUrl ) { |
| 160 | theNoteEditor.newUrlNote ( [ latUrl, lonUrl ] ); |
| 161 | } |
| 162 | } |
| 163 | |
| 164 | |
| 165 | |
| 166 | |
| 167 | |
| 168 | |
| 169 | addProvider ( providerClass ) { |
| 170 | theApiKeysManager.addProvider ( providerClass ); |
| 171 | } |
| 172 | |
| 173 | |
| 174 | |
| 175 | |
| 176 | |
| 177 | |
| 178 | showInfo ( info ) { |
| 179 | theErrorsUI.showInfo ( info ); |
| 180 | } |
| 181 | |
| 182 | |
| 183 | |
| 184 | |
| 185 | |
| 186 | |
| 187 | get overpassApiUrl ( ) { return theConfig.overpassApi.url; } |
| 188 | |
| 189 | |
| 190 | |
| 191 | |
| 192 | |
| 193 | |
| 194 | get map ( ) { return theTravelNotesData.map; } |
| 195 | |
| 196 | |
| 197 | |
| 198 | |
| 199 | |
| 200 | |
| 201 | get version ( ) { return theAppVersion; } |
| 202 | } |
| 203 | |
| 204 | |
| 205 | |
| 206 | |
| 207 | |
| 208 | |
| 209 | |
| 210 | |
| 211 | const theTravelNotes = new TravelNotes ( ); |
| 212 | |
| 213 | export default theTravelNotes; |
| 214 | |
| 215 | |
| 216 | |