UNPKG

@arcgis/core

Version:

ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API

3 lines (2 loc) • 13.6 kB
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */ import{__decorate as e}from"tslib";import t from"../../Graphic.js";import r from"../../core/Accessor.js";import{createTask as s}from"../../core/asyncUtils.js";import a from"../../core/Collection.js";import{abortMaybe as o}from"../../core/maybe.js";import{ignoreAbortErrors as i,debounce as n}from"../../core/promiseUtils.js";import{watch as l,initial as u}from"../../core/reactiveUtils.js";import{sqlAnd as c}from"../../core/sql.js";import{property as y,subclass as h}from"../../core/accessorSupport/decorators.js";import{UpdatingHandles as d}from"../../core/support/UpdatingHandles.js";import{isLayerFromCatalog as p}from"../../layers/catalog/catalogUtils.js";import{isSubtypeGroupLayer as g,isKnowledgeGraphLayer as _,isMapImageLayer as m,isSubtypeSublayer as f}from"../../layers/support/layerUtils.js";import{isAssociatedFeatureSupportedLayer as b}from"../Feature/support/featureUtils.js";import{createAssociation as C}from"../support/UtilityNetworkAssociations/utils/createAssociation.js";import{getFeatureTitle as F}from"../support/UtilityNetworkAssociations/utils/getFeatureTitle.js";const A=100,q="association-key";let w=class extends r{constructor(e){super(e),this.graphic=null,this.layer=null,this.map=null,this.utilityNetwork=null,this.associationType=null,this.featureCount=0,this.featureSpatialItems=new a,this.highlightHelper=null,this._queryAbortController=null,this._queryPageAbortController=null,this._queryFeatureCountAbortController=null,this.featuresPerPage=30,this.selectedFeature=null,this.association=null,this.filterOptionsVisible=!1,this.filterWhereClause=null,this._rulesTable=null,this._canAssociate=!1,this._whereClause=null,this._setUpItemsTask=null,this._updatingHandlesSetUp=new d,this._queryFeaturesTask=null,this._updatingHandlesQueryFeatures=new d,this._validateAssociationTask=null,this._updatingHandlesAssociation=new d,this._featureIsNotSelected=e=>(this.globalIdField?e.attributes?.[this.globalIdField]??null:null)!==this.globalId,this._cancelQuery=()=>{const{_queryAbortController:e}=this;e&&e.abort(),this._queryAbortController=null},this._cancelQueryFeatureCount=()=>{const{_queryFeatureCountAbortController:e}=this;e&&e.abort(),this._queryFeatureCountAbortController=null},this._cancelQueryPage=()=>{const{_queryPageAbortController:e}=this;e&&e.abort(),this._queryPageAbortController=null},this._queryController=async()=>{this._cancelQuery();const e=new AbortController;this._queryAbortController=e,await i(this._query()).catch(()=>this._cancelQuery()),this._queryAbortController===e&&(this._queryAbortController=null)},this._queryFeatureCountController=async e=>{this._cancelQueryFeatureCount();const t=new AbortController;this._queryFeatureCountAbortController=t,await i(this._queryFeatureCount(e)).catch(()=>this._cancelQueryFeatureCount()),this._queryFeatureCountAbortController===t&&(this._queryFeatureCountAbortController=null)},this._queryPageController=async()=>{const e=new AbortController;this._queryPageAbortController=e,await i(this._queryPage()).catch(()=>this._cancelQueryPage()),this._queryPageAbortController===e&&(this._queryPageAbortController=null)},this._queryDebounced=n(this._queryController,A),this._queryFeatureCountDebounced=n(this._queryFeatureCountController,A),this._queryPageDebounced=n(this._queryPageController,A)}initialize(){this.addHandles([l(()=>[this.graphic,this.layer,this.map,this.utilityNetwork,this.globalId,this.associationType],()=>this._syncLayerItems(),u),l(()=>[this.selectedLayer,this.filterWhereClause,this.featuresPerPage],()=>{this.selectedLayer&&this._setUpFeatures()}),l(()=>this.selectedFeature,()=>{this._setUpAssociation()}),l(()=>this.featurePage,()=>this._queryPageDebounced())])}destroy(){this._setUpItemsTask=o(this._setUpItemsTask),this._updatingHandlesSetUp.destroy(),this._queryFeaturesTask=o(this._queryFeaturesTask),this._updatingHandlesQueryFeatures.destroy(),this._validateAssociationTask=o(this._validateAssociationTask),this._updatingHandlesAssociation.destroy(),this._cancelQuery(),this._cancelQueryFeatureCount(),this._cancelQueryPage()}get mapTables(){const{map:e}=this;if(!e)return null;const t=new Set;return e.allTables.forEach(e=>this._collectIfValidParent(e,t)),new a([...t])}get mapLayers(){const{map:e}=this;if(!e)return null;const t=new Set;return e.allLayers.forEach(e=>this._collectIfValidParent(e,t)),new a([...t])}get state(){const{canLoadLayers:e,_queryAbortController:t,_queryPageAbortController:r}=this;return e?t||r||this._updatingHandlesQueryFeatures.updating?"querying":this._updatingHandlesSetUp.updating?"loading":"ready":"disabled"}get canAddAssociation(){return!(this.updating||!this.association)&&this._canAssociate}get globalId(){return(this.globalIdField&&this.graphic?.attributes?.[this.globalIdField])??null}get globalIdField(){const{layer:e}=this;return e?.globalIdField??null}get layerItems(){return this._get("layerItems")||new a}get tableItems(){return this._get("tableItems")||new a}get featureItems(){return this._get("featureItems")||new a}set featurePage(e){const{featuresPerPage:t,featureCount:r,featureSpatialItems:s}=this,a=s.length||r,o=1,i=Math.ceil(a/t)||1;this._set("featurePage",Math.min(Math.max(e,o),i))}get featurePage(){return this._get("featurePage")}get canLoadLayers(){const{map:e,utilityNetwork:t,graphic:r,associationType:s}=this;return!!(e&&t&&r&&s)}get canQuery(){const{utilityNetwork:e,graphic:t,associationType:r,selectedLayer:s}=this;return!!(e&&t&&r&&s)}get updating(){return this._updatingHandlesSetUp.updating||this._updatingHandlesAssociation.updating}get selectedLayer(){return this._get("selectedLayer")}set selectedLayer(e){e!==this.selectedLayer&&(this.filterWhereClause=null),this._set("selectedLayer",e)}get queryWhereClause(){const{_whereClause:e,filterWhereClause:t}=this;return c(e,t)}async onSelectionComplete(e){const{associationType:t,featureSpatialItems:r,graphic:s,_rulesTable:a}=this,{selection:o}=e;if(r.removeAll(),!(t&&s&&a&&o?.length))return;const i=this._convertTypeToDirection(t.type),n=o.filter(this._featureIsNotSelected),l=a.getFeaturesCanAssociateWith(s,n,i),u=await this._processFeatures(l);r.addMany(u)}reset(){this.highlightHelper?.removeAll(),this.featureSpatialItems.removeAll(),this.featurePage=1}_collectIfValidLayer(e,t){b(e)&&!g(e)&&t.add(e)}_collectIfValidParent(e,t){const r=e=>this._collectIfValidLayer(e,t);p(e)||"catalog-footprint"===e.type||(_(e)?(e.layers?.forEach(r),e.tables?.forEach(r)):m(e)?(e.sublayers?.forEach(r),e.subtables?.forEach(r)):g(e)?e.sublayers?.forEach(r):this._collectIfValidLayer(e,t))}async _queryFeatureCount(e){const{selectedLayer:t,_queryFeatureCountAbortController:r}=this;if(this._set("featureCount",0),!t)return;await t.load();const s=t.createQuery();s.returnGeometry=!1,s.where=c(s.where,e);const a=await t.queryFeatureCount(s,{signal:r?.signal});a>0&&this._set("featureCount",a)}async _query(){const{canQuery:e,queryWhereClause:t,_queryAbortController:r,featureItems:s}=this;e&&(this.featurePage=1,s.destroyAll(),this.featureCount&&!this.destroyed&&s.addMany(await this._queryAssociatedFeatures(t,{signal:r?.signal})))}async _queryPage(){const{canQuery:e,queryWhereClause:t,featurePage:r,_queryPageAbortController:s,featureCount:a,featureItems:o}=this;e&&(r<2||!a||o.addMany(await this._queryAssociatedFeatures(t,{signal:s?.signal})))}_convertTypeToDirection(e){switch(e){case"attachment":return[{type:"attachment",direction:"from"}];case"connectivity":return[{type:"junction-junction-connectivity"},{type:"junction-edge-from-connectivity"},{type:"junction-edge-midspan-connectivity"},{type:"junction-edge-to-connectivity"}];case"container":return[{type:"containment",direction:"to"}];case"content":return[{type:"containment",direction:"from"}];case"structure":return[{type:"attachment",direction:"to"}]}}async getRulesTable(){const{utilityNetwork:e}=this;if(!e)return null;if(this._rulesTable)return this._rulesTable;const t=await e.getRulesTable();return await(t?.load()),this._rulesTable=t,t}async _syncLayerItems(){o(this._setUpItemsTask);const{graphic:e,associationType:t,layerItems:r,tableItems:a,canLoadLayers:i}=this,n=s(async s=>{if(this.selectedLayer=null,r.removeAll(),a.removeAll(),!i)return;const o=this.mapLayers?.toArray(),n=this.mapTables?.toArray();if(!o&&!n)return;if(s.aborted)return;const l=await this.getRulesTable(),u=this._convertTypeToDirection(t.type);if(o?.length){const t=l?.getLayersCanAssociateWith(e,o,u);if(s.aborted)return;r.addMany(t||[])}if(n?.length){const t=l?.getLayersCanAssociateWith(e,n,u);if(s.aborted)return;a.addMany(t||[])}});this._updatingHandlesSetUp.addPromise(n.promise),this._setUpItemsTask=n}async _setUpFeatures(){o(this._queryFeaturesTask);const{graphic:e,associationType:t,selectedLayer:r,canQuery:a}=this;if(!a)return;const i=s(async s=>{const a=await this.getRulesTable(),o=this._convertTypeToDirection(t.type),i=a?.getFeaturesCanAssociateWithClause(e,r,o);this._whereClause=i,s.aborted||(await this._queryFeatureCountDebounced(this.queryWhereClause),await this._queryDebounced())});this._updatingHandlesQueryFeatures.addPromise(i.promise),this._queryFeaturesTask=i}_determineFromAndTo(e,t,r){return"from"===r?{fromFeature:e,toFeature:t}:{fromFeature:t,toFeature:e}}_determineJunctionEdgeConnectivity(e,t){const{utilityNetwork:r}=this,s=f(e.sourceLayer)?e.sourceLayer.parent:e.sourceLayer,a=f(t.sourceLayer)?t.sourceLayer.parent:t.sourceLayer;if(!(r&&s&&"layerId"in s&&a&&"layerId"in a))return{fromFeature:e,toFeature:t,type:"junction-junction-connectivity"};const o=r.getSourceIdByLayerId(s.layerId),i=r.getSourceIdByLayerId(a.layerId);if(!o||!i)return{fromFeature:e,toFeature:t,type:"junction-junction-connectivity"};const n="junction"===r.getSourceTypeById(o),l="junction"===r.getSourceTypeById(i);return n&&l?{fromFeature:e,toFeature:t,type:"junction-junction-connectivity"}:l?{fromFeature:t,toFeature:e,type:"junction-edge-midspan-connectivity"}:{fromFeature:e,toFeature:t,type:"junction-edge-midspan-connectivity"}}_setUpAssociationHandles(){this.removeHandles(q),this.association&&this.addHandles(l(()=>[this.association?.associationType,this.association?.fromNetworkElement,this.association?.fromNetworkElement?.terminalId,this.association?.toNetworkElement,this.association?.toNetworkElement?.terminalId],()=>this.validateAssociation(),u),q)}_setUpAssociation(){const{utilityNetwork:e,graphic:t,selectedFeature:r,associationType:s}=this;if(!(e&&t&&r&&s))return void(this.association=null);const a=this._convertTypeToDirection(s.type);if(a.length>1){const{fromFeature:s,toFeature:a,type:o}=this._determineJunctionEdgeConnectivity(t,r.feature);return this.association=C({fromFeature:s,toFeature:a,utilityNetwork:e,associationType:o}),void this._setUpAssociationHandles()}const{fromFeature:o,toFeature:i}=this._determineFromAndTo(t,r.feature,a[0].direction);this.association=C({fromFeature:o,toFeature:i,utilityNetwork:e,associationType:a[0].type}),this._setUpAssociationHandles()}async _processFeatures(e){return Promise.all(e.map(async e=>{const{sourceLayer:t}=e;if(t&&"getFeatureTitle"in t){return{label:await t.getFeatureTitle(e)||F(e),feature:e}}return{label:F(e),feature:e}}))}async _queryAssociatedFeatures(e,t){const{featuresPerPage:r,layer:s,featurePage:a,featureCount:o,selectedLayer:i}=this,{canQuery:n,globalId:l}=this;if(!n||!s||!i||null==l)return[];const u=((a-1)*r+o)%o,y=r,{historicMoment:h,gdbVersion:d}=i,p=i.createQuery();p.where=c(p.where,e),p.start=u,p.num=y,p.returnGeometry=!1,p.historicMoment=h,p.gdbVersion=d,p.outFields=["*"];const g=await i.queryFeatures(p,{signal:t?.signal});return await this._processFeatures(g.features)}validateAssociation(){o(this._validateAssociationTask);const{utilityNetwork:e,association:t}=this,r=s(async()=>{e&&t&&(this._canAssociate=await e.canAddAssociation(t))});this._updatingHandlesAssociation.addPromise(r.promise),this._validateAssociationTask=r}};e([y({type:t})],w.prototype,"graphic",void 0),e([y()],w.prototype,"layer",void 0),e([y()],w.prototype,"map",void 0),e([y({readOnly:!0})],w.prototype,"mapTables",null),e([y({readOnly:!0})],w.prototype,"mapLayers",null),e([y()],w.prototype,"utilityNetwork",void 0),e([y()],w.prototype,"associationType",void 0),e([y()],w.prototype,"state",null),e([y({readOnly:!0})],w.prototype,"canAddAssociation",null),e([y({readOnly:!0})],w.prototype,"globalId",null),e([y({readOnly:!0})],w.prototype,"globalIdField",null),e([y()],w.prototype,"featureCount",void 0),e([y({readOnly:!0})],w.prototype,"layerItems",null),e([y({readOnly:!0})],w.prototype,"tableItems",null),e([y({readOnly:!0})],w.prototype,"featureItems",null),e([y()],w.prototype,"featureSpatialItems",void 0),e([y()],w.prototype,"highlightHelper",void 0),e([y()],w.prototype,"_queryAbortController",void 0),e([y()],w.prototype,"_queryPageAbortController",void 0),e([y()],w.prototype,"_queryFeatureCountAbortController",void 0),e([y({value:1})],w.prototype,"featurePage",null),e([y()],w.prototype,"featuresPerPage",void 0),e([y({readOnly:!0})],w.prototype,"canLoadLayers",null),e([y({readOnly:!0})],w.prototype,"canQuery",null),e([y({readOnly:!0})],w.prototype,"updating",null),e([y()],w.prototype,"selectedLayer",null),e([y()],w.prototype,"selectedFeature",void 0),e([y()],w.prototype,"association",void 0),e([y()],w.prototype,"filterOptionsVisible",void 0),e([y()],w.prototype,"filterWhereClause",void 0),e([y()],w.prototype,"queryWhereClause",null),e([y()],w.prototype,"_rulesTable",void 0),e([y()],w.prototype,"_canAssociate",void 0),e([y()],w.prototype,"_whereClause",void 0),w=e([h("esri.widgets.FeatureForm.UtilityNetworkAssociationAddAssociationViewModel")],w);export{w as default};