(mq)
| 24 | } |
| 25 | } |
| 26 | async _registerMediaQuery(mq) { |
| 27 | if (!this._changeHandler) { |
| 28 | // Define and bind the change handler once |
| 29 | this._changeHandler = () => { |
| 30 | this._disconnect(); |
| 31 | if (this._mql.matches) { |
| 32 | this._connect(); |
| 33 | } |
| 34 | }; |
| 35 | } |
| 36 | |
| 37 | if (mq) { |
| 38 | let map = this.getMapEl(); |
| 39 | if (!map) return; |
| 40 | // have to wait until map has an extent i.e. is ready, because the |
| 41 | // matchMedia function below relies on it for map related queries |
| 42 | await map.whenReady(); |
| 43 | |
| 44 | // Remove listener from the old media query (if it exists) |
| 45 | if (this._mql) { |
| 46 | this._mql.removeEventListener('change', this._changeHandler); |
| 47 | } |
| 48 | |
| 49 | // Set up the new media query and listener |
| 50 | this._mql = map.matchMedia(mq); |
| 51 | this._changeHandler(); // Initial evaluation |
| 52 | this._mql.addEventListener('change', this._changeHandler); |
| 53 | } else if (this._mql) { |
| 54 | // Clean up the existing listener |
| 55 | this._mql.removeEventListener('change', this._changeHandler); |
| 56 | delete this._mql; |
| 57 | this._disconnect(); |
| 58 | this._connect(); |
| 59 | } |
| 60 | } |
| 61 | getMapEl() { |
| 62 | return Util.getClosest(this, 'mapml-viewer,map[is=web-map]'); |
| 63 | } |
no test coverage detected