From f8fff7fe3f1424c6764bce76537ac919b947f390 Mon Sep 17 00:00:00 2001 From: Peter Rushforth Date: Wed, 18 Dec 2024 14:25:45 -0500 Subject: [PATCH] Make map-link._registerMediaQuery async, wait on mapml-viewer to be ready before trying to register a media query (which may depend on mapml-viewer.extent). Remove map-link media attribute from those attributes that are copied onto the 'rendered' element, because the link element actually supports the media attribute, but not the media features we are designing (hence it always forces the element to be disabled). --- src/map-link.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/map-link.js b/src/map-link.js index 1b8352508..3a9cdea7e 100644 --- a/src/map-link.js +++ b/src/map-link.js @@ -305,7 +305,7 @@ export class HTMLLinkElement extends HTMLElement { // this._createLicenseLink(); break; } - this._registerMediaQuery(this.media); + await this._registerMediaQuery(this.media); // create the type of templated leaflet layer appropriate to the rel value // image/map/features = templated(Image/Feature), tile=templatedTile, // this._tempatedTileLayer = Util.templatedTile(pane: this.extentElement._leafletLayer._container) @@ -372,7 +372,7 @@ export class HTMLLinkElement extends HTMLElement { break; } } - _registerMediaQuery(mq) { + async _registerMediaQuery(mq) { if (!this._changeHandler) { // Define and bind the change handler once this._changeHandler = () => { @@ -383,6 +383,7 @@ export class HTMLLinkElement extends HTMLElement { if (mq) { let map = this.getMapEl(); if (!map) return; + await map.whenReady(); // Remove listener from the old media query (if it exists) if (this._mql) { @@ -451,7 +452,7 @@ export class HTMLLinkElement extends HTMLElement { function copyAttributes(source, target) { return Array.from(source.attributes).forEach((attribute) => { - if (attribute.nodeName !== 'href') + if (attribute.nodeName !== 'href' && attribute.nodeName !== 'media') target.setAttribute(attribute.nodeName, attribute.nodeValue); }); }