File : contextMenus/OsmSearchContextMenu.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 theNoteEditor from '../core/NoteEditor.js';
28
import Zoomer from '../core/Zoomer.js';
29
import theTranslator from '../core/uiLib/Translator.js';
30
import theWayPointEditor from '../core/WayPointEditor.js';
31
import theTravelNotesData from '../data/TravelNotesData.js';
32
import PoiData from '../containers/PoiData.js';
33
import theEventDispatcher from '../core/lib/EventDispatcher.js';
34
import { LAT_LNG, INVALID_OBJ_ID } from '../main/Constants.js';
35
36
/* ------------------------------------------------------------------------------------------------------------------------- */
37
/**
38
this class implements the BaseContextMenu class for the OsmSearch data
39
*/
40
/* ------------------------------------------------------------------------------------------------------------------------- */
41
42
class OsmSearchContextMenu extends BaseContextMenu {
43
44
    /**
45
    The osmElement for witch the context menu is displayed
46
    @type {OsmElement}
47
    */
48
49
    #osmElement;
50
51
    /**
52
    The lat and lng of the osmElement
53
    @type {Array.<Number>}
54
    */
55
56
    #latLng;
57
58
    /**
59
    The constructor
60
    @param {Event} contextMenuEvent The event that have triggered the menu
61
    @param {HTMLElement} parentNode The parent node of the menu. Can be null for leaflet objects
62
    */
63
64
    constructor ( contextMenuEvent, parentNode ) {
65
        super ( contextMenuEvent, parentNode );
66
        this.#osmElement =
67
            theTravelNotesData.searchData [ Number.parseInt ( contextMenuEvent.currentTarget.dataset.tanElementIndex ) ];
68
        this.#latLng = [ this.#osmElement.lat, this.#osmElement.lon ];
69
        theEventDispatcher.dispatch ( 'removeobject', { objId : this.targetObjId } );
70
    }
71
72
    /**
73
    The list of menu items to use. Implementation of the BaseContextMenu.menuItems property
74
    @type {Array.<MenuItem>}
75
    */
76
77
    get menuItems ( ) {
78
        return [
79
            new MenuItem (
80
                theTranslator.getText ( 'OsmSearchContextMenu - Select this point as start point' ),
81
                ( INVALID_OBJ_ID !== theTravelNotesData.editedRouteObjId )
82
                &&
83
                ( LAT_LNG.defaultValue === theTravelNotesData.travel.editedRoute.wayPoints.first.lat ),
84
                ( ) => theWayPointEditor.setStartPoint ( this.#latLng )
85
            ),
86
            new MenuItem (
87
                theTranslator.getText ( 'OsmSearchContextMenu - Select this point as way point' ),
88
                INVALID_OBJ_ID !== theTravelNotesData.editedRouteObjId,
89
                ( ) => theWayPointEditor.addWayPoint ( this.#latLng )
90
            ),
91
            new MenuItem (
92
                theTranslator.getText ( 'OsmSearchContextMenu - Select this point as end point' ),
93
                ( INVALID_OBJ_ID !== theTravelNotesData.editedRouteObjId )
94
                &&
95
                ( LAT_LNG.defaultValue === theTravelNotesData.travel.editedRoute.wayPoints.last.lat ),
96
                ( ) => theWayPointEditor.setEndPoint ( this.#latLng )
97
            ),
98
            new MenuItem (
99
                theTranslator.getText ( 'OsmSearchContextMenu - Create a route note with this result' ),
100
                true,
101
                ( ) => theNoteEditor.newSearchRouteNote ( this.#osmElement )
102
            ),
103
            new MenuItem (
104
                theTranslator.getText ( 'OsmSearchContextMenu - Create a travel note with this result' ),
105
                true,
106
                ( ) => theNoteEditor.newSearchTravelNote ( this.#osmElement )
107
            ),
108
            new MenuItem (
109
                theTranslator.getText (
110
                    theNoteEditor.osmSearchNoteDialog
111
                        ?
112
                        'OsmSearchContextMenu - Hide note dialog'
113
                        :
114
                        'OsmSearchContextMenu - Show note dialog'
115
                ),
116
                true,
117
                ( ) => theNoteEditor.changeOsmSearchNoteDialog ( )
118
            ),
119
            new MenuItem (
120
                theTranslator.getText ( 'OsmSearchContextMenu - Zoom to this result' ),
121
                true,
122
                ( ) => new Zoomer ( ).zoomToPoi ( new PoiData ( this.#latLng, this.#osmElement.geometry ) )
123
            )
124
        ];
125
    }
126
}
127
128
export default OsmSearchContextMenu;
129
130
/* --- End of file --------------------------------------------------------------------------------------------------------- */
131