File : core/mapEditor/routeEL/RouteMouseOverOrMoveEL.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 theDataSearchEngine from '../../../data/DataSearchEngine.js';
26
import theGeometry from '../../../core/lib/Geometry.js';
27
import theUtilities from '../../../core/uiLib/Utilities.js';
28
import theTravelNotesData from '../../../data/TravelNotesData.js';
29
import { ZERO } from '../../../main/Constants.js';
30
31
/* ------------------------------------------------------------------------------------------------------------------------- */
32
/**
33
mouseover and mousemove event listener for the routes
34
*/
35
/* ------------------------------------------------------------------------------------------------------------------------- */
36
37
class RouteMouseOverOrMoveEL {
38
39
    /**
40
    Event listener method
41
    @param {Event} mapEvent The event to handle
42
    */
43
44
    static handleEvent ( mapEvent ) {
45
        const route = theDataSearchEngine.getRoute ( mapEvent.target.objId );
46
        let distance = theGeometry.getClosestLatLngDistance ( route, [ mapEvent.latlng.lat, mapEvent.latlng.lng ] )
47
            .distance;
48
        distance += route.chainedDistance;
49
        distance = theUtilities.formatDistance ( distance );
50
        const polyline = theTravelNotesData.mapObjects.get ( mapEvent.target.objId );
51
        polyline.closeTooltip ( );
52
        let tooltipText = route.computedName;
53
        if ( ! theTravelNotesData.travel.readOnly ) {
54
            tooltipText += ( ZERO === tooltipText.length ? '' : ' - ' );
55
            tooltipText += distance;
56
        }
57
        polyline.setTooltipContent ( tooltipText );
58
        polyline.openTooltip ( mapEvent.latlng );
59
    }
60
}
61
62
export default RouteMouseOverOrMoveEL;
63
64
/* --- End of file --------------------------------------------------------------------------------------------------------- */
65