MCPcopy Index your code
hub / github.com/Maps4HTML/MapML.js / _validateDisabled

Method _validateDisabled

src/layer.js:638–734  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

636 }
637
638 _validateDisabled() {
639 const countTileLayers = () => {
640 let totalCount = 0;
641 let disabledCount = 0;
642
643 this._layer.eachLayer((layer) => {
644 if (layer instanceof MapTileLayer) {
645 totalCount++;
646 if (!layer.isVisible()) disabledCount++;
647 }
648 });
649
650 return { totalCount, disabledCount };
651 };
652 const countFeatureLayers = () => {
653 let totalCount = 0;
654 let disabledCount = 0;
655
656 this._layer.eachLayer((layer) => {
657 if (layer instanceof MapFeatureLayer) {
658 totalCount++;
659 if (!layer.isVisible()) disabledCount++;
660 }
661 });
662
663 return { totalCount, disabledCount };
664 };
665 // setTimeout is necessary to make the validateDisabled happen later than the moveend operations etc.,
666 // to ensure that the validated result is correct
667 setTimeout(() => {
668 let layer = this._layer,
669 map = layer?._map;
670 // if there's a media query in play, check it early
671 if (this._mql && !this._mql.matches) {
672 this.setAttribute('disabled', '');
673 this.disabled = true;
674 return;
675 }
676 if (map) {
677 // prerequisite: no inline and remote mapml elements exists at the same time
678 const mapExtents = this.src
679 ? this.shadowRoot.querySelectorAll('map-extent')
680 : this.querySelectorAll('map-extent');
681 let extentLinksReady = [];
682 for (let i = 0; i < mapExtents.length; i++) {
683 extentLinksReady.push(mapExtents[i].whenLinksReady());
684 }
685 Promise.allSettled(extentLinksReady)
686 .then(() => {
687 let disabledExtentCount = 0,
688 totalExtentCount = 0,
689 layerTypes = [
690 '_staticTileLayer',
691 '_mapmlvectors',
692 '_extentLayer'
693 ];
694 for (let j = 0; j < layerTypes.length; j++) {
695 let type = layerTypes[j];

Callers 7

_registerMediaQueryMethod · 0.95
_onAddMethod · 0.95
_addExtentElementMethod · 0.95
_addMetaElementMethod · 0.95
_disableLinkMethod · 0.45
_enableLinkMethod · 0.45

Calls 3

setAttributeMethod · 0.80
whenLinksReadyMethod · 0.80

Tested by

no test coverage detected