* _updateHash * Push changes in map state to the urlhash. * This gets called on 'draw', so fairly frequently
()
| 400 | * This gets called on 'draw', so fairly frequently |
| 401 | */ |
| 402 | _updateHash() { |
| 403 | const context = this.context; |
| 404 | const scene = context.systems.gfx.scene; |
| 405 | const urlhash = context.systems.urlhash; |
| 406 | const viewport = context.viewport; |
| 407 | |
| 408 | // map |
| 409 | const [lon, lat] = viewport.centerLoc(); |
| 410 | const transform = viewport.transform; |
| 411 | const zoom = transform.zoom; |
| 412 | // Why a '-' here? Because "bearing" is the angle that the user points, not the angle that north points. |
| 413 | const ang = numWrap(-transform.r * RAD2DEG, 0, 360); |
| 414 | const precision = Math.max(0, Math.ceil(Math.log(zoom) / Math.LN2)); |
| 415 | const EPSILON = 0.1; |
| 416 | |
| 417 | const zoomStr = zoom.toFixed(2); |
| 418 | const latStr = lat.toFixed(precision); |
| 419 | const lonStr = lon.toFixed(precision); |
| 420 | const angStr = ang.toFixed(1); // degrees |
| 421 | |
| 422 | let val = `${zoomStr}/${latStr}/${lonStr}`; |
| 423 | if (Math.abs(ang) > EPSILON) { |
| 424 | val += `/${angStr}`; |
| 425 | } |
| 426 | |
| 427 | urlhash.setParam('map', val); |
| 428 | |
| 429 | |
| 430 | // note |
| 431 | const layer = scene.layers.get('notes'); |
| 432 | let noteID; |
| 433 | const [pair] = context.selectedData(); // get the first thing in the Map() |
| 434 | const [datumID, datum] = pair || []; |
| 435 | if (datum instanceof QAItem && datum.service === 'osm') { |
| 436 | noteID = datumID; |
| 437 | } |
| 438 | |
| 439 | // `note=true` -or- `note=<noteID>` |
| 440 | if (layer?.enabled) { |
| 441 | if (noteID) { |
| 442 | urlhash.setParam('note', noteID); |
| 443 | } else { |
| 444 | urlhash.setParam('note', 'true'); |
| 445 | } |
| 446 | } else { |
| 447 | urlhash.setParam('note', null); |
| 448 | } |
| 449 | |
| 450 | } |
| 451 | |
| 452 | |
| 453 | /** |
no test coverage detected