File : contextMenus/MapContextMenu.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 BaseContextMenu from './baseContextMenu/BaseContextMenu.js';
26
import MenuItem from './baseContextMenu/MenuItem.js';
27
import theWayPointEditor from '../core/WayPointEditor.js';
28
import theTranslator from '../core/uiLib/Translator.js';
29
import theTravelNotesData from '../data/TravelNotesData.js';
30
import theNoteEditor from '../core/NoteEditor.js';
31
import theRouteEditor from '../core/RouteEditor.js';
32
import Zoomer from '../core/Zoomer.js';
33
34
import { LAT, LNG, LAT_LNG, INVALID_OBJ_ID } from '../main/Constants.js';
35
36
/* ------------------------------------------------------------------------------------------------------------------------- */
37
/**
38
this class implements the BaseContextMenu class for the map
39
*/
40
/* ------------------------------------------------------------------------------------------------------------------------- */
41
42
class MapContextMenu extends BaseContextMenu {
43
44
    /**
45
    The constructor
46
    @param {Event} contextMenuEvent The event that have triggered the menu
47
    @param {HTMLElement} parentNode The parent node of the menu. Can be null for leaflet objects
48
    */
49
50
    constructor ( contextMenuEvent, parentNode ) {
51
        super ( contextMenuEvent, parentNode );
52
    }
53
54
    /**
55
    The list of menu items to use. Implementation of the BaseContextMenu.menuItems property
56
    @type {Array.<MenuItem>}
57
    */
58
59
    get menuItems ( ) {
60
        return [
61
            new MenuItem (
62
                theTranslator.getText ( 'MapContextMenu - Select this point as start point' ),
63
                ( INVALID_OBJ_ID !== theTravelNotesData.editedRouteObjId )
64
                    &&
65
                    ( LAT_LNG.defaultValue === theTravelNotesData.travel.editedRoute.wayPoints.first.lat ),
66
                ( ) => theWayPointEditor.setStartPoint ( this.latLng )
67
            ),
68
            new MenuItem (
69
                theTranslator.getText ( 'MapContextMenu - Select this point as way point' ),
70
                ( INVALID_OBJ_ID !== theTravelNotesData.editedRouteObjId ),
71
                ( ) => theWayPointEditor.addWayPoint ( this.latLng )
72
            ),
73
            new MenuItem (
74
                theTranslator.getText ( 'MapContextMenu - Select this point as end point' ),
75
                ( INVALID_OBJ_ID !== theTravelNotesData.editedRouteObjId )
76
                    &&
77
                    ( LAT_LNG.defaultValue === theTravelNotesData.travel.editedRoute.wayPoints.last.lat ),
78
                ( ) => theWayPointEditor.setEndPoint ( this.latLng )
79
            ),
80
            new MenuItem (
81
                theTranslator.getText ( 'MapContextMenu - Select this point as start and end point' ),
82
                ( INVALID_OBJ_ID !== theTravelNotesData.editedRouteObjId )
83
                    &&
84
                    ( LAT_LNG.defaultValue === theTravelNotesData.travel.editedRoute.wayPoints.first.lat )
85
                    &&
86
                    ( LAT_LNG.defaultValue === theTravelNotesData.travel.editedRoute.wayPoints.last.lat ),
87
                ( ) => theWayPointEditor.setStartAndEndPoint ( this.latLng )
88
            ),
89
            new MenuItem ( theTranslator.getText ( 'MapContextMenu - Add a route' ),
90
                true,
91
                ( ) => theRouteEditor.addRoute ( )
92
            ),
93
            new MenuItem (
94
                theTranslator.getText ( 'MapContextMenu - Hide all routes' ),
95
                true,
96
                ( ) => theRouteEditor.hideRoutes ( )
97
            ),
98
            new MenuItem (
99
                theTranslator.getText ( 'MapContextMenu - Show all routes' ),
100
                true,
101
                ( ) => theRouteEditor.showRoutes ( )
102
            ),
103
            new MenuItem (
104
                theTranslator.getText ( 'MapContextMenu - New travel note' ),
105
                true,
106
                ( ) => theNoteEditor.newTravelNote ( this.latLng )
107
            ),
108
            new MenuItem (
109
                theTranslator.getText ( 'MapContextMenu - Hide all notes' ),
110
                true,
111
                ( ) => theNoteEditor.hideNotes ( )
112
            ),
113
            new MenuItem (
114
                theTranslator.getText ( 'MapContextMenu - Show all notes' ),
115
                true,
116
                ( ) => theNoteEditor.showNotes ( )
117
            ),
118
            new MenuItem (
119
                theTranslator.getText ( 'MapContextMenu - Zoom to travel' ),
120
                true,
121
                ( ) => new Zoomer ( ).zoomToTravel ( )
122
            ),
123
            new MenuItem (
124
                'What the fuck?',
125
                true,
126
                ( ) => {
127
                    const linkElement = document.createElement ( 'a' );
128
                    linkElement.href =
129
                        'https://www.openstreetmap.org/query?lat=' +
130
                        this.latLng [ LAT ].toFixed ( LAT_LNG.fixed ) +
131
                        '&lon=' +
132
                        this.latLng [ LNG ].toFixed ( LAT_LNG.fixed ) +
133
                        '#map=' +
134
                        theTravelNotesData.map.getZoom ( ) +
135
                        '/' +
136
                        this.latLng [ LAT ].toFixed ( LAT_LNG.fixed ) +
137
                        '/' +
138
                        this.latLng [ LNG ].toFixed ( LAT_LNG.fixed );
139
                    linkElement.target = '_blank';
140
                    linkElement.click ( );
141
                }
142
            )
143
        ];
144
    }
145
}
146
147
export default MapContextMenu;
148
149
/* --- End of file --------------------------------------------------------------------------------------------------------- */
150