| 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 theEventDispatcher from '../../core/lib/EventDispatcher.js'; |
| 26 | import theUtilities from '../../core/uiLib/Utilities.js'; |
| 27 | import theDataSearchEngine from '../../data/DataSearchEngine.js'; |
| 28 | import SvgProfileBuilder from '../../core/lib/SvgProfileBuilder.js'; |
| 29 | import BaseSvgEL from './BaseSvgEL.js'; |
| 30 | import { SVG_NS, ZERO, TWO, THREE } from '../../main/Constants.js'; |
| 31 | |
| 32 | |
| 33 | |
| 34 | |
| 35 | |
| 36 | |
| 37 | |
| 38 | class SvgMouseMoveEL extends BaseSvgEL { |
| 39 | |
| 40 | |
| 41 | |
| 42 | |
| 43 | |
| 44 | |
| 45 | #marker; |
| 46 | |
| 47 | |
| 48 | |
| 49 | |
| 50 | |
| 51 | |
| 52 | #distanceText; |
| 53 | |
| 54 | |
| 55 | |
| 56 | |
| 57 | |
| 58 | |
| 59 | #elevText; |
| 60 | |
| 61 | |
| 62 | |
| 63 | |
| 64 | |
| 65 | |
| 66 | #ascentText; |
| 67 | |
| 68 | |
| 69 | |
| 70 | |
| 71 | |
| 72 | |
| 73 | #textAnchor; |
| 74 | |
| 75 | |
| 76 | |
| 77 | |
| 78 | |
| 79 | |
| 80 | #markerX; |
| 81 | |
| 82 | |
| 83 | |
| 84 | |
| 85 | |
| 86 | |
| 87 | #profileSvg; |
| 88 | |
| 89 | |
| 90 | |
| 91 | |
| 92 | |
| 93 | |
| 94 | |
| 95 | |
| 96 | #createSvgText ( text, markerY ) { |
| 97 | const svgText = document.createElementNS ( SVG_NS, 'text' ); |
| 98 | svgText.appendChild ( document.createTextNode ( text ) ); |
| 99 | svgText.setAttributeNS ( null, 'class', 'TravelNotes-Route-SvgProfile-elevText' ); |
| 100 | svgText.setAttributeNS ( null, 'x', this.#markerX ); |
| 101 | svgText.setAttributeNS ( null, 'y', markerY ); |
| 102 | svgText.setAttributeNS ( null, 'text-anchor', this.#textAnchor ); |
| 103 | this.#profileSvg.appendChild ( svgText ); |
| 104 | |
| 105 | return svgText; |
| 106 | } |
| 107 | |
| 108 | |
| 109 | |
| 110 | |
| 111 | |
| 112 | constructor ( ) { |
| 113 | super ( ); |
| 114 | } |
| 115 | |
| 116 | |
| 117 | |
| 118 | |
| 119 | |
| 120 | |
| 121 | handleEvent ( mouseEvent ) { |
| 122 | |
| 123 | mouseEvent.preventDefault ( ); |
| 124 | mouseEvent.stopPropagation ( ); |
| 125 | |
| 126 | this.#profileSvg = mouseEvent.currentTarget; |
| 127 | const latLngElevOnRoute = this.getlatLngElevOnRouteAtMousePosition ( mouseEvent ); |
| 128 | if ( latLngElevOnRoute ) { |
| 129 | |
| 130 | |
| 131 | const markerObjId = Number.parseInt ( this.#profileSvg.dataset.tanMarkerObjId ); |
| 132 | theEventDispatcher.dispatch ( 'removeobject', { objId : markerObjId } ); |
| 133 | theEventDispatcher.dispatch ( |
| 134 | 'additinerarypointmarker', |
| 135 | { |
| 136 | objId : markerObjId, |
| 137 | latLng : latLngElevOnRoute.latLng |
| 138 | } |
| 139 | ); |
| 140 | |
| 141 | |
| 142 | if ( this.#marker && this.#profileSvg.contains ( this.#marker ) ) { |
| 143 | this.#profileSvg.removeChild ( this.#marker ); |
| 144 | this.#profileSvg.removeChild ( this.#distanceText ); |
| 145 | this.#profileSvg.removeChild ( this.#elevText ); |
| 146 | this.#profileSvg.removeChild ( this.#ascentText ); |
| 147 | } |
| 148 | else { |
| 149 | this.#marker = null; |
| 150 | this.#distanceText = null; |
| 151 | this.#elevText = null; |
| 152 | this.#ascentText = null; |
| 153 | } |
| 154 | const clientRect = this.#profileSvg.getBoundingClientRect ( ); |
| 155 | this.#markerX = |
| 156 | ( ( TWO * SvgProfileBuilder.PROFILE_MARGIN ) + SvgProfileBuilder.PROFILE_WIDTH ) * |
| 157 | ( mouseEvent.clientX - clientRect.x ) / clientRect.width; |
| 158 | const markerY = SvgProfileBuilder.PROFILE_MARGIN + SvgProfileBuilder.PROFILE_HEIGHT; |
| 159 | |
| 160 | |
| 161 | this.#marker = document.createElementNS ( SVG_NS, 'polyline' ); |
| 162 | this.#marker.setAttributeNS ( |
| 163 | null, |
| 164 | 'points', |
| 165 | String ( this.#markerX ) + ',' + SvgProfileBuilder.PROFILE_MARGIN + ' ' + this.#markerX + ',' + markerY |
| 166 | ); |
| 167 | this.#marker.setAttributeNS ( null, 'class', 'TravelNotes-Route-SvgProfile-markerPolyline' ); |
| 168 | this.#profileSvg.appendChild ( this.#marker ); |
| 169 | |
| 170 | |
| 171 | const route = theDataSearchEngine.getRoute ( Number.parseInt ( this.#profileSvg.dataset.tanObjId ) ); |
| 172 | this.#textAnchor = latLngElevOnRoute.distance > route.distance / TWO ? 'end' : 'start'; |
| 173 | this.#markerX += |
| 174 | latLngElevOnRoute.distance > route.distance / TWO |
| 175 | ? |
| 176 | -SvgProfileBuilder.X_DELTA_TEXT |
| 177 | : |
| 178 | SvgProfileBuilder.X_DELTA_TEXT; |
| 179 | |
| 180 | |
| 181 | this.#distanceText = this.#createSvgText ( |
| 182 | theUtilities.formatDistance ( latLngElevOnRoute.distance ), |
| 183 | SvgProfileBuilder.PROFILE_MARGIN + SvgProfileBuilder.Y_DELTA_TEXT |
| 184 | ); |
| 185 | |
| 186 | this.#elevText = this.#createSvgText ( |
| 187 | 'Alt. ' + latLngElevOnRoute.elev.toFixed ( ZERO ) + ' m.', |
| 188 | SvgProfileBuilder.PROFILE_MARGIN + ( SvgProfileBuilder.Y_DELTA_TEXT * TWO ) |
| 189 | ); |
| 190 | |
| 191 | this.#ascentText = this.#createSvgText ( |
| 192 | 'Pente ' + latLngElevOnRoute.ascent.toFixed ( ZERO ) + ' % ', |
| 193 | SvgProfileBuilder.PROFILE_MARGIN + ( SvgProfileBuilder.Y_DELTA_TEXT * THREE ) |
| 194 | ); |
| 195 | } |
| 196 | } |
| 197 | } |
| 198 | |
| 199 | export default SvgMouseMoveEL; |
| 200 | |
| 201 | |
| 202 | |