| 245 | } |
| 246 | } |
| 247 | _initShadowRoot() { |
| 248 | let tmpl = document.createElement('template'); |
| 249 | /* jshint ignore:start */ |
| 250 | tmpl.innerHTML = `<link rel="stylesheet" href="${ |
| 251 | new URL('mapml.css', import.meta.url).href |
| 252 | }">`; |
| 253 | /* jshint ignore:end */ |
| 254 | |
| 255 | const rootDiv = document.createElement('div'); |
| 256 | rootDiv.classList.add('mapml-web-map'); |
| 257 | |
| 258 | let shadowRoot = rootDiv.attachShadow({ mode: 'open' }); |
| 259 | this._container = document.createElement('div'); |
| 260 | |
| 261 | let output = |
| 262 | "<output role='status' aria-live='polite' aria-atomic='true' class='mapml-screen-reader-output'></output>"; |
| 263 | this._container.insertAdjacentHTML('beforeend', output); |
| 264 | |
| 265 | // Set default styles for the map element. |
| 266 | let mapDefaultCSS = document.createElement('style'); |
| 267 | mapDefaultCSS.id = 'web-map-default-style'; |
| 268 | mapDefaultCSS.innerHTML = |
| 269 | `[is="web-map"] {` + |
| 270 | `all: initial;` + // Reset properties inheritable from html/body, as some inherited styles may cause unexpected issues with the map element's components (https://github.com/Maps4HTML/MapML.js/issues/140). |
| 271 | `contain: layout size;` + // Contain layout and size calculations within the map element. |
| 272 | `display: inline-block;` + // This together with dimension properties is required so that Leaflet isn't working with a height=0 box by default. |
| 273 | `height: 150px;` + // Provide a "default object size" (https://github.com/Maps4HTML/HTML-Map-Element/issues/31). |
| 274 | `width: 300px;` + |
| 275 | `border-width: 2px;` + // Set a default border for contrast, similar to UA default for iframes. |
| 276 | `border-style: inset;` + |
| 277 | `box-sizing: inherit;` + // https://github.com/Maps4HTML/MapML.js/issues/350#issuecomment-888361985 |
| 278 | `}` + |
| 279 | `[is="web-map"][frameborder="0"] {` + |
| 280 | `border-width: 0;` + |
| 281 | `}` + |
| 282 | `[is="web-map"][hidden] {` + |
| 283 | `display: none!important;` + |
| 284 | `}` + |
| 285 | `[is="web-map"] .mapml-web-map {` + |
| 286 | `display: contents;` + // This div doesn't have to participate in layout by generating its own box. |
| 287 | `}`; |
| 288 | |
| 289 | let shadowRootCSS = document.createElement('style'); |
| 290 | shadowRootCSS.innerHTML = |
| 291 | `:host .leaflet-control-container {` + |
| 292 | `visibility: hidden!important;` + // Visibility hack to improve percieved performance (mitigate FOUC) – visibility is unset in mapml.css! (https://github.com/Maps4HTML/MapML.js/issues/154). |
| 293 | `}`; |
| 294 | |
| 295 | // Hide all (light DOM) children of the map element except for the |
| 296 | // `<area>` and `<div class="mapml-web-map">` (shadow root host) elements. |
| 297 | let hideElementsCSS = document.createElement('style'); |
| 298 | hideElementsCSS.innerHTML = |
| 299 | `[is="web-map"] > :not(area):not(.mapml-web-map) {` + |
| 300 | `display: none!important;` + |
| 301 | `}`; |
| 302 | this.appendChild(hideElementsCSS); |
| 303 | |
| 304 | shadowRoot.appendChild(shadowRootCSS); |