()
| 66 | super(); |
| 67 | } |
| 68 | _connect() { |
| 69 | this.styleElement = document.createElement('style'); |
| 70 | this.styleElement.mapStyle = this; |
| 71 | this.styleElement.textContent = this.textContent; |
| 72 | copyAttributes(this, this.styleElement); |
| 73 | // IMPORTANT: Only render if the correct container exists for THIS element's parent. |
| 74 | // Don't fall back to _extentLayer if this is a layer child - wait for _layer instead. |
| 75 | const isLayerChild = this._stylesheetHost.tagName === 'MAP-LAYER'; |
| 76 | const isExtentChild = this._stylesheetHost.tagName === 'MAP-EXTENT'; |
| 77 | |
| 78 | if (isLayerChild && this._stylesheetHost._layer) { |
| 79 | this._stylesheetHost._layer.renderStyles(this); |
| 80 | } else if (isExtentChild && this._stylesheetHost._extentLayer) { |
| 81 | this._stylesheetHost._extentLayer.renderStyles(this); |
| 82 | } else if (this._stylesheetHost._templatedLayer) { |
| 83 | this._stylesheetHost._templatedLayer.renderStyles(this); |
| 84 | } |
| 85 | |
| 86 | function copyAttributes(source, target) { |
| 87 | return Array.from(source.attributes).forEach((attribute) => { |
| 88 | if ( |
| 89 | attribute.nodeName !== 'media' && |
| 90 | attribute.nodeName !== 'data-testid' |
| 91 | ) { |
| 92 | target.setAttribute(attribute.nodeName, attribute.nodeValue); |
| 93 | } |
| 94 | }); |
| 95 | } |
| 96 | |
| 97 | // use observer to monitor the changes in mapStyle textContent |
| 98 | this._observer = new MutationObserver(() => { |
| 99 | this.styleElement.textContent = this.textContent; |
| 100 | }); |
| 101 | this._observer.observe(this, { |
| 102 | childList: true, |
| 103 | subtree: true, |
| 104 | characterData: true |
| 105 | }); |
| 106 | } |
| 107 | _disconnect() { |
| 108 | if (this._observer) { |
| 109 | this._observer.disconnect(); |
no test coverage detected