@doegis/core
Version:
DOE GIS API
3 lines (1 loc) • 8.01 kB
JavaScript
import{_ as e}from"../../../chunks/tslib.es6.js";import t from"../../../Graphic.js";import r from"../../../core/Accessor.js";import{ClonableMixin as o}from"../../../core/Clonable.js";import l from"../../../core/Collection.js";import{HandleOwnerMixin as s}from"../../../core/HandleOwner.js";import{IdentifiableMixin as a}from"../../../core/Identifiable.js";import{unwrapOrValue as i,isSome as n}from"../../../core/maybe.js";import{ignoreAbortErrors as u}from"../../../core/promiseUtils.js";import{watch as d,initial as y}from"../../../core/reactiveUtils.js";import{throttle as h}from"../../../core/throttle.js";import{property as p}from"../../../core/accessorSupport/decorators/property.js";import"../../../core/accessorSupport/ensureType.js";import"../../../core/arrayUtils.js";import{subclass as c}from"../../../core/accessorSupport/decorators/subclass.js";import C from"../../../rest/support/RelationshipQuery.js";import{getFixedFieldName as _,findRelatedLayer as g}from"../support/featureUtils.js";const b=100;let F=class extends(o(a(s(r)))){constructor(e){super(e),this._queryAbortController=null,this._queryPageAbortController=null,this._queryFeatureCountAbortController=null,this.featuresPerPage=10,this.description=null,this.graphic=null,this.layer=null,this.map=null,this.orderByFields=null,this.featureCount=0,this.relationshipId=null,this.showAllEnabled=!1,this.title=null,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 u(this._query()),this._queryAbortController===e&&(this._queryAbortController=null)},this._queryFeatureCountController=async()=>{this._cancelQueryFeatureCount();const e=new AbortController;this._queryFeatureCountAbortController=e,await u(this._queryFeatureCount()),this._queryFeatureCountAbortController===e&&(this._queryFeatureCountAbortController=null)},this._queryPageController=async()=>{const e=new AbortController;this._queryPageAbortController=e,await u(this._queryPage()),this._queryPageAbortController===e&&(this._queryPageAbortController=null)},this._queryThrottled=h(this._queryController,b,this),this._queryFeatureCountThrottled=h(this._queryFeatureCountController,b,this),this._queryPageThrottled=h(this._queryPageController,b,this),this._query=async()=>{const{_queryAbortController:e,relatedFeatures:t}=this;this._destroyRelatedFeatureViewModels(),this.featurePage=1,t.removeAll(),t.addMany(this._sliceFeatures(await this._queryRelatedFeatures({signal:e?.signal})))},this.handles.add([d((()=>[this.displayCount,this.graphic,this.layer,this.map,this.orderByFieldsFixedCasing,this.relationshipId,this.featuresPerPage,this.showAllEnabled,this.canQuery,this.featureCount]),(()=>this._queryThrottled()),y),d((()=>[this.featurePage,this.showAllEnabled]),(()=>this._queryPageThrottled())),d((()=>[this.layer,this.relationshipId,this.objectId,this.canQuery]),(()=>this._queryFeatureCountThrottled()))])}destroy(){this._destroyRelatedFeatureViewModels(),this.relatedFeatures.removeAll(),this._cancelQuery(),this._cancelQueryFeatureCount(),this._cancelQueryPage()}set featurePage(e){const{featuresPerPage:t,featureCount:r}=this,o=1,l=Math.ceil(r/t)||1;this._set("featurePage",Math.min(Math.max(e,o),l))}get featurePage(){return this._get("featurePage")}get orderByFieldsFixedCasing(){const{orderByFields:e,relatedLayer:t}=this;return e&&t?.loaded?e.map((e=>{const r=e.clone(),o=_(e.field,t);return r.field=o,r})):e??[]}get supportsCacheHint(){return!!this.layer?.capabilities?.queryRelated?.supportsCacheHint}get canQuery(){const e=this.layer?.capabilities?.queryRelated;return!!(this.relatedLayer&&this.relationship&&"number"==typeof this.relationshipId&&"number"==typeof this.objectId&&e?.supportsCount&&e?.supportsPagination)}get itemDescriptionFieldName(){return this.orderByFieldsFixedCasing?.[0]?.field||null}set displayCount(e){const t=0,r=10;this._set("displayCount",Math.min(Math.max(e,t),r))}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 relatedFeatures(){return this._get("relatedFeatures")||new l}get relatedLayer(){const{layer:e,map:t,relationship:r}=this;return e?.loaded&&t&&r?g(t,e,r)??null:null}get relationship(){const{relationshipId:e,layer:t}=this;return"number"==typeof e?t?.relationships?.find((({id:t})=>t===e))??null:null}get relatedFeatureViewModels(){return this._get("relatedFeatureViewModels")||new l}get state(){const{_queryAbortController:e,_queryFeatureCountAbortController:t,_queryPageAbortController:r,canQuery:o}=this;return t?"loading":e||r?"querying":o?"ready":"disabled"}_destroyRelatedFeatureViewModels(){this.relatedFeatureViewModels?.forEach((e=>!e.destroyed&&e.destroy())),this.relatedFeatureViewModels.removeAll()}async _queryFeatureCount(){const{layer:e,relatedLayer:t,relationshipId:r,objectId:o,_queryFeatureCountAbortController:l,canQuery:s,supportsCacheHint:a}=this;if(await(e?.load()),await(t?.load()),!s||!e||!t)return void this._set("featureCount",0);const n=t.createQuery(),u=new C({cacheHint:a,relationshipId:r,returnGeometry:!1,objectIds:[o],where:i(n.where,void 0)}),d=await e.queryRelatedFeaturesCount(u,{signal:l?.signal});this._set("featureCount",d[o]||0)}_sliceFeatures(e){const{showAllEnabled:t,displayCount:r}=this;return t?e:r?e.slice(0,r):[]}async _queryPage(){const{relatedFeatures:e,featurePage:t,showAllEnabled:r,_queryPageAbortController:o}=this;!r||t<2||e.addMany(await this._queryRelatedFeatures({signal:o?.signal}))}async _queryRelatedFeatures(e){const{orderByFieldsFixedCasing:t,showAllEnabled:r,featuresPerPage:o,displayCount:l,layer:s,relationshipId:a,featurePage:u,featureCount:d,relatedLayer:y,supportsCacheHint:h}=this,{canQuery:p,objectId:c}=this;if(!p||!s||!y)return[];const _=r?((u-1)*o+d)%d:0,g=r?o:l,b=y.objectIdField,F=[...t?.map((e=>e.field)),b].filter(n),m=t?.map((e=>`${e.field} ${e.order}`)),f=y.createQuery(),q=new C({orderByFields:m,start:_,num:g,outFields:F,cacheHint:h,relationshipId:a,returnGeometry:!1,objectIds:[c],where:i(f.where,void 0)}),A=(await s.queryRelatedFeatures(q,{signal:e?.signal}))[c]?.features||[];return A.forEach((e=>{e.sourceLayer=y,e.layer=y})),A}};e([p()],F.prototype,"_queryAbortController",void 0),e([p()],F.prototype,"_queryPageAbortController",void 0),e([p()],F.prototype,"_queryFeatureCountAbortController",void 0),e([p({value:1})],F.prototype,"featurePage",null),e([p()],F.prototype,"featuresPerPage",void 0),e([p({readOnly:!0})],F.prototype,"orderByFieldsFixedCasing",null),e([p({readOnly:!0})],F.prototype,"supportsCacheHint",null),e([p({readOnly:!0})],F.prototype,"canQuery",null),e([p()],F.prototype,"description",void 0),e([p({readOnly:!0})],F.prototype,"itemDescriptionFieldName",null),e([p({value:3})],F.prototype,"displayCount",null),e([p({type:t})],F.prototype,"graphic",void 0),e([p()],F.prototype,"layer",void 0),e([p()],F.prototype,"map",void 0),e([p({readOnly:!0})],F.prototype,"objectId",null),e([p({readOnly:!0})],F.prototype,"objectIdField",null),e([p()],F.prototype,"orderByFields",void 0),e([p({readOnly:!0})],F.prototype,"relatedFeatures",null),e([p({readOnly:!0})],F.prototype,"relatedLayer",null),e([p({readOnly:!0})],F.prototype,"relationship",null),e([p()],F.prototype,"featureCount",void 0),e([p({readOnly:!0})],F.prototype,"relatedFeatureViewModels",null),e([p()],F.prototype,"relationshipId",void 0),e([p()],F.prototype,"showAllEnabled",void 0),e([p()],F.prototype,"state",null),e([p()],F.prototype,"title",void 0),F=e([c("esri.widgets.Feature.FeatureRelationship.FeatureRelationshipViewModel")],F);const m=F;export{m as default};