Skip to content

Commit

Permalink
Make map-link._registerMediaQuery async, wait on mapml-viewer to be
Browse files Browse the repository at this point in the history
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' <link> 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).
  • Loading branch information
prushforth committed Dec 18, 2024
1 parent aa85119 commit f8fff7f
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/map-link.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 = () => {
Expand All @@ -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) {
Expand Down Expand Up @@ -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);
});
}
Expand Down

0 comments on commit f8fff7f

Please sign in to comment.