MCPcopy Create free account
hub / github.com/Maps4HTML/MapML.js / _registerMediaQuery

Method _registerMediaQuery

src/map-link.js:389–420  ·  view source on GitHub ↗
(mq)

Source from the content-addressed store, hash-verified

387 }
388 }
389 async _registerMediaQuery(mq) {
390 if (!this._changeHandler) {
391 // Define and bind the change handler once
392 this._changeHandler = () => {
393 this.disabled = !this._mql.matches;
394 };
395 }
396
397 if (mq) {
398 let map = this.getMapEl();
399 if (!map) return;
400 // have to wait until map has an extent i.e. is ready, because the
401 // matchMedia function below relies on it for map related queries
402 await map.whenReady();
403
404 // Remove listener from the old media query (if it exists)
405 if (this._mql) {
406 this._mql.removeEventListener('change', this._changeHandler);
407 }
408
409 // Set up the new media query and listener
410 this._mql = map.matchMedia(mq);
411 this._changeHandler(); // Initial evaluation
412 this._mql.addEventListener('change', this._changeHandler);
413 } else if (this._mql) {
414 // Clean up the existing listener
415 this._mql.removeEventListener('change', this._changeHandler);
416 delete this._mql;
417 // unlike map-layer.disabled, map-link.disabled is an observed attribute
418 this.disabled = false;
419 }
420 }
421 _createAlternateLink(mapml) {
422 if (this.href && this.projection) this._alternate = true;
423 }

Callers 2

connectedCallbackMethod · 0.95

Calls 2

getMapElMethod · 0.95
whenReadyMethod · 0.45

Tested by

no test coverage detected