| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 | |
| 19 | |
| 20 | |
| 21 | |
| 22 | |
| 23 | import ObjId from '../data/ObjId.js'; |
| 24 | import ObjType from '../data/ObjType.js'; |
| 25 | import { LAT_LNG, DISTANCE, ZERO, ONE, INVALID_OBJ_ID, ICON_DIMENSIONS } from '../main/Constants.js'; |
| 26 | import TravelObject from '../data/TravelObject.js'; |
| 27 | import theHTMLSanitizer from '../core/htmlSanitizer/HTMLSanitizer.js'; |
| 28 | |
| 29 | |
| 30 | |
| 31 | |
| 32 | |
| 33 | |
| 34 | |
| 35 | class Note extends TravelObject { |
| 36 | |
| 37 | |
| 38 | |
| 39 | |
| 40 | |
| 41 | |
| 42 | static #objType = new ObjType ( |
| 43 | 'Note', |
| 44 | [ |
| 45 | 'iconHeight', |
| 46 | 'iconWidth', |
| 47 | 'iconContent', |
| 48 | 'popupContent', |
| 49 | 'tooltipContent', |
| 50 | 'phone', |
| 51 | 'url', |
| 52 | 'address', |
| 53 | 'iconLat', |
| 54 | 'iconLng', |
| 55 | 'lat', |
| 56 | 'lng', |
| 57 | 'distance', |
| 58 | 'chainedDistance', |
| 59 | 'objId' |
| 60 | ] |
| 61 | ); |
| 62 | |
| 63 | |
| 64 | |
| 65 | |
| 66 | |
| 67 | |
| 68 | #iconHeight = ICON_DIMENSIONS.height; |
| 69 | |
| 70 | |
| 71 | |
| 72 | |
| 73 | |
| 74 | |
| 75 | #iconWidth = ICON_DIMENSIONS.width; |
| 76 | |
| 77 | |
| 78 | |
| 79 | |
| 80 | |
| 81 | |
| 82 | #iconContent = ''; |
| 83 | |
| 84 | |
| 85 | |
| 86 | |
| 87 | |
| 88 | |
| 89 | #popupContent = ''; |
| 90 | |
| 91 | |
| 92 | |
| 93 | |
| 94 | |
| 95 | |
| 96 | #tooltipContent = ''; |
| 97 | |
| 98 | |
| 99 | |
| 100 | |
| 101 | |
| 102 | |
| 103 | #phone = ''; |
| 104 | |
| 105 | |
| 106 | |
| 107 | |
| 108 | |
| 109 | |
| 110 | #url = ''; |
| 111 | |
| 112 | |
| 113 | |
| 114 | |
| 115 | |
| 116 | |
| 117 | #address = ''; |
| 118 | |
| 119 | |
| 120 | |
| 121 | |
| 122 | |
| 123 | |
| 124 | #iconLat = LAT_LNG.defaultValue; |
| 125 | |
| 126 | |
| 127 | |
| 128 | |
| 129 | |
| 130 | |
| 131 | #iconLng = LAT_LNG.defaultValue; |
| 132 | |
| 133 | |
| 134 | |
| 135 | |
| 136 | |
| 137 | |
| 138 | #lat = LAT_LNG.defaultValue; |
| 139 | |
| 140 | |
| 141 | |
| 142 | |
| 143 | |
| 144 | |
| 145 | #lng = LAT_LNG.defaultValue; |
| 146 | |
| 147 | |
| 148 | |
| 149 | |
| 150 | |
| 151 | |
| 152 | |
| 153 | #distance = DISTANCE.invalid; |
| 154 | |
| 155 | |
| 156 | |
| 157 | |
| 158 | |
| 159 | |
| 160 | |
| 161 | #chainedDistance = DISTANCE.defaultValue; |
| 162 | |
| 163 | |
| 164 | |
| 165 | |
| 166 | |
| 167 | |
| 168 | #objId = INVALID_OBJ_ID; |
| 169 | |
| 170 | |
| 171 | |
| 172 | |
| 173 | |
| 174 | constructor ( ) { |
| 175 | super ( ); |
| 176 | this.#objId = ObjId.nextObjId; |
| 177 | } |
| 178 | |
| 179 | |
| 180 | |
| 181 | |
| 182 | |
| 183 | |
| 184 | get iconHeight ( ) { return this.#iconHeight; } |
| 185 | |
| 186 | set iconHeight ( iconHeight ) { |
| 187 | this.#iconHeight = 'number' === typeof ( iconHeight ) ? iconHeight : ICON_DIMENSIONS.height; |
| 188 | } |
| 189 | |
| 190 | |
| 191 | |
| 192 | |
| 193 | |
| 194 | |
| 195 | get iconWidth ( ) { return this.#iconWidth; } |
| 196 | |
| 197 | set iconWidth ( iconWidth ) { |
| 198 | this.#iconWidth = 'number' === typeof ( iconWidth ) ? iconWidth : ICON_DIMENSIONS.width; |
| 199 | } |
| 200 | |
| 201 | |
| 202 | |
| 203 | |
| 204 | |
| 205 | |
| 206 | get iconContent ( ) { return this.#iconContent; } |
| 207 | |
| 208 | set iconContent ( iconContent ) { |
| 209 | this.#iconContent = |
| 210 | 'string' === typeof ( iconContent ) |
| 211 | ? |
| 212 | theHTMLSanitizer.sanitizeToHtmlString ( iconContent ).htmlString |
| 213 | : |
| 214 | ''; |
| 215 | } |
| 216 | |
| 217 | |
| 218 | |
| 219 | |
| 220 | |
| 221 | |
| 222 | get popupContent ( ) { return this.#popupContent; } |
| 223 | |
| 224 | set popupContent ( popupContent ) { |
| 225 | this.#popupContent = |
| 226 | 'string' === typeof ( popupContent ) |
| 227 | ? |
| 228 | theHTMLSanitizer.sanitizeToHtmlString ( popupContent ).htmlString |
| 229 | : |
| 230 | ''; |
| 231 | } |
| 232 | |
| 233 | |
| 234 | |
| 235 | |
| 236 | |
| 237 | |
| 238 | get tooltipContent ( ) { return this.#tooltipContent; } |
| 239 | |
| 240 | set tooltipContent ( tooltipContent ) { |
| 241 | this.#tooltipContent = |
| 242 | 'string' === typeof ( tooltipContent ) |
| 243 | ? |
| 244 | theHTMLSanitizer.sanitizeToHtmlString ( tooltipContent ).htmlString |
| 245 | : |
| 246 | ''; |
| 247 | } |
| 248 | |
| 249 | |
| 250 | |
| 251 | |
| 252 | |
| 253 | |
| 254 | get phone ( ) { return this.#phone; } |
| 255 | |
| 256 | set phone ( phone ) { |
| 257 | this.#phone = |
| 258 | 'string' === typeof ( phone ) |
| 259 | ? |
| 260 | theHTMLSanitizer.sanitizeToHtmlString ( phone ).htmlString |
| 261 | : |
| 262 | ''; |
| 263 | } |
| 264 | |
| 265 | |
| 266 | |
| 267 | |
| 268 | |
| 269 | |
| 270 | get url ( ) { return this.#url; } |
| 271 | |
| 272 | set url ( url ) { |
| 273 | this.#url = |
| 274 | 'string' === typeof ( url ) |
| 275 | ? |
| 276 | encodeURI ( theHTMLSanitizer.sanitizeToUrl ( url ).url ) |
| 277 | : |
| 278 | ''; |
| 279 | } |
| 280 | |
| 281 | |
| 282 | |
| 283 | |
| 284 | |
| 285 | |
| 286 | get address ( ) { return this.#address; } |
| 287 | |
| 288 | set address ( address ) { |
| 289 | this.#address = |
| 290 | 'string' === typeof ( address ) |
| 291 | ? |
| 292 | theHTMLSanitizer.sanitizeToHtmlString ( address ).htmlString |
| 293 | : |
| 294 | ''; |
| 295 | } |
| 296 | |
| 297 | |
| 298 | |
| 299 | |
| 300 | |
| 301 | |
| 302 | get iconLat ( ) { return this.#iconLat; } |
| 303 | |
| 304 | set iconLat ( iconLat ) { |
| 305 | this.#iconLat = 'number' === typeof ( iconLat ) ? iconLat : LAT_LNG.defaultValue; |
| 306 | } |
| 307 | |
| 308 | |
| 309 | |
| 310 | |
| 311 | |
| 312 | |
| 313 | get iconLng ( ) { return this.#iconLng; } |
| 314 | |
| 315 | set iconLng ( iconLng ) { |
| 316 | this.#iconLng = 'number' === typeof ( iconLng ) ? iconLng : LAT_LNG.defaultValue; |
| 317 | } |
| 318 | |
| 319 | |
| 320 | |
| 321 | |
| 322 | |
| 323 | |
| 324 | get lat ( ) { return this.#lat; } |
| 325 | |
| 326 | set lat ( lat ) { |
| 327 | this.#lat = 'number' === typeof ( lat ) ? lat : LAT_LNG.defaultValue; |
| 328 | } |
| 329 | |
| 330 | |
| 331 | |
| 332 | |
| 333 | |
| 334 | |
| 335 | get lng ( ) { return this.#lng; } |
| 336 | |
| 337 | set lng ( lng ) { |
| 338 | this.#lng = 'number' === typeof ( lng ) ? lng : LAT_LNG.defaultValue; |
| 339 | } |
| 340 | |
| 341 | |
| 342 | |
| 343 | |
| 344 | |
| 345 | |
| 346 | |
| 347 | get distance ( ) { return this.#distance; } |
| 348 | |
| 349 | set distance ( distance ) { |
| 350 | this.#distance = 'number' === typeof ( distance ) ? distance : DISTANCE.invalid; |
| 351 | } |
| 352 | |
| 353 | |
| 354 | |
| 355 | |
| 356 | |
| 357 | |
| 358 | |
| 359 | get chainedDistance ( ) { return this.#chainedDistance; } |
| 360 | |
| 361 | set chainedDistance ( chainedDistance ) { |
| 362 | this.#chainedDistance = 'number' === typeof ( chainedDistance ) ? chainedDistance : DISTANCE.defaultValue; |
| 363 | } |
| 364 | |
| 365 | |
| 366 | |
| 367 | |
| 368 | |
| 369 | |
| 370 | get isRouteNote ( ) { return this.#distance !== DISTANCE.invalid; } |
| 371 | |
| 372 | |
| 373 | |
| 374 | |
| 375 | |
| 376 | |
| 377 | get iconLatLng ( ) { return [ this.iconLat, this.iconLng ]; } |
| 378 | |
| 379 | set iconLatLng ( iconLatLng ) { |
| 380 | if ( |
| 381 | 'number' === typeof ( iconLatLng [ ZERO ] ) |
| 382 | && |
| 383 | 'number' === typeof ( iconLatLng [ ONE ] ) |
| 384 | ) { |
| 385 | this.#iconLat = iconLatLng [ ZERO ]; |
| 386 | this.#iconLng = iconLatLng [ ONE ]; |
| 387 | } |
| 388 | else { |
| 389 | this.#iconLat = LAT_LNG.defaultValue; |
| 390 | this.#iconLng = LAT_LNG.defaultValue; |
| 391 | } |
| 392 | } |
| 393 | |
| 394 | |
| 395 | |
| 396 | |
| 397 | |
| 398 | |
| 399 | get latLng ( ) { return [ this.lat, this.lng ]; } |
| 400 | |
| 401 | set latLng ( latLng ) { |
| 402 | if ( |
| 403 | 'number' === typeof ( latLng [ ZERO ] ) |
| 404 | && |
| 405 | 'number' === typeof ( latLng [ ONE ] ) |
| 406 | ) { |
| 407 | this.#lat = latLng [ ZERO ]; |
| 408 | this.#lng = latLng [ ONE ]; |
| 409 | } |
| 410 | else { |
| 411 | this.#lat = LAT_LNG.defaultValue; |
| 412 | this.#lng = LAT_LNG.defaultValue; |
| 413 | } |
| 414 | } |
| 415 | |
| 416 | |
| 417 | |
| 418 | |
| 419 | |
| 420 | |
| 421 | get objType ( ) { return Note.#objType; } |
| 422 | |
| 423 | |
| 424 | |
| 425 | |
| 426 | |
| 427 | |
| 428 | get objId ( ) { return this.#objId; } |
| 429 | |
| 430 | |
| 431 | |
| 432 | |
| 433 | |
| 434 | |
| 435 | |
| 436 | get jsonObject ( ) { |
| 437 | return { |
| 438 | iconHeight : this.iconHeight, |
| 439 | iconWidth : this.iconWidth, |
| 440 | iconContent : this.iconContent, |
| 441 | popupContent : this.popupContent, |
| 442 | tooltipContent : this.tooltipContent, |
| 443 | phone : this.phone, |
| 444 | url : this.url, |
| 445 | address : this.address, |
| 446 | iconLat : parseFloat ( this.iconLat.toFixed ( LAT_LNG.fixed ) ), |
| 447 | iconLng : parseFloat ( this.iconLng.toFixed ( LAT_LNG.fixed ) ), |
| 448 | lat : parseFloat ( this.lat.toFixed ( LAT_LNG.fixed ) ), |
| 449 | lng : parseFloat ( this.lng.toFixed ( LAT_LNG.fixed ) ), |
| 450 | distance : parseFloat ( this.distance.toFixed ( DISTANCE.fixed ) ), |
| 451 | chainedDistance : parseFloat ( this.chainedDistance.toFixed ( DISTANCE.fixed ) ), |
| 452 | objId : this.#objId, |
| 453 | objType : this.objType.jsonObject |
| 454 | }; |
| 455 | } |
| 456 | set jsonObject ( something ) { |
| 457 | const otherthing = this.validateObject ( something ); |
| 458 | this.iconHeight = otherthing.iconHeight; |
| 459 | this.iconWidth = otherthing.iconWidth; |
| 460 | this.iconContent = otherthing.iconContent; |
| 461 | this.popupContent = otherthing.popupContent; |
| 462 | this.tooltipContent = otherthing.tooltipContent; |
| 463 | this.phone = otherthing.phone; |
| 464 | this.url = otherthing.url; |
| 465 | this.address = otherthing.address; |
| 466 | this.iconLat = otherthing.iconLat; |
| 467 | this.iconLng = otherthing.iconLng; |
| 468 | this.lat = otherthing.lat; |
| 469 | this.lng = otherthing.lng; |
| 470 | this.distance = otherthing.distance; |
| 471 | this.chainedDistance = otherthing.chainedDistance; |
| 472 | this.#objId = ObjId.nextObjId; |
| 473 | } |
| 474 | } |
| 475 | |
| 476 | export default Note; |
| 477 | |
| 478 | |
| 479 | |