@arcgis/core 4.33.0-next.20250608 → 4.33.0-next.20250610

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.33/esri/copyright.txt for details.
4
4
  */
5
- import{_ as t}from"../../../chunks/tslib.es6.js";import e from"../../../Graphic.js";import o from"../../../core/Accessor.js";import s from"../../../core/Clonable.js";import r from"../../../core/Collection.js";import a from"../../../core/Identifiable.js";import{ignoreAbortErrors as i,debounce as n}from"../../../core/promiseUtils.js";import c from"../../../core/ReactiveMap.js";import{watch as l,initial as u}from"../../../core/reactiveUtils.js";import{sqlIn as y}from"../../../core/sql.js";import{property as d}from"../../../core/accessorSupport/decorators/property.js";import"../../../core/has.js";import"../../../core/Logger.js";import"../../../core/RandomLCG.js";import{subclass as h}from"../../../core/accessorSupport/decorators/subclass.js";import{queryAllJSON as p}from"../../../layers/support/featureQueryAll.js";import{isSubtypeSublayer as m,isSubtypeGroupLayer as g}from"../../../layers/support/layerUtils.js";import b from"../../../rest/networks/support/NetworkElement.js";import w from"../../../rest/support/FeatureSet.js";import _ from"../../../rest/support/Query.js";import{featureUtilityNetworkFields as A}from"../../Feature/FeatureUtilityNetworkAssociations/resources.js";import{findUtilityNetwork as f}from"../../Feature/support/featureUtils.js";const C=100;let F=class extends(s.ClonableMixin(a.IdentifiableMixin(o))){constructor(t){super(t),this._loaded=!1,this._queryAbortController=null,this._queryPageAbortController=null,this._queryFeatureCountAbortController=null,this.networkSourceIdsInUse=new Set,this.source="popup",this.description=null,this.graphic=null,this.layer=null,this.map=null,this.featureCount=0,this.associationTypes=null,this.showAllEnabled=!1,this.title=null,this.attachmentsFeatureCount=0,this.structureFeatureCount=0,this.contentFeatureCount=0,this.containerFeatureCount=0,this.connectivityFeatureCount=0,this._queryOpenAssociationType=async()=>{this.activeAssociationType&&await this._queryDebounced(this.activeAssociationType)},this._cancelQuery=()=>{const{_queryAbortController:t}=this;t&&t.abort(),this._queryAbortController=null},this._cancelQueryFeatureCount=()=>{const{_queryFeatureCountAbortController:t}=this;t&&t.abort(),this._queryFeatureCountAbortController=null},this._queryController=async t=>{this._cancelQuery();const e=new AbortController;this._queryAbortController=e,await i(this._query(t)),this._queryAbortController===e&&(this._queryAbortController=null)},this._queryFeatureCountController=async()=>{this._loaded=!1,this._cancelQueryFeatureCount();const t=new AbortController;this._queryFeatureCountAbortController=t,await i(this._queryFeatureCount()),this._queryFeatureCountAbortController===t&&(this._queryFeatureCountAbortController=null),this._loaded=!0},this._queryDebounced=n(this._queryController,C),this._queryFeatureCountDebounced=n(this._queryFeatureCountController,C)}initialize(){this.addHandles([l((()=>[this.graphic,this.layer,this.map,this.associationTypes,this.objectId,this.globalId,this.canQuery]),(()=>this.refresh()),u),l((()=>this.activeAssociationType),(t=>this._queryDebounced(t)),u)])}destroy(){this._cancelQuery(),this._cancelQueryFeatureCount(),this._destroyAssociatedFeatureViewModels()}get supportsCacheHint(){return!!this.layer?.capabilities?.query?.supportsCacheHint}get canLoad(){return!!this.map&&!!this.associationTypes&&"string"==typeof this.globalId}get canQuery(){const t=this.layer?.capabilities?.query;return!!this.associationTypes&&"string"==typeof this.globalId&&!!t?.supportsPagination}set displayCount(t){const e=0,o=3;this._set("displayCount",Math.max(t??o,e))}get displayCount(){return this._get("displayCount")}get objectId(){return(this.objectIdField&&this.graphic?.attributes?.[this.objectIdField])??null}get objectIdField(){return this.layer?.objectIdField||null}get globalId(){return(this.globalIdField&&this.graphic?.attributes?.[this.globalIdField])??null}get globalIdField(){const{layer:t}=this;return t?.globalIdField}get activeAssociationType(){return this._get("activeAssociationType")}set activeAssociationType(t){t&&!this.associationTypes.includes(t)||this._set("activeAssociationType",t)}get state(){const{_queryAbortController:t,_queryFeatureCountAbortController:e,_queryPageAbortController:o,canQuery:s,_loaded:r,canLoad:a,source:i}=this;return e||a&&!r?"loading":t||o?"querying":!s||"popup"===i&&0===this.featureCount?"disabled":"ready"}get utilityNetwork(){const{layer:t,map:e}=this;if(!t?.loaded||!e)return null;const o=m(t)?t.parent:t;return f(e,o)}get attachmentsAssociations(){return this._get("attachmentsAssociations")||new r}get structureAssociations(){return this._get("structureAssociations")||new r}get contentAssociations(){return this._get("contentAssociations")||new r}get containerAssociations(){return this._get("containerAssociations")||new r}get connectivityAssociations(){return this._get("connectivityAssociations")||new r}get associationFeatures(){return this._get("associationFeatures")||new c}get associationViewModels(){return this._get("associationViewModels")||new Map}async refresh(){await this._queryFeatureCountDebounced(),await this._queryOpenAssociationType()}getFeatureCountForAssociationType(t){switch(t){case"attachment":return this.attachmentsFeatureCount;case"structure":return this.structureFeatureCount;case"content":return this.contentFeatureCount;case"container":return this.containerFeatureCount;case"connectivity":return this.connectivityFeatureCount}}_destroyAssociatedFeatureViewModels(){this.associationViewModels.forEach((t=>t.destroyAll()))}async _loadUtiltyNetworks(){const t=this.map;if(!t)return;await Promise.allSettled(t.utilityNetworks?.map((async t=>{await t.load()}))??[]);const e=this.utilityNetwork;if(e){const o=t=>{if("layerId"in t&&e.isUtilityLayer(t)){const o=e.getSourceIdByLayerId(t.layerId);null!==o&&this.networkSourceIdsInUse.add(o)}};this._set("networkSourceIdsInUse",new Set),t.allLayers.forEach(o),t.allTables.forEach(o)}}async _findLayersBySourceId(t){const{utilityNetwork:e,map:o}=this,s=t=>{const o=t;if(!t.url)return!1;if(o.layerId===r){return t.url.replace(/\/\d+$/,"")===e?.featureServiceUrl}return!1};await(e?.load());const r=e.getLayerIdBySourceId(t),a=o.allLayers.filter(s),i=o.allTables.filter(s),n=a.concat(i).toArray();return await Promise.allSettled(n.map((t=>t.load()))),n}_clearAssociations(){this.attachmentsAssociations.removeAll(),this.structureAssociations.removeAll(),this.contentAssociations.removeAll(),this.containerAssociations.removeAll(),this.connectivityAssociations.removeAll()}_clearFeatures(){this.associationFeatures.forEach((t=>t.removeAll())),this.associationFeatures.clear()}_getAssociationsByType(t){switch(t){case"attachment":return this.attachmentsAssociations;case"structure":return this.structureAssociations;case"connectivity":return this.connectivityAssociations;case"container":return this.containerAssociations;case"content":return this.contentAssociations}}async _queryLayer(t,e,o,s,r){const a=this._getFeatureQueryWhereClause(t,e,o,s),i=new _({where:a,outFields:["*"],cacheHint:this.supportsCacheHint}),n=w.fromJSON(await p(t,i,r));return n.features.forEach((e=>{e.layer=e.sourceLayer=g(t)?t.findSublayerForFeature(e):t})),n.features}async _createAssociationFeatureObjects(t,e,o,s,r,a){if(0===t.length)return[];const i=new Map;for(const[c,l]of e){const t=await this._findLayersBySourceId(c);for(const e of t){(await this._queryLayer(e,l,s,r,a)).forEach((t=>{if("popup"===this.source?t.layer&&t.getEffectivePopupTemplate():!!t.layer){const o=i.get(t.attributes[e.globalIdField])??[];o.push(t),i.set(t.attributes[e.globalIdField],o)}}))}}const n=[];return await Promise.all(t.toArray().map((async t=>{const{fromNetworkElement:e,toNetworkElement:s}=t,r=e.globalId===o?s:e,a=i.get(r.globalId)??[];await Promise.all(a.map((async e=>{const o=this.utilityNetwork?.getTerminalById(r?.terminalId)?.name;if(e.layer&&"getFeatureTitle"in e.layer){const s=await e.layer.getFeatureTitle(e);n.push({title:s,association:t,feature:e,terminalName:o})}else n.push({association:t,feature:e,terminalName:o})})))}))),n}_parseFeatureObjects(t,e){t.forEach((t=>{const o=t?.feature,s=o.layer,a=e.get(s)??new r;a.add(t),e.set(s,a)}))}async _queryAssociations(t){const{layer:e,globalId:o,associationTypes:s,utilityNetwork:r,canQuery:a}=this;if(await Promise.allSettled([e?.load(),r?.load()]),this._clearAssociations(),!(a&&e&&s&&r&&o))return;const i=m(e)?e.parent:e,n=new b({globalId:o,networkSourceId:r.getSourceIdByLayerId(i.layerId)}),c=new Set;s.forEach((t=>{switch(t.type){case"attachment":case"structure":c.add("attachment");break;case"container":case"content":c.add("containment");break;case"connectivity":c.add("connectivity"),c.add("junction-junction-connectivity"),c.add("junction-edge-from-connectivity"),c.add("junction-edge-midspan-connectivity"),c.add("junction-edge-to-connectivity")}}));const l=await(r?.queryAssociations({elements:[n],types:Array.from(c)},{signal:t?.signal})),u=new Map,y=new Map;s.forEach((t=>{y.set(t.type,t),u.set(t.type,[])})),l.forEach((t=>{const{toNetworkElement:e,fromNetworkElement:s}=t;switch(t.associationType){case"connectivity":case"junction-junction-connectivity":case"junction-edge-from-connectivity":case"junction-edge-midspan-connectivity":case"junction-edge-to-connectivity":if(s?.globalId===o){if(this._shouldDiscardNetworkElement(e,"connectivity",y))break;u.get("connectivity")?.push(e.globalId)}else{if(this._shouldDiscardNetworkElement(s,"connectivity",y))break;u.get("connectivity")?.push(s.globalId)}this.connectivityAssociations.add(t);break;case"containment":if(s?.globalId===o){if(this._shouldDiscardNetworkElement(e,"content",y))break;u.get("content")?.push(e.globalId),this.contentAssociations.add(t)}else{if(this._shouldDiscardNetworkElement(s,"container",y))break;u.get("container")?.push(s.globalId),this.containerAssociations.add(t)}break;case"attachment":if(s?.globalId===o){if(this._shouldDiscardNetworkElement(e,"attachment",y))break;u.get("attachment")?.push(e.globalId),this.attachmentsAssociations.add(t)}else{if(this._shouldDiscardNetworkElement(s,"structure",y))break;u.get("structure")?.push(s.globalId),this.structureAssociations.add(t)}}}));const d=s.map((async e=>{const{associatedNetworkSourceId:o,associatedAssetGroup:s,associatedAssetType:r}=e,a=u.get(e.type),i=null!=s?await this._countAssociatedFeatures(o,a,s,r,t):a.length;switch(e.type){case"attachment":this._set("attachmentsFeatureCount",i);break;case"structure":this._set("structureFeatureCount",i);break;case"content":this._set("contentFeatureCount",i);break;case"container":this._set("containerFeatureCount",i);break;case"connectivity":this._set("connectivityFeatureCount",i)}}));await Promise.allSettled(d)}async _countAssociatedFeatureCount(t,e,o,s,r){const a=this._getFeatureQueryWhereClause(t,e,o,s);return t.queryFeatureCount({where:a,outFields:["*"],returnGeometry:!1},{signal:r?.signal})}async _countAssociatedFeatures(t,e,o,s,r){if(0===e.length)return 0;const a=(await this._findLayersBySourceId(t)).map((async t=>this._countAssociatedFeatureCount(t,e,o,s,r)));return(await Promise.all(a)).reduce(((t,e)=>t+e),0)}async _queryAssociatedFeatures(t,e){const{layer:o,globalId:s,associationTypes:r,utilityNetwork:a,canQuery:i,associationFeatures:n}=this;if(await Promise.allSettled([o?.load(),a?.load()]),!(i&&o&&r&&a))return;const c=this._getAssociationsByType(t.type),{associatedAssetGroup:l,associatedAssetType:u}=t,y=new Map;c.forEach((t=>{const{fromNetworkElement:e,toNetworkElement:o}=t,{networkSourceId:r,elementGlobalId:a}=e.globalId===s?{networkSourceId:o.networkSourceId,elementGlobalId:o.globalId}:{networkSourceId:e.networkSourceId,elementGlobalId:e.globalId},i=y.get(r)||[];i.push(a),y.set(r,i)}));const d=await this._createAssociationFeatureObjects(c,y,s,l,u,e);this._parseFeatureObjects(d,n)}async _queryFeatureCount(){await this._loadUtiltyNetworks();const{_queryFeatureCountAbortController:t,canQuery:e}=this;e?(await this._queryAssociations(t),this._set("featureCount",this.attachmentsFeatureCount+this.structureFeatureCount+this.contentFeatureCount+this.containerFeatureCount+this.connectivityFeatureCount)):this._set("featureCount",0)}async _query(t){if(!t)return;await this._loadUtiltyNetworks();const{_queryAbortController:e}=this;this._destroyAssociatedFeatureViewModels(),this._clearFeatures(),0!==this.featureCount&&(this.destroyed||await this._queryAssociatedFeatures(t,{signal:e?.signal}))}_shouldDiscardNetworkElement(t,e,o){if(!t)return!1;const{networkSourceIdsInUse:s}=this,{networkSourceId:r}=t,a=o.get(e)?.associatedNetworkSourceId,i=s.has(r);return null!=a&&a!==r||!i}_getFeatureQueryWhereClause(t,e,o,s){const r=t.globalIdField,a=t.fieldsIndex.get(A.assetGroup),i=t.fieldsIndex.get(A.assetType),n=null!=o,c=null!=s;return[r?y(r,e):null,n?`(${a?.name} = ${o})`:null,n&&c?`(${i?.name} = ${s})`:null].filter(Boolean).join(" AND ")}};t([d()],F.prototype,"_loaded",void 0),t([d()],F.prototype,"_queryAbortController",void 0),t([d()],F.prototype,"_queryPageAbortController",void 0),t([d()],F.prototype,"_queryFeatureCountAbortController",void 0),t([d({readOnly:!0})],F.prototype,"supportsCacheHint",null),t([d({readOnly:!0})],F.prototype,"canLoad",null),t([d({readOnly:!0})],F.prototype,"canQuery",null),t([d()],F.prototype,"networkSourceIdsInUse",void 0),t([d({constructOnly:!0})],F.prototype,"source",void 0),t([d()],F.prototype,"description",void 0),t([d({value:3})],F.prototype,"displayCount",null),t([d({type:e})],F.prototype,"graphic",void 0),t([d()],F.prototype,"layer",void 0),t([d()],F.prototype,"map",void 0),t([d({readOnly:!0})],F.prototype,"objectId",null),t([d({readOnly:!0})],F.prototype,"objectIdField",null),t([d({readOnly:!0})],F.prototype,"globalId",null),t([d({readOnly:!0})],F.prototype,"globalIdField",null),t([d()],F.prototype,"featureCount",void 0),t([d()],F.prototype,"associationTypes",void 0),t([d()],F.prototype,"activeAssociationType",null),t([d()],F.prototype,"showAllEnabled",void 0),t([d()],F.prototype,"state",null),t([d()],F.prototype,"title",void 0),t([d({readOnly:!0})],F.prototype,"utilityNetwork",null),t([d({readOnly:!0})],F.prototype,"attachmentsFeatureCount",void 0),t([d({readOnly:!0})],F.prototype,"structureFeatureCount",void 0),t([d({readOnly:!0})],F.prototype,"attachmentsAssociations",null),t([d({readOnly:!0})],F.prototype,"structureAssociations",null),t([d({readOnly:!0})],F.prototype,"contentFeatureCount",void 0),t([d({readOnly:!0})],F.prototype,"containerFeatureCount",void 0),t([d({readOnly:!0})],F.prototype,"contentAssociations",null),t([d({readOnly:!0})],F.prototype,"containerAssociations",null),t([d({readOnly:!0})],F.prototype,"connectivityFeatureCount",void 0),t([d({readOnly:!0})],F.prototype,"connectivityAssociations",null),t([d({readOnly:!0})],F.prototype,"associationFeatures",null),t([d({readOnly:!0})],F.prototype,"associationViewModels",null),F=t([h("esri.widgets.support.UtilityNetworkAssociations.FeatureUtilityNetworkAssociationsViewModel")],F);export{F as default};
5
+ import{_ as t}from"../../../chunks/tslib.es6.js";import e from"../../../Graphic.js";import o from"../../../core/Accessor.js";import s from"../../../core/Clonable.js";import r from"../../../core/Collection.js";import i from"../../../core/Identifiable.js";import{ignoreAbortErrors as a,debounce as n}from"../../../core/promiseUtils.js";import c from"../../../core/ReactiveMap.js";import{watch as l,initial as u}from"../../../core/reactiveUtils.js";import{sqlIn as y}from"../../../core/sql.js";import{property as d}from"../../../core/accessorSupport/decorators/property.js";import"../../../core/has.js";import"../../../core/Logger.js";import"../../../core/RandomLCG.js";import{subclass as h}from"../../../core/accessorSupport/decorators/subclass.js";import{queryAllJSON as p}from"../../../layers/support/featureQueryAll.js";import{isSubtypeSublayer as m,isSubtypeGroupLayer as g}from"../../../layers/support/layerUtils.js";import b from"../../../rest/networks/support/NetworkElement.js";import w from"../../../rest/support/FeatureSet.js";import _ from"../../../rest/support/Query.js";import{featureUtilityNetworkFields as A}from"../../Feature/FeatureUtilityNetworkAssociations/resources.js";import{findUtilityNetwork as C}from"../../Feature/support/featureUtils.js";import{getFeatureTitle as f}from"./utils/getFeatureTitle.js";const F=100;let I=class extends(s.ClonableMixin(i.IdentifiableMixin(o))){constructor(t){super(t),this._loaded=!1,this._queryAbortController=null,this._queryPageAbortController=null,this._queryFeatureCountAbortController=null,this.networkSourceIdsInUse=new Set,this.source="popup",this.description=null,this.graphic=null,this.layer=null,this.map=null,this.featureCount=0,this.associationTypes=null,this.showAllEnabled=!1,this.title=null,this.attachmentsFeatureCount=0,this.structureFeatureCount=0,this.contentFeatureCount=0,this.containerFeatureCount=0,this.connectivityFeatureCount=0,this._queryOpenAssociationType=async()=>{this.activeAssociationType&&await this._queryDebounced(this.activeAssociationType)},this._cancelQuery=()=>{const{_queryAbortController:t}=this;t&&t.abort(),this._queryAbortController=null},this._cancelQueryFeatureCount=()=>{const{_queryFeatureCountAbortController:t}=this;t&&t.abort(),this._queryFeatureCountAbortController=null},this._queryController=async t=>{this._cancelQuery();const e=new AbortController;this._queryAbortController=e,await a(this._query(t)),this._queryAbortController===e&&(this._queryAbortController=null)},this._queryFeatureCountController=async()=>{this._loaded=!1,this._cancelQueryFeatureCount();const t=new AbortController;this._queryFeatureCountAbortController=t,await a(this._queryFeatureCount()),this._queryFeatureCountAbortController===t&&(this._queryFeatureCountAbortController=null),this._loaded=!0},this._queryDebounced=n(this._queryController,F),this._queryFeatureCountDebounced=n(this._queryFeatureCountController,F)}initialize(){this.addHandles([l((()=>[this.graphic,this.layer,this.map,this.associationTypes,this.objectId,this.globalId,this.canQuery]),(()=>this.refresh()),u),l((()=>this.activeAssociationType),(t=>this._queryDebounced(t)),u)])}destroy(){this._cancelQuery(),this._cancelQueryFeatureCount(),this._destroyAssociatedFeatureViewModels()}get supportsCacheHint(){return!!this.layer?.capabilities?.query?.supportsCacheHint}get canLoad(){return!!this.map&&!!this.associationTypes&&"string"==typeof this.globalId}get canQuery(){const t=this.layer?.capabilities?.query;return!!this.associationTypes&&"string"==typeof this.globalId&&!!t?.supportsPagination}set displayCount(t){const e=0,o=3;this._set("displayCount",Math.max(t??o,e))}get displayCount(){return this._get("displayCount")}get objectId(){return(this.objectIdField&&this.graphic?.attributes?.[this.objectIdField])??null}get objectIdField(){return this.layer?.objectIdField||null}get globalId(){return(this.globalIdField&&this.graphic?.attributes?.[this.globalIdField])??null}get globalIdField(){const{layer:t}=this;return t?.globalIdField}get activeAssociationType(){return this._get("activeAssociationType")}set activeAssociationType(t){t&&!this.associationTypes.includes(t)||this._set("activeAssociationType",t)}get state(){const{_queryAbortController:t,_queryFeatureCountAbortController:e,_queryPageAbortController:o,canQuery:s,_loaded:r,canLoad:i,source:a}=this;return e||i&&!r?"loading":t||o?"querying":!s||"popup"===a&&0===this.featureCount?"disabled":"ready"}get utilityNetwork(){const{layer:t,map:e}=this;if(!t?.loaded||!e)return null;const o=m(t)?t.parent:t;return C(e,o)}get attachmentsAssociations(){return this._get("attachmentsAssociations")||new r}get structureAssociations(){return this._get("structureAssociations")||new r}get contentAssociations(){return this._get("contentAssociations")||new r}get containerAssociations(){return this._get("containerAssociations")||new r}get connectivityAssociations(){return this._get("connectivityAssociations")||new r}get associationFeatures(){return this._get("associationFeatures")||new c}get associationViewModels(){return this._get("associationViewModels")||new Map}async refresh(){await this._queryFeatureCountDebounced(),await this._queryOpenAssociationType()}getFeatureCountForAssociationType(t){switch(t){case"attachment":return this.attachmentsFeatureCount;case"structure":return this.structureFeatureCount;case"content":return this.contentFeatureCount;case"container":return this.containerFeatureCount;case"connectivity":return this.connectivityFeatureCount}}_destroyAssociatedFeatureViewModels(){this.associationViewModels.forEach((t=>t.destroyAll()))}async _loadUtiltyNetworks(){const t=this.map;if(!t)return;await Promise.allSettled(t.utilityNetworks?.map((async t=>{await t.load()}))??[]);const e=this.utilityNetwork;if(e){const o=t=>{if("layerId"in t&&e.isUtilityLayer(t)){const o=e.getSourceIdByLayerId(t.layerId);null!==o&&this.networkSourceIdsInUse.add(o)}};this._set("networkSourceIdsInUse",new Set),t.allLayers.forEach(o),t.allTables.forEach(o)}}async _findLayersBySourceId(t){const{utilityNetwork:e,map:o}=this,s=t=>{const o=t;if(!t.url)return!1;if(o.layerId===r){return t.url.replace(/\/\d+$/,"")===e?.featureServiceUrl}return!1};await(e?.load());const r=e.getLayerIdBySourceId(t),i=o.allLayers.filter(s),a=o.allTables.filter(s),n=i.concat(a).toArray();return await Promise.allSettled(n.map((t=>t.load()))),n}_clearAssociations(){this.attachmentsAssociations.removeAll(),this.structureAssociations.removeAll(),this.contentAssociations.removeAll(),this.containerAssociations.removeAll(),this.connectivityAssociations.removeAll()}_clearFeatures(){this.associationFeatures.forEach((t=>t.removeAll())),this.associationFeatures.clear()}_getAssociationsByType(t){switch(t){case"attachment":return this.attachmentsAssociations;case"structure":return this.structureAssociations;case"connectivity":return this.connectivityAssociations;case"container":return this.containerAssociations;case"content":return this.contentAssociations}}async _queryLayer(t,e,o,s,r){const i=this._getFeatureQueryWhereClause(t,e,o,s),a=new _({where:i,outFields:["*"],cacheHint:this.supportsCacheHint}),n=w.fromJSON(await p(t,a,r));return n.features.forEach((e=>{e.layer=e.sourceLayer=g(t)?t.findSublayerForFeature(e):t})),n.features}async _createAssociationFeatureObjects(t,e,o,s,r,i){if(0===t.length)return[];const a=new Map;for(const[c,l]of e){const t=await this._findLayersBySourceId(c);for(const e of t){(await this._queryLayer(e,l,s,r,i)).forEach((t=>{if("popup"===this.source?t.layer&&t.getEffectivePopupTemplate():!!t.layer){const o=a.get(t.attributes[e.globalIdField])??[];o.push(t),a.set(t.attributes[e.globalIdField],o)}}))}}const n=[];return await Promise.all(t.toArray().map((async t=>{const{fromNetworkElement:e,toNetworkElement:s}=t,r=e.globalId===o?s:e,i=a.get(r.globalId)??[];await Promise.all(i.map((async e=>{const o=this.utilityNetwork?.getTerminalById(r?.terminalId)?.name,s=e.sourceLayer&&"getFeatureTitle"in e.sourceLayer?await e.sourceLayer.getFeatureTitle(e):f(e);n.push({title:s,feature:e,association:t,terminalName:o})})))}))),n}_parseFeatureObjects(t,e){t.forEach((t=>{const o=t?.feature,s=o.layer,i=e.get(s)??new r;i.add(t),e.set(s,i)}))}async _queryAssociations(t){const{layer:e,globalId:o,associationTypes:s,utilityNetwork:r,canQuery:i}=this;if(await Promise.allSettled([e?.load(),r?.load()]),this._clearAssociations(),!(i&&e&&s&&r&&o))return;const a=m(e)?e.parent:e,n=new b({globalId:o,networkSourceId:r.getSourceIdByLayerId(a.layerId)}),c=new Set;s.forEach((t=>{switch(t.type){case"attachment":case"structure":c.add("attachment");break;case"container":case"content":c.add("containment");break;case"connectivity":c.add("connectivity"),c.add("junction-junction-connectivity"),c.add("junction-edge-from-connectivity"),c.add("junction-edge-midspan-connectivity"),c.add("junction-edge-to-connectivity")}}));const l=await(r?.queryAssociations({elements:[n],types:Array.from(c)},{signal:t?.signal})),u=new Map,y=new Map;s.forEach((t=>{y.set(t.type,t),u.set(t.type,[])})),l.forEach((t=>{const{toNetworkElement:e,fromNetworkElement:s}=t;switch(t.associationType){case"connectivity":case"junction-junction-connectivity":case"junction-edge-from-connectivity":case"junction-edge-midspan-connectivity":case"junction-edge-to-connectivity":if(s?.globalId===o){if(this._shouldDiscardNetworkElement(e,"connectivity",y))break;u.get("connectivity")?.push(e.globalId)}else{if(this._shouldDiscardNetworkElement(s,"connectivity",y))break;u.get("connectivity")?.push(s.globalId)}this.connectivityAssociations.add(t);break;case"containment":if(s?.globalId===o){if(this._shouldDiscardNetworkElement(e,"content",y))break;u.get("content")?.push(e.globalId),this.contentAssociations.add(t)}else{if(this._shouldDiscardNetworkElement(s,"container",y))break;u.get("container")?.push(s.globalId),this.containerAssociations.add(t)}break;case"attachment":if(s?.globalId===o){if(this._shouldDiscardNetworkElement(e,"attachment",y))break;u.get("attachment")?.push(e.globalId),this.attachmentsAssociations.add(t)}else{if(this._shouldDiscardNetworkElement(s,"structure",y))break;u.get("structure")?.push(s.globalId),this.structureAssociations.add(t)}}}));const d=s.map((async e=>{const{associatedNetworkSourceId:o,associatedAssetGroup:s,associatedAssetType:r}=e,i=u.get(e.type),a=null!=s?await this._countAssociatedFeatures(o,i,s,r,t):i.length;switch(e.type){case"attachment":this._set("attachmentsFeatureCount",a);break;case"structure":this._set("structureFeatureCount",a);break;case"content":this._set("contentFeatureCount",a);break;case"container":this._set("containerFeatureCount",a);break;case"connectivity":this._set("connectivityFeatureCount",a)}}));await Promise.allSettled(d)}async _countAssociatedFeatureCount(t,e,o,s,r){const i=this._getFeatureQueryWhereClause(t,e,o,s);return t.queryFeatureCount({where:i,outFields:["*"],returnGeometry:!1},{signal:r?.signal})}async _countAssociatedFeatures(t,e,o,s,r){if(0===e.length)return 0;const i=(await this._findLayersBySourceId(t)).map((async t=>this._countAssociatedFeatureCount(t,e,o,s,r)));return(await Promise.all(i)).reduce(((t,e)=>t+e),0)}async _queryAssociatedFeatures(t,e){const{layer:o,globalId:s,associationTypes:r,utilityNetwork:i,canQuery:a,associationFeatures:n}=this;if(await Promise.allSettled([o?.load(),i?.load()]),!(a&&o&&r&&i))return;const c=this._getAssociationsByType(t.type),{associatedAssetGroup:l,associatedAssetType:u}=t,y=new Map;c.forEach((t=>{const{fromNetworkElement:e,toNetworkElement:o}=t,{networkSourceId:r,elementGlobalId:i}=e.globalId===s?{networkSourceId:o.networkSourceId,elementGlobalId:o.globalId}:{networkSourceId:e.networkSourceId,elementGlobalId:e.globalId},a=y.get(r)||[];a.push(i),y.set(r,a)}));const d=await this._createAssociationFeatureObjects(c,y,s,l,u,e);this._parseFeatureObjects(d,n)}async _queryFeatureCount(){await this._loadUtiltyNetworks();const{_queryFeatureCountAbortController:t,canQuery:e}=this;e?(await this._queryAssociations(t),this._set("featureCount",this.attachmentsFeatureCount+this.structureFeatureCount+this.contentFeatureCount+this.containerFeatureCount+this.connectivityFeatureCount)):this._set("featureCount",0)}async _query(t){if(!t)return;await this._loadUtiltyNetworks();const{_queryAbortController:e}=this;this._destroyAssociatedFeatureViewModels(),this._clearFeatures(),0!==this.featureCount&&(this.destroyed||await this._queryAssociatedFeatures(t,{signal:e?.signal}))}_shouldDiscardNetworkElement(t,e,o){if(!t)return!1;const{networkSourceIdsInUse:s}=this,{networkSourceId:r}=t,i=o.get(e)?.associatedNetworkSourceId,a=s.has(r);return null!=i&&i!==r||!a}_getFeatureQueryWhereClause(t,e,o,s){const r=t.globalIdField,i=t.fieldsIndex.get(A.assetGroup),a=t.fieldsIndex.get(A.assetType),n=null!=o,c=null!=s;return[r?y(r,e):null,n?`(${i?.name} = ${o})`:null,n&&c?`(${a?.name} = ${s})`:null].filter(Boolean).join(" AND ")}};t([d()],I.prototype,"_loaded",void 0),t([d()],I.prototype,"_queryAbortController",void 0),t([d()],I.prototype,"_queryPageAbortController",void 0),t([d()],I.prototype,"_queryFeatureCountAbortController",void 0),t([d({readOnly:!0})],I.prototype,"supportsCacheHint",null),t([d({readOnly:!0})],I.prototype,"canLoad",null),t([d({readOnly:!0})],I.prototype,"canQuery",null),t([d()],I.prototype,"networkSourceIdsInUse",void 0),t([d({constructOnly:!0})],I.prototype,"source",void 0),t([d()],I.prototype,"description",void 0),t([d({value:3})],I.prototype,"displayCount",null),t([d({type:e})],I.prototype,"graphic",void 0),t([d()],I.prototype,"layer",void 0),t([d()],I.prototype,"map",void 0),t([d({readOnly:!0})],I.prototype,"objectId",null),t([d({readOnly:!0})],I.prototype,"objectIdField",null),t([d({readOnly:!0})],I.prototype,"globalId",null),t([d({readOnly:!0})],I.prototype,"globalIdField",null),t([d()],I.prototype,"featureCount",void 0),t([d()],I.prototype,"associationTypes",void 0),t([d()],I.prototype,"activeAssociationType",null),t([d()],I.prototype,"showAllEnabled",void 0),t([d()],I.prototype,"state",null),t([d()],I.prototype,"title",void 0),t([d({readOnly:!0})],I.prototype,"utilityNetwork",null),t([d({readOnly:!0})],I.prototype,"attachmentsFeatureCount",void 0),t([d({readOnly:!0})],I.prototype,"structureFeatureCount",void 0),t([d({readOnly:!0})],I.prototype,"attachmentsAssociations",null),t([d({readOnly:!0})],I.prototype,"structureAssociations",null),t([d({readOnly:!0})],I.prototype,"contentFeatureCount",void 0),t([d({readOnly:!0})],I.prototype,"containerFeatureCount",void 0),t([d({readOnly:!0})],I.prototype,"contentAssociations",null),t([d({readOnly:!0})],I.prototype,"containerAssociations",null),t([d({readOnly:!0})],I.prototype,"connectivityFeatureCount",void 0),t([d({readOnly:!0})],I.prototype,"connectivityAssociations",null),t([d({readOnly:!0})],I.prototype,"associationFeatures",null),t([d({readOnly:!0})],I.prototype,"associationViewModels",null),I=t([h("esri.widgets.support.UtilityNetworkAssociations.FeatureUtilityNetworkAssociationsViewModel")],I);export{I as default};