File : dialogs/profileDialog/BaseSvgEL.js

1
/*
2
Copyright - 2020 - wwwouaiebe - Contact: http//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 theGeometry from '../../core/lib/Geometry.js';
26
import theDataSearchEngine from '../../data/DataSearchEngine.js';
27
import SvgProfileBuilder from '../../core/lib/SvgProfileBuilder.js';
28
import { ZERO, TWO } from '../../main/Constants.js';
29
30
/* ------------------------------------------------------------------------------------------------------------------------- */
31
/**
32
Base class for Svg event listeners
33
*/
34
/* ------------------------------------------------------------------------------------------------------------------------- */
35
36
class BaseSvgEL {
37
38
    /**
39
    The constructor
40
    */
41
42
    constructor ( ) {
43
        Object.freeze ( this );
44
    }
45
46
    /**
47
    Get the lat, lng, elevation, ascent and distance from the route origin at the mouse position on the svg
48
    @param {Event} mouseEvent The triggered event
49
    @return {LatLngElevOnRoute} An object with the lat, lng, elevation, ascent and distance from the route origin
50
    at the mouse position on the svg
51
    */
52
53
    getlatLngElevOnRouteAtMousePosition ( mouseEvent ) {
54
        const route = theDataSearchEngine.getRoute ( Number.parseInt ( mouseEvent.currentTarget.dataset.tanObjId ) );
55
        const clientRect = mouseEvent.currentTarget.getBoundingClientRect ( );
56
        const routeDist =
57
            (
58
                ( mouseEvent.clientX - clientRect.x -
59
                    (
60
                        ( SvgProfileBuilder.PROFILE_MARGIN /
61
                            ( ( TWO * SvgProfileBuilder.PROFILE_MARGIN ) + SvgProfileBuilder.PROFILE_WIDTH )
62
                        ) * clientRect.width )
63
                ) /
64
                (
65
                    ( SvgProfileBuilder.PROFILE_WIDTH /
66
                        ( ( TWO * SvgProfileBuilder.PROFILE_MARGIN ) + SvgProfileBuilder.PROFILE_WIDTH )
67
                    ) * clientRect.width )
68
            ) * route.distance;
69
        if ( ZERO < routeDist && routeDist < route.distance ) {
70
            return theGeometry.getLatLngElevAtDist ( route, routeDist );
71
        }
72
73
        return null;
74
    }
75
}
76
77
export default BaseSvgEL;
78
79
/* --- End of file --------------------------------------------------------------------------------------------------------- */
80