MCPcopy Index your code
hub / github.com/Maps4HTML/MapML.js / postTraversalSetup

Function postTraversalSetup

src/mapml/utils/Util.js:420–456  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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!

Callers 1

Util.jsFile · 0.85

Calls 4

updateMapZoomToFunction · 0.85
focusMethod · 0.80
whenReadyMethod · 0.45
zoomToMethod · 0.45

Tested by

no test coverage detected