()
| 418 | } |
| 419 | |
| 420 | function postTraversalSetup() { |
| 421 | // when the projection is changed as part of the link traversal process, |
| 422 | // it's necessary to set the map viewer's lat, lon and zoom NOW, so that |
| 423 | // the promises that are created when the viewer's projection is changed |
| 424 | // can use the viewer's lat, lon and zoom properties that were in effect |
| 425 | // before the projection change i.e. in the closure for that code |
| 426 | // see mapml-viewer / map is=web-map projection attributeChangedCallback |
| 427 | // specifically required for use cases like changing projection after |
| 428 | // link traversal, e.g. BC link here https://maps4html.org/experiments/linking/features/ |
| 429 | if (!link.inPlace && zoomTo) updateMapZoomTo(zoomTo); |
| 430 | |
| 431 | // Only _parent target can trigger projection change (replaces all layers) |
| 432 | // For other targets, just wait for layer.whenReady() |
| 433 | const promises = [layer.whenReady()]; |
| 434 | if (link.target === '_parent') { |
| 435 | const projectionChangePromise = new Promise((resolve) => { |
| 436 | const timeout = setTimeout(resolve, 5000); |
| 437 | map.options.mapEl.addEventListener( |
| 438 | 'map-projectionchange', |
| 439 | () => { |
| 440 | clearTimeout(timeout); |
| 441 | resolve(); |
| 442 | }, |
| 443 | { once: true } |
| 444 | ); |
| 445 | }); |
| 446 | promises.push(projectionChangePromise); |
| 447 | } |
| 448 | |
| 449 | Promise.all(promises).then(() => { |
| 450 | if (!link.inPlace && zoomTo) |
| 451 | layer.parentElement.zoomTo(+zoomTo.lat, +zoomTo.lng, +zoomTo.z); |
| 452 | else if (!link.inPlace) layer.zoomTo(); |
| 453 | if (opacity) layer.opacity = opacity; |
| 454 | map.getContainer().focus(); |
| 455 | }); |
| 456 | } |
| 457 | |
| 458 | function updateMapZoomTo(zoomTo) { |
| 459 | // can't use mapEl.zoomTo(...) here, it's too slow! |
no test coverage detected