1 |
- import{gA as oe,t as S,ea as ne,c7 as ie,c0 as ue,b2 as L,dy as R,cV as k,gf as le,hM as de,hN as ce,hO as he,hP as M,U as p,hQ as ye,ge as pe,cA as Q,hR as C,cL as V,hS as fe,a as c,bP as H,dP as me,eI as J,as as ge,hT as P,_ as y,$ as g,a0 as U,a1 as Fe,hU as K,h as G,hV as _e,eb as be,al as Re,g as O,cl as W,hW as Oe,d4 as Se,hX as Ie,k as qe,dL as we,gd as xe,hY as je,aL as Ee,cJ as Te,c1 as De,cn as Z}from"./index.6c049565.js";import{o as Ae}from"./clientSideDefaults.e21714f1.js";import{n as Ce,s as Pe}from"./executeForIds.4e97b9d4.js";import"./QueryEngineCapabilities.78217f95.js";var $;(function(t){t[t.PROJECT_VERTICES=1]="PROJECT_VERTICES"})($||($={}));function ve(t,e){return e}function B(t,e,s,r){switch(s){case 0:return j(t,e+r,0);case 1:return t.originPosition==="lowerLeft"?j(t,e+r,1):Ge(t,e+r,1)}}function ee(t,e,s,r){return s===2?j(t,e,2):B(t,e,s,r)}function Ne(t,e,s,r){return s===2?j(t,e,3):B(t,e,s,r)}function Je(t,e,s,r){return s===3?j(t,e,3):ee(t,e,s,r)}function j({translate:t,scale:e},s,r){return t[r]+s*e[r]}function Ge({translate:t,scale:e},s,r){return t[r]-s*e[r]}class $e{constructor(e){this._options=e,this.geometryTypes=["esriGeometryPoint","esriGeometryMultipoint","esriGeometryPolyline","esriGeometryPolygon"],this._previousCoordinate=[0,0],this._transform=null,this._applyTransform=ve,this._lengths=[],this._currentLengthIndex=0,this._toAddInCurrentPath=0,this._vertexDimension=0,this._coordinateBuffer=null,this._coordinateBufferPtr=0,this._attributesConstructor=class{}}createFeatureResult(){return{fields:[],features:[]}}finishFeatureResult(e){if(this._options.applyTransform&&(e.transform=null),this._attributesConstructor=class{},this._coordinateBuffer=null,this._lengths.length=0,!e.hasZ)return;const s=oe(e.geometryType,this._options.sourceSpatialReference,e.spatialReference);if(!S(s))for(const r of e.features)s(r.geometry)}createSpatialReference(){return{}}addField(e,s){const r=e.fields;ne(r),r.push(s);const a=r.map(o=>o.name);this._attributesConstructor=function(){for(const o of a)this[o]=null}}addFeature(e,s){e.features.push(s)}prepareFeatures(e){switch(this._transform=e.transform,this._options.applyTransform&&e.transform&&(this._applyTransform=this._deriveApplyTransform(e)),this._vertexDimension=2,e.hasZ&&this._vertexDimension++,e.hasM&&this._vertexDimension++,e.geometryType){case"esriGeometryPoint":this.addCoordinate=(s,r,a)=>this.addCoordinatePoint(s,r,a),this.createGeometry=s=>this.createPointGeometry(s);break;case"esriGeometryPolygon":this.addCoordinate=(s,r,a)=>this._addCoordinatePolygon(s,r,a),this.createGeometry=s=>this._createPolygonGeometry(s);break;case"esriGeometryPolyline":this.addCoordinate=(s,r,a)=>this._addCoordinatePolyline(s,r,a),this.createGeometry=s=>this._createPolylineGeometry(s);break;case"esriGeometryMultipoint":this.addCoordinate=(s,r,a)=>this._addCoordinateMultipoint(s,r,a),this.createGeometry=s=>this._createMultipointGeometry(s)}}createFeature(){return this._lengths.length=0,this._currentLengthIndex=0,this._previousCoordinate[0]=0,this._previousCoordinate[1]=0,this._coordinateBuffer=null,this._coordinateBufferPtr=0,{attributes:new this._attributesConstructor}}allocateCoordinates(){}addLength(e,s,r){this._lengths.length===0&&(this._toAddInCurrentPath=s),this._lengths.push(s)}addQueryGeometry(e,s){const{queryGeometry:r,queryGeometryType:a}=s,o=ie(r.clone(),r,!1,!1,this._transform),n=ue(o,a,!1,!1);e.queryGeometryType=a,e.queryGeometry={...n}}createPointGeometry(e){const s={x:0,y:0,spatialReference:e.spatialReference};return e.hasZ&&(s.z=0),e.hasM&&(s.m=0),s}addCoordinatePoint(e,s,r){const a=L(this._transform,"transform");switch(s=this._applyTransform(a,s,r,0),r){case 0:e.x=s;break;case 1:e.y=s;break;case 2:"z"in e?e.z=s:e.m=s;break;case 3:e.m=s}}_transformPathLikeValue(e,s){let r=0;s<=1&&(r=this._previousCoordinate[s],this._previousCoordinate[s]+=e);const a=L(this._transform,"transform");return this._applyTransform(a,e,s,r)}_addCoordinatePolyline(e,s,r){this._dehydratedAddPointsCoordinate(e.paths,s,r)}_addCoordinatePolygon(e,s,r){this._dehydratedAddPointsCoordinate(e.rings,s,r)}_addCoordinateMultipoint(e,s,r){r===0&&e.points.push([]);const a=this._transformPathLikeValue(s,r);e.points[e.points.length-1].push(a)}_createPolygonGeometry(e){return{rings:[[]],spatialReference:e.spatialReference,hasZ:!!e.hasZ,hasM:!!e.hasM}}_createPolylineGeometry(e){return{paths:[[]],spatialReference:e.spatialReference,hasZ:!!e.hasZ,hasM:!!e.hasM}}_createMultipointGeometry(e){return{points:[],spatialReference:e.spatialReference,hasZ:!!e.hasZ,hasM:!!e.hasM}}_dehydratedAddPointsCoordinate(e,s,r){r===0&&this._toAddInCurrentPath--==0&&(e.push([]),this._toAddInCurrentPath=this._lengths[++this._currentLengthIndex]-1,this._previousCoordinate[0]=0,this._previousCoordinate[1]=0);const a=this._transformPathLikeValue(s,r),o=e[e.length-1];r===0&&(this._coordinateBufferPtr=0,this._coordinateBuffer=new Array(this._vertexDimension),o.push(this._coordinateBuffer)),this._coordinateBuffer[this._coordinateBufferPtr++]=a}_deriveApplyTransform(e){const{hasZ:s,hasM:r}=e;return s&&r?Je:s?ee:r?Ne:B}}async function ke(t,e,s){const r=R(t),a={...s},o=k.from(e),n=!o.quantizationParameters,{data:i}=await le(r,o,new $e({sourceSpatialReference:o.sourceSpatialReference,applyTransform:n}),a);return i}function Me(t){const e=t.toJSON();return e.attachmentTypes&&(e.attachmentTypes=e.attachmentTypes.join(",")),e.keywords&&(e.keywords=e.keywords.join(",")),e.globalIds&&(e.globalIds=e.globalIds.join(",")),e.objectIds&&(e.objectIds=e.objectIds.join(",")),e.size&&(e.size=e.size.join(",")),e}function te(t,e){const s={};for(const r of t){const{parentObjectId:a,parentGlobalId:o,attachmentInfos:n}=r;for(const i of n){const{id:u}=i,l=de(ce(`${e}/${a}/attachments/${u}`)),d=he.fromJSON(i);d.set({url:l,parentObjectId:a,parentGlobalId:o}),s[a]?s[a].push(d):s[a]=[d]}}return s}function Qe(t,e,s){let r={query:M({...t.query,f:"json",...Me(e)})};return s&&(r={...s,...r,query:{...s.query,...r.query}}),p(t.path+"/queryAttachments",r)}async function Ve(t,e,s){const r=R(t);return Qe(r,ye.from(e),{...s}).then(a=>te(a.data.attachmentGroups,r.path))}async function Ue(t,e,s){const r=R(t);return pe(r,k.from(e),{...s}).then(a=>({count:a.data.count,extent:Q.fromJSON(a.data.extent)}))}function Be(t,e){const s=t.toJSON();return s.objectIds&&(s.objectIds=s.objectIds.join(",")),s.orderByFields&&(s.orderByFields=s.orderByFields.join(",")),s.outFields&&!(e!=null&&e.returnCountOnly)?s.outFields.includes("*")?s.outFields="*":s.outFields=s.outFields.join(","):delete s.outFields,s.outSpatialReference&&(s.outSR=s.outSR.wkid||JSON.stringify(s.outSR.toJSON()),delete s.outSpatialReference),s.dynamicDataSource&&(s.layer=JSON.stringify({source:s.dynamicDataSource}),delete s.dynamicDataSource),s}async function ze(t,e,s){const r=await se(t,e,s),a=r.data,o=a.geometryType,n=a.spatialReference,i={};for(const u of a.relatedRecordGroups){const l={fields:void 0,objectIdFieldName:void 0,geometryType:o,spatialReference:n,hasZ:!!a.hasZ,hasM:!!a.hasM,features:u.relatedRecords};if(u.objectId!=null)i[u.objectId]=l;else for(const d in u)u.hasOwnProperty(d)&&d!=="relatedRecords"&&(i[u[d]]=l)}return{...r,data:i}}async function Le(t,e,s){const r=await se(t,e,s,{returnCountOnly:!0}),a=r.data,o={};for(const n of a.relatedRecordGroups)n.objectId!=null&&(o[n.objectId]=n.count);return{...r,data:o}}async function se(t,e,s={},r){const a=M({...t.query,f:"json",...r,...Be(e,r)});return p(t.path+"/queryRelatedRecords",{...s,query:{...s.query,...a}})}async function Ze(t,e,s){e=C.from(e);const r=R(t);return ze(r,e,s).then(a=>{const o=a.data,n={};return Object.keys(o).forEach(i=>n[i]=V.fromJSON(o[i])),n})}async function Xe(t,e,s){e=C.from(e);const r=R(t);return Le(r,e,{...s}).then(a=>a.data)}const X="Layer does not support extent calculation.";function Ye(t,e){var o,n;const s=t.geometry,r=t.toJSON(),a=r;if(c(s)&&(a.geometry=JSON.stringify(s),a.geometryType=ge(s),a.inSR=s.spatialReference.wkid||JSON.stringify(s.spatialReference)),(o=r.topFilter)!=null&&o.groupByFields&&(a.topFilter.groupByFields=r.topFilter.groupByFields.join(",")),(n=r.topFilter)!=null&&n.orderByFields&&(a.topFilter.orderByFields=r.topFilter.orderByFields.join(",")),r.topFilter&&(a.topFilter=JSON.stringify(a.topFilter)),r.objectIds&&(a.objectIds=r.objectIds.join(",")),r.orderByFields&&(a.orderByFields=r.orderByFields.join(",")),r.outFields&&!((e==null?void 0:e.returnCountOnly)||(e==null?void 0:e.returnExtentOnly)||(e==null?void 0:e.returnIdsOnly))?r.outFields.includes("*")?a.outFields="*":a.outFields=r.outFields.join(","):delete a.outFields,r.outSR?a.outSR=r.outSR.wkid||JSON.stringify(r.outSR):s&&r.returnGeometry&&(a.outSR=a.inSR),r.returnGeometry&&delete r.returnGeometry,r.timeExtent){const i=r.timeExtent,{start:u,end:l}=i;u==null&&l==null||(a.time=u===l?u:`${u!=null?u:"null"},${l!=null?l:"null"}`),delete r.timeExtent}return a}async function He(t,e,s,r){const a=await v(t,e,"json",r);return fe(e,s,a.data),a}async function Ke(t,e,s){return c(e.timeExtent)&&e.timeExtent.isEmpty?{data:{objectIds:[]}}:v(t,e,"json",s,{returnIdsOnly:!0})}async function We(t,e,s){return c(e.timeExtent)&&e.timeExtent.isEmpty?{data:{count:0,extent:null}}:v(t,e,"json",s,{returnExtentOnly:!0,returnCountOnly:!0}).then(r=>{const a=r.data;if(a.hasOwnProperty("extent"))return r;if(a.features)throw new Error(X);if(a.hasOwnProperty("count"))throw new Error(X);return r})}function et(t,e,s){return c(e.timeExtent)&&e.timeExtent.isEmpty?Promise.resolve({data:{count:0}}):v(t,e,"json",s,{returnIdsOnly:!0,returnCountOnly:!0})}function v(t,e,s,r={},a={}){const o=typeof t=="string"?H(t):t,n=e.geometry?[e.geometry]:[];return r.responseType=s==="pbf"?"array-buffer":"json",me(n,null,r).then(i=>{const u=i&&i[0];c(u)&&((e=e.clone()).geometry=u);const l=M({...o.query,f:s,...a,...Ye(e,a)});return p(J(o.path,"queryTopFeatures"),{...r,query:{...l,...r.query}})})}async function tt(t,e,s,r){const a=R(t),o={...r},{data:n}=await He(a,P.from(e),s,o);return V.fromJSON(n)}async function st(t,e,s){const r=R(t);return(await Ke(r,P.from(e),{...s})).data.objectIds}async function rt(t,e,s){const r=R(t),a=await We(r,P.from(e),{...s});return{count:a.data.count,extent:Q.fromJSON(a.data.extent)}}async function at(t,e,s){const r=R(t);return(await et(r,P.from(e),{...s})).data.count}let q=class extends Fe{constructor(...t){super(...t),this.requestOptions=null,this.url=null}normalizeCtorArgs(t,e){return typeof t!="string"?t:{url:t,...e}}get parsedUrl(){return this._parseUrl(this.url)}_parseUrl(t){return H(t)}_encode(t,e,s){const r={};for(const a in t){if(a==="declaredClass")continue;const o=t[a];if(o!=null&&typeof o!="function")if(Array.isArray(o)){r[a]=[];for(let n=0;n<o.length;n++)r[a][n]=this._encode(o[n])}else if(typeof o=="object")if(o.toJSON){const n=o.toJSON(s&&s[a]);r[a]=e?n:JSON.stringify(n)}else r[a]=e?o:JSON.stringify(o);else r[a]=o}return r}};y([g({readOnly:!0})],q.prototype,"parsedUrl",null),y([g()],q.prototype,"requestOptions",void 0),y([g({type:String})],q.prototype,"url",void 0),q=y([U("esri.tasks.Task")],q);const ot=q;let b=class extends ot{constructor(t){super(t),this.dynamicDataSource=null,this.fieldsIndex=null,this.format="json",this.gdbVersion=null,this.infoFor3D=null,this.sourceSpatialReference=null}async execute(t,e){const s=await this.executeJSON(t,e);return this.featureSetFromJSON(t,s,e)}async executeJSON(t,e){var u;const s={...this.requestOptions,...e},r=this._normalizeQuery(t),a=((u=t.outStatistics)==null?void 0:u[0])!=null,o=G("featurelayer-pbf-statistics"),n=!a||o;let i;if(this.format==="pbf"&&n)try{i=await ke(this.url,r,s)}catch(l){if(l.name!=="query:parsing-pbf")throw l;this.format="json"}return this.format!=="json"&&n||(i=await _e(this.url,r,s)),this._normalizeFields(i.fields),i}async featureSetFromJSON(t,e,s){if(!this._queryIs3DObjectFormat(t)||S(this.infoFor3D)||!e.assetMaps||!e.features||!e.features.length)return V.fromJSON(e);const{meshFeatureSetFromJSON:r}=await be(Re(()=>import("./meshFeatureSet.e448c389.js").then(function(a){return a.a}),["assets/meshFeatureSet.e448c389.js","assets/index.6c049565.js","assets/index.cf071e35.css","assets/georeference.11d1c93a.js","assets/mat3f64.6d32a1d7.js","assets/mat4f64.ff2a477c.js","assets/quat.4f976512.js","assets/quatf64.4ae3e6f1.js","assets/BufferView.f5101c27.js","assets/vec33.9bd40b84.js","assets/imageUtils.753f41b1.js","assets/earcut.afc1d357.js","assets/deduplicate.b87c02b8.js"]),s);return r(t,this.infoFor3D,e)}executeForCount(t,e){const s={...this.requestOptions,...e},r=this._normalizeQuery(t);return Ce(this.url,r,s)}executeForExtent(t,e){const s={...this.requestOptions,...e},r=this._normalizeQuery(t);return Ue(this.url,r,s)}executeForIds(t,e){const s={...this.requestOptions,...e},r=this._normalizeQuery(t);return Pe(this.url,r,s)}executeRelationshipQuery(t,e){t=C.from(t);const s={...this.requestOptions,...e};return(this.gdbVersion||this.dynamicDataSource)&&((t=t.clone()).gdbVersion=t.gdbVersion||this.gdbVersion,t.dynamicDataSource=t.dynamicDataSource||this.dynamicDataSource),Ze(this.url,t,s)}executeRelationshipQueryForCount(t,e){t=C.from(t);const s={...this.requestOptions,...e};return(this.gdbVersion||this.dynamicDataSource)&&((t=t.clone()).gdbVersion=t.gdbVersion||this.gdbVersion,t.dynamicDataSource=t.dynamicDataSource||this.dynamicDataSource),Xe(this.url,t,s)}executeAttachmentQuery(t,e){const s={...this.requestOptions,...e};return Ve(this.url,t,s)}executeTopFeaturesQuery(t,e){const s={...this.requestOptions,...e};return tt(this.parsedUrl,t,this.sourceSpatialReference,s)}executeForTopIds(t,e){const s={...this.requestOptions,...e};return st(this.parsedUrl,t,s)}executeForTopExtents(t,e){const s={...this.requestOptions,...e};return rt(this.parsedUrl,t,s)}executeForTopCount(t,e){const s={...this.requestOptions,...e};return at(this.parsedUrl,t,s)}_normalizeQuery(t){let e=k.from(t);if(e.sourceSpatialReference=e.sourceSpatialReference||this.sourceSpatialReference,(this.gdbVersion||this.dynamicDataSource)&&(e=e===t?e.clone():e,e.gdbVersion=t.gdbVersion||this.gdbVersion,e.dynamicDataSource=t.dynamicDataSource?K.from(t.dynamicDataSource):this.dynamicDataSource),c(this.infoFor3D)&&this._queryIs3DObjectFormat(t)){e=e===t?e.clone():e,e.formatOf3DObjects=null;for(const s of this.infoFor3D.queryFormats){if(s==="3D_glb"){e.formatOf3DObjects=s;break}s!=="3D_gltf"||e.formatOf3DObjects||(e.formatOf3DObjects=s)}if(!e.formatOf3DObjects)throw new O("query:unsupported-3d-query-formats","Could not find any supported 3D object query format. Only supported formats are 3D_glb and 3D_gltf");if(S(e.outFields)||!e.outFields.includes("*")){e=e===t?e.clone():e,S(e.outFields)&&(e.outFields=[]);const{originX:s,originY:r,originZ:a,translationX:o,translationY:n,translationZ:i,scaleX:u,scaleY:l,scaleZ:d,rotationX:_,rotationY:h,rotationZ:f,rotationDeg:F}=this.infoFor3D.transformFieldRoles;e.outFields.push(s,r,a,o,n,i,u,l,d,_,h,f,F)}}return e}_normalizeFields(t){if(c(this.fieldsIndex)&&c(t))for(const e of t){const s=this.fieldsIndex.get(e.name);s&&Object.assign(e,s.toJSON())}}_queryIs3DObjectFormat(t){return c(this.infoFor3D)&&t.returnGeometry&&t.multipatchOption!=="xyFootprint"&&!t.outStatistics}};y([g({type:K})],b.prototype,"dynamicDataSource",void 0),y([g()],b.prototype,"fieldsIndex",void 0),y([g()],b.prototype,"format",void 0),y([g()],b.prototype,"gdbVersion",void 0),y([g()],b.prototype,"infoFor3D",void 0),y([g()],b.prototype,"sourceSpatialReference",void 0),b=y([U("esri.tasks.QueryTask")],b);const nt=b,it=new W({originalAndCurrentFeatures:"original-and-current-features",none:"none"});async function Y(t){return typeof t=="string"?Z(t)||{data:t}:new Promise((e,s)=>{const r=new FileReader;r.readAsDataURL(t),r.onload=()=>e(Z(r.result)),r.onerror=a=>s(a)})}const ut=new Set(["Feature Layer","Table"]),lt=new W({Started:"published",Publishing:"publishing",Stopped:"unavailable"});let w=class extends Oe{constructor(){super(...arguments),this.type="feature-layer",this.refresh=Se(async()=>{var s,r;await this.load();const t=(s=this.sourceJSON.editingInfo)==null?void 0:s.lastEditDate;if(t==null)return{dataChanged:!0,updates:{}};try{await this._fetchService(null)}catch{return{dataChanged:!0,updates:{}}}const e=t!==((r=this.sourceJSON.editingInfo)==null?void 0:r.lastEditDate);return{dataChanged:e,updates:e?{editingInfo:this.sourceJSON.editingInfo,extent:this.sourceJSON.extent}:null}})}load(t){const e=c(t)?t.signal:null;return this.addResolvingPromise(this._fetchService(this.layer.sourceJSON,e)),Promise.resolve(this)}get queryTask(){const{capabilities:{query:{supportsFormatPBF:t}},parsedUrl:e,dynamicDataSource:s,infoFor3D:r,gdbVersion:a,spatialReference:o,fieldsIndex:n}=this.layer,i=G("featurelayer-pbf")&&t&&S(r)?"pbf":"json";return new nt({url:e.path,format:i,fieldsIndex:n,infoFor3D:r,dynamicDataSource:s,gdbVersion:a,sourceSpatialReference:o})}async addAttachment(t,e){await this.load();const s=t.attributes[this.layer.objectIdField],r=this.layer.parsedUrl.path+"/"+s+"/addAttachment",a=this._getLayerRequestOptions(),o=this._getFormDataForAttachment(e,a.query);try{const n=await p(r,{body:o});return this._createFeatureEditResult(n.data.addAttachmentResult)}catch(n){throw this._createAttachmentErrorResult(s,n)}}async updateAttachment(t,e,s){await this.load();const r=t.attributes[this.layer.objectIdField],a=this.layer.parsedUrl.path+"/"+r+"/updateAttachment",o=this._getLayerRequestOptions({query:{attachmentId:e}}),n=this._getFormDataForAttachment(s,o.query);try{const i=await p(a,{body:n});return this._createFeatureEditResult(i.data.updateAttachmentResult)}catch(i){throw this._createAttachmentErrorResult(r,i)}}async applyEdits(t,e){await this.load();const s=this.layer.infoFor3D,r=c(s),a=r||(e==null?void 0:e.globalIdUsed),o=t.addFeatures.map(m=>this._serializeFeature(m,s)),n=t.updateFeatures.map(m=>this._serializeFeature(m,s)),i=this._getFeatureIds(t.deleteFeatures,a);Ie(o,n,this.layer.spatialReference);const u=[],l=[],d=[...t.deleteAttachments];for(const m of t.addAttachments)u.push(await this._serializeAttachment(m));for(const m of t.updateAttachments)l.push(await this._serializeAttachment(m));const _=u.length||l.length||d.length?{adds:u,updates:l,deletes:d}:null;let h,f=null;if(r){f=new Map;const m=[];for(const x of t.addAssets)m.push(this._serializeAssetMapEditAndUploadAssets(x,f));const T=await Promise.all(m);h=T.length?{adds:T,updates:[],deletes:[]}:void 0}const F={gdbVersion:(e==null?void 0:e.gdbVersion)||this.layer.gdbVersion,rollbackOnFailure:e==null?void 0:e.rollbackOnFailureEnabled,useGlobalIds:a,returnEditMoment:e==null?void 0:e.returnEditMoment,usePreviousEditMoment:e==null?void 0:e.usePreviousEditMoment,sessionId:e==null?void 0:e.sessionId};e!=null&&e.returnServiceEditsOption?(F.edits=JSON.stringify([{id:this.layer.layerId,adds:o,updates:n,deletes:i,attachments:_,assetMaps:qe(h)}]),F.returnServiceEditsOption=it.toJSON(e==null?void 0:e.returnServiceEditsOption),F.returnServiceEditsInSourceSR=e==null?void 0:e.returnServiceEditsInSourceSR):(F.adds=o.length?JSON.stringify(o):null,F.updates=n.length?JSON.stringify(n):null,F.deletes=i.length?a?JSON.stringify(i):i.join(","):null,F.attachments=_&&JSON.stringify(_),F.assetMaps=c(h)?JSON.stringify(h):void 0);const re=this._getLayerRequestOptions({method:"post",query:F}),z=e!=null&&e.returnServiceEditsOption?this.layer.url:this.layer.parsedUrl.path,E=await p(z+"/applyEdits",re);if(r&&E.data!=null&&E.data.assetMaps!=null){const m=E.data,T=this.layer.objectIdField,x=[];for(const I of m.addResults)I.success&&x.push(I.objectId);for(const I of m.updateResults)I.success&&x.push(I.objectId);const ae=this._createRequestQueryOptions(),D=await p(z+"/query",{...ae,query:{f:"json",formatOf3DObjects:"3D_glb",where:`OBJECTID IN (${x.join(",")})`,outFields:`${T}`}});if(D&&D.data&&D.data.assetMaps&&c(f)){const I=D.data.assetMaps;for(const N of I){const A=f.get(N.parentGlobalId).geometry;c(A)&&A.type==="mesh"&&A.updateExternalSource({source:[{name:N.assetName,source:N.assetName}],extent:A.extent})}}}return this._createEditsResult(E)}async deleteAttachments(t,e){await this.load();const s=t.attributes[this.layer.objectIdField],r=this.layer.parsedUrl.path+"/"+s+"/deleteAttachments";try{return(await p(r,this._getLayerRequestOptions({query:{attachmentIds:e.join(",")},method:"post"}))).data.deleteAttachmentResults.map(this._createFeatureEditResult)}catch(a){throw this._createAttachmentErrorResult(s,a)}}fetchRecomputedExtents(t={}){const e=t.signal;return this.load({signal:e}).then(async()=>{const s=this._getLayerRequestOptions({...t,query:{returnUpdates:!0}}),{layerId:r,url:a}=this.layer,{data:o}=await p(`${a}/${r}`,s),{id:n,extent:i,fullExtent:u,timeExtent:l}=o,d=i||u;return{id:n,fullExtent:d&&Q.fromJSON(d),timeExtent:l&&we.fromJSON({start:l[0],end:l[1]})}})}async queryAttachments(t,e={}){const{parsedUrl:s}=this.layer,r=s.path;await this.load();const a=this._getLayerRequestOptions(e);if(!this.layer.get("capabilities.operations.supportsQueryAttachments")){const{objectIds:o}=t,n=[];for(const i of o){const u=r+"/"+i+"/attachments";n.push(p(u,a))}return Promise.all(n).then(i=>o.map((u,l)=>({parentObjectId:u,attachmentInfos:i[l].data.attachmentInfos}))).then(i=>te(i,r))}return this.queryTask.executeAttachmentQuery(t,a)}async queryFeatures(t,e){return await this.load(),this.queryTask.execute(t,{...e,query:this._createRequestQueryOptions(e)})}async queryFeaturesJSON(t,e){return await this.load(),this.queryTask.executeJSON(t,{...e,query:this._createRequestQueryOptions(e)})}async queryObjectIds(t,e){return await this.load(),this.queryTask.executeForIds(t,{...e,query:this._createRequestQueryOptions(e)})}async queryFeatureCount(t,e){return await this.load(),this.queryTask.executeForCount(t,{...e,query:this._createRequestQueryOptions(e)})}async queryExtent(t,e){return await this.load(),this.queryTask.executeForExtent(t,{...e,query:this._createRequestQueryOptions(e)})}async queryRelatedFeatures(t,e){return await this.load(),this.queryTask.executeRelationshipQuery(t,{...e,query:this._createRequestQueryOptions(e)})}async queryRelatedFeaturesCount(t,e){return await this.load(),this.queryTask.executeRelationshipQueryForCount(t,{...e,query:this._createRequestQueryOptions(e)})}async queryTopFeatures(t,e){return await this.load(),this.queryTask.executeTopFeaturesQuery(t,{...e,query:this._createRequestQueryOptions(e)})}async queryTopObjectIds(t,e){return await this.load(),this.queryTask.executeForTopIds(t,{...e,query:this._createRequestQueryOptions(e)})}async queryTopExtents(t,e){return await this.load(),this.queryTask.executeForTopExtents(t,{...e,query:this._createRequestQueryOptions(e)})}async queryTopCount(t,e){return await this.load(),this.queryTask.executeForTopCount(t,{...e,query:this._createRequestQueryOptions(e)})}async fetchPublishingStatus(){if(!xe(this.layer.url))return"unavailable";const t=J(this.layer.url,"status"),e=await p(t,{query:{f:"json"}});return lt.fromJSON(e.data.status)}_createRequestQueryOptions(t){const e={...this.layer.customParameters,token:this.layer.apiKey,...t==null?void 0:t.query};return this.layer.datesInUnknownTimezone&&(e.timeReferenceUnknownClient=!0),e}async _fetchService(t,e){if(!t){const{data:r}=await p(this.layer.parsedUrl.path,this._getLayerRequestOptions({query:G("featurelayer-advanced-symbols")?{returnAdvancedSymbols:!0}:{},signal:e}));t=r}this.sourceJSON=this._patchServiceJSON(t);const s=t.type;if(!ut.has(s))throw new O("feature-layer-source:unsupported-type",`Source type "${s}" is not supported`)}_patchServiceJSON(t){var e;if(t.type!=="Table"&&t.geometryType&&!((e=t==null?void 0:t.drawingInfo)!=null&&e.renderer)&&!t.defaultSymbol){const s=Ae(t.geometryType).renderer;je("drawingInfo.renderer",s,t)}return t.geometryType==="esriGeometryMultiPatch"&&t.infoFor3D&&(t.geometryType="mesh"),t}_serializeFeature(t,e){const{geometry:s,attributes:r}=t;if(c(e)&&c(t.geometry)&&t.geometry.type==="mesh"){const a={...r},o=t.geometry,n=o.origin,i=o.transform;if(a[e.transformFieldRoles.originX]=n.x,a[e.transformFieldRoles.originY]=n.y,a[e.transformFieldRoles.originZ]=n.z,c(i)){const u=i.translation,l=i.scale,d=i.rotation;a[e.transformFieldRoles.translationX]=u[0],a[e.transformFieldRoles.translationY]=u[1],a[e.transformFieldRoles.translationZ]=u[2],a[e.transformFieldRoles.scaleX]=l[0],a[e.transformFieldRoles.scaleY]=l[1],a[e.transformFieldRoles.scaleZ]=l[2],a[e.transformFieldRoles.rotationX]=d[0],a[e.transformFieldRoles.rotationY]=d[1],a[e.transformFieldRoles.rotationZ]=d[2],a[e.transformFieldRoles.rotationDeg]=d[3]}return{geometry:null,attributes:a}}return S(s)?{attributes:r}:s.type==="mesh"||s.type==="extent"?null:{geometry:s.toJSON(),attributes:r}}async _serializeAttachment(t){const{feature:e,attachment:s}=t,{globalId:r,name:a,contentType:o,data:n,uploadId:i}=s,u={globalId:r,parentGlobalId:null,contentType:null,name:null,uploadId:null,data:null};if(e&&(u.parentGlobalId="attributes"in e?e.attributes&&e.attributes[this.layer.globalIdField]:e.globalId),i)u.uploadId=i;else if(n){const l=await Y(n);u.contentType=l.mediaType,u.data=l.data,n instanceof File&&(u.name=n.name)}return a&&(u.name=a),o&&(u.contentType=o),u}async _serializeAssetMapEditAndUploadAssets(t,e){const s=this.layer.url;let r=null;try{const l=new Blob([t.data],{type:t.mimeType}),d=new FormData;d.append("f","json"),d.append("file",l,`${t.assetName}`);const _={body:d,method:"post",responseType:"json"},{data:h}=await p(`${s}/uploads/upload`,_);if(!h.success)throw new O("feature-layer-source:upload-failure","Expected upload to be successfull.");r={assetType:t.assetType,assetUploadId:h.item.itemID}}catch{r=null}if(S(r)){const l=await Y(new Blob([t.data]));if(!l.isBase64)throw new O("feature-layer-source:uploadAssets-failure","Expected gltf data in base64 format after conversion.");r={assetType:t.assetType,assetData:l.data}}if(S(r))throw new O("feature-layer-source:uploadAssets-failure","Unable to prepare uploadAsset request options.");const a={method:"post",query:{f:"json",assets:JSON.stringify([r])},responseType:"json"},o=await p(J(this.layer.parsedUrl.path,"uploadAssets"),a);if(o.data.uploadResults.length!==1||!o.data.uploadResults[0].success)throw new O("feature-layer-source:uploadAssets-failure","Bad response.");const n=o.data.uploadResults[0].assetHash,i=[];t.flags&$.PROJECT_VERTICES&&i.push("PROJECT_VERTICES");const u={globalId:t.assetMapGlobalId,parentGlobalId:t.featureGlobalId,assetName:t.assetName,assetHash:n,flags:i};return e.set(t.featureGlobalId,t.feature),u}_getFeatureIds(t,e){const s=t[0];return s?this._canUseGlobalIds(e,t)?this._getGlobalIdsFromFeatureIdentifier(t):"objectId"in s?this._getObjectIdsFromFeatureIdentifier(t):this._getIdsFromFeatures(t):[]}_getIdsFromFeatures(t){const e=this.layer.objectIdField;return t.map(s=>s.attributes&&s.attributes[e])}_canUseGlobalIds(t,e){return t&&"globalId"in e[0]}_getObjectIdsFromFeatureIdentifier(t){return t.map(e=>e.objectId)}_getGlobalIdsFromFeatureIdentifier(t){return t.map(e=>e.globalId)}_createEditsResult(t){const e=t.data,{layerId:s}=this.layer,r=[];let a=null;if(Array.isArray(e))for(const i of e)r.push({id:i.id,editedFeatures:i.editedFeatures}),i.id===s&&(a={addResults:i.addResults,updateResults:i.updateResults,deleteResults:i.deleteResults,attachments:i.attachments,editMoment:i.editMoment});else a=e;const o=a==null?void 0:a.attachments,n={addFeatureResults:a.addResults?a.addResults.map(this._createFeatureEditResult,this):[],updateFeatureResults:a.updateResults?a.updateResults.map(this._createFeatureEditResult,this):[],deleteFeatureResults:a.deleteResults?a.deleteResults.map(this._createFeatureEditResult,this):[],addAttachmentResults:o&&o.addResults?o.addResults.map(this._createFeatureEditResult,this):[],updateAttachmentResults:o&&o.updateResults?o.updateResults.map(this._createFeatureEditResult,this):[],deleteAttachmentResults:o&&o.deleteResults?o.deleteResults.map(this._createFeatureEditResult,this):[]};if(a.editMoment&&(n.editMoment=a.editMoment),r.length>0){n.editedFeatureResults=[];for(const i of r){const{adds:u,updates:l,deletes:d,spatialReference:_}=i.editedFeatures,h=_?new Ee(_):null;n.editedFeatureResults.push({layerId:i.id,editedFeatures:{adds:(u==null?void 0:u.map(f=>this._createEditedFeature(f,h)))||[],updates:(l==null?void 0:l.map(f=>({original:this._createEditedFeature(f[0],h),current:this._createEditedFeature(f[1],h)})))||[],deletes:(d==null?void 0:d.map(f=>this._createEditedFeature(f,h)))||[],spatialReference:h}})}}return n}_createEditedFeature(t,e){return new Te({attributes:t.attributes,geometry:De({...t.geometry,spatialReference:e})})}_createFeatureEditResult(t){const e=t.success===!0?null:t.error||{code:void 0,description:void 0};return{objectId:t.objectId,globalId:t.globalId,error:e?new O("feature-layer-source:edit-failure",e.description,{code:e.code}):null}}_createAttachmentErrorResult(t,e){const s=e.details.messages&&e.details.messages[0]||e.message,r=e.details.httpStatus||e.details.messageCode;return{objectId:t,globalId:null,error:new O("feature-layer-source:attachment-failure",s,{code:r})}}_getFormDataForAttachment(t,e){const s=t instanceof FormData?t:t&&t.elements?new FormData(t):null;if(s)for(const r in e){const a=e[r];a!=null&&(s.set?s.set(r,a):s.append(r,a))}return s}_getLayerRequestOptions(t={}){const{parsedUrl:e,gdbVersion:s,dynamicDataSource:r}=this.layer;return{...t,query:{gdbVersion:s,layer:r?JSON.stringify({source:r}):void 0,...e.query,f:"json",...this._createRequestQueryOptions(t)},responseType:"json"}}};y([g()],w.prototype,"type",void 0),y([g({constructOnly:!0})],w.prototype,"layer",void 0),y([g({readOnly:!0})],w.prototype,"queryTask",null),w=y([U("esri.layers.graphics.sources.FeatureLayerSource")],w);const pt=w;export{pt as default};
|