Maps4HTML / Web-Map-Custom-Element

A custom <mapml-viewer> and <layer-> element suite
https://maps4html.org/Web-Map-Custom-Element/
Other
54 stars 15 forks source link

Handle Switch from local layer- content to remote content (with layer-.src) and vice versa #898

Closed AliyanH closed 5 months ago

AliyanH commented 9 months ago

When switching from local content for layer- to add a src attribute for a layer- we need to remove all the local content properly so that content is not used for the remote layer. Handle the opposite also.

Sample code for layer.js attribute changed callback:

case 'src':
        if (oldValue !== newValue && this._layer) {
          this._onRemove();
          if (this.children) {
            let elements = this.children;
            for (let i = 0; i < elements.length; i++) {
              elements[i].remove();
            }
          }
          if (this.isConnected) {
            this._onAdd();
          }
          // the original inline content will not be removed
          // but has NO EFFECT and works as a fallback
        }