1import{fE as I,d4 as R,f as E,fF as A,fG as D,fH as v,fI as N,fJ as P,fK as Z,e2 as G,eJ as M,at as B,bd as W,fL as z,fM as J,cc as H,fs as O,fN as L,fO as U,fP as V,fQ as K}from"./index-CyVzZKgG.js";import{f as Y}from"./FeatureStore-DZpNE1Gl.js";import{f as b,a as T}from"./queryUtils-BIR2uwrr.js";import{W as X}from"./QueryEngine-KAgJyoxW.js";import{I as ee,N as te,E as se}from"./geojson-DELlAOxv.js";import{S as ie,E as re,d as w,f as q,p as F,h as $}from"./sourceUtils-CxG44S9h.js";import"./BoundsStore-DZCxxFxh.js";import"./PooledRBush-DB__5DQZ.js";import"./timeSupport-b5uPa2kt.js";import"./optimizedFeatureQueryEngineAdapter-ChO8t3qC.js";import"./WhereClauseCache-BTC9eqgS.js";import"./WhereClause-CCCZLDyG.js";import"./utils-Csm8gh3v.js";import"./utils-Cr4jv42a.js";import"./ClassBreaksDefinition-B9s3WXiT.js";import"./SnappingCandidate-DGkpYqI6.js";import"./FixedIntervalBinParameters--Fojn42v.js";import"./date-Ctp1FiBW.js";const ne={hasAttachments:!1,capabilities:"query, editing, create, delete, update",useStandardizedQueries:!0,supportsCoordinatesQuantization:!0,supportsReturningQueryGeometry:!0,advancedQueryCapabilities:{supportsQueryAttachments:!1,supportsQueryAttachmentOrderByFields:!1,supportsQueryAttachmentWithTypeWildcard:!1,supportsQueryBins:!0,supportsQueryPivot:!1,supportsQueryWithCacheHint:!0,supportsQueryWithDistance:!0,supportsQueryWithResultType:!0,supportsStatistics:!0,supportsPercentileStatistics:!0,supportsReturningGeometryCentroid:!0,supportsDistinct:!0,supportsReturningQueryExtent:!0,supportsReturningGeometryProperties:!1,supportsHavingClause:!0,supportsOrderBy:!0,supportsPagination:!0,supportsSqlExpression:!0,supportsDisjointSpatialRel:!0},queryBinsCapabilities:ie};class qe{constructor(){this._queryEngine=null,this._snapshotFeatures=async e=>{const t=await this._fetch(e);return this._createFeatures(t)}}destroy(){var e;(e=this._queryEngine)==null||e.destroy(),this._queryEngine=this._createDefaultAttributes=null}async load(e,t={}){this._loadOptions={url:e.url,customParameters:e.customParameters};const r=[],[s]=await Promise.all([e.url?this._fetch(t==null?void 0:t.signal):null,this._checkProjection(e.spatialReference)]),i=ee(s,{geometryType:e.geometryType}),o=e.fields||i.fields||[],l=e.hasZ!=null?e.hasZ:i.hasZ,d=i.geometryType;let f=e.objectIdField||i.objectIdFieldName||"__OBJECTID";const m=e.spatialReference||I;let u=e.timeInfo;o===i.fields&&i.unknownFields.length>0&&r.push({name:"geojson-layer:unknown-field-types",message:"Some fields types couldn't be inferred from the features and were dropped",details:{unknownFields:i.unknownFields}});const p=new R(o);let n=p.get(f);n?(n.type!=="esriFieldTypeString"&&(n.type="esriFieldTypeOID"),n.editable=!1,n.nullable=!1,f=n.name):(n={alias:f,name:f,type:i.objectIdFieldType==="string"?"esriFieldTypeString":"esriFieldTypeOID",editable:!1,nullable:!1},o.unshift(n));const c={};for(const a of o){if(a.name==null&&(a.name=a.alias),a.alias==null&&(a.alias=a.name),!a.name)throw new E("geojson-layer:invalid-field-name","field name is missing",{field:a});if(!A.jsonValues.includes(a.type))throw new E("geojson-layer:invalid-field-type",`invalid type for field "${a.name}"`,{field:a});if(a.name!==n.name){const _=D(a);_!==void 0&&(c[a.name]=_)}a.length==null&&(a.length=v(a))}if(u){if(u.startTimeField){const a=p.get(u.startTimeField);
1a?(u.startTimeField=a.name,a.type="esriFieldTypeDate"):u.startTimeField=null}if(u.endTimeField){const a=p.get(u.endTimeField);a?(u.endTimeField=a.name,a.type="esriFieldTypeDate"):u.endTimeField=null}if(u.trackIdField){const a=p.get(u.trackIdField);a?u.trackIdField=a.name:(u.trackIdField=null,r.push({name:"geojson-layer:invalid-timeInfo-trackIdField",message:"trackIdField is missing",details:{timeInfo:u}}))}u.startTimeField||u.endTimeField||(r.push({name:"geojson-layer:invalid-timeInfo",message:"startTimeField and endTimeField are missing",details:{timeInfo:u}}),u=null)}const h=d?K(d):void 0,y=p.dateFields.length?{timeZoneIANA:P}:null,g={warnings:r,featureErrors:[],layerDefinition:{...ne,drawingInfo:h??void 0,templates:N(c),extent:void 0,geometryType:d,objectIdField:f,fields:o,hasZ:!!l,timeInfo:u,dateFieldsTimeReference:y}},Q={type:"object-id",fieldName:f};this._queryEngine=new X({fieldsIndex:R.fromLayerJSON({fields:o,timeInfo:u,dateFieldsTimeReference:y}),geometryType:d,hasM:!1,hasZ:l,featureIdInfo:Q,spatialReference:m,timeInfo:u,featureStore:new Y({geometryType:d,hasM:!1,hasZ:l})});const j=this._queryEngine.fieldsIndex.requiredFields.indexOf(n);j>-1&&this._queryEngine.fieldsIndex.requiredFields.splice(j,1),this._createDefaultAttributes=Z(c,f);const x=this._createFeatures(s);this._objectIdGenerator=this._createObjectIdGenerator(this._queryEngine,x);const C=this._normalizeFeatures(x,g.featureErrors);this._queryEngine.featureStore.addMany(C);const{fullExtent:k,timeExtent:S}=await this._queryEngine.fetchRecomputedExtents();if(g.layerDefinition.extent=k,S){const{start:a,end:_}=S;g.layerDefinition.timeInfo.timeExtent=[a,_]}return g}async applyEdits(e){const{spatialReference:t,geometryType:r}=this._queryEngine;return await Promise.all([re(t,r),b(e.adds,t),b(e.updates,t)]),await this._waitSnapshotComplete(),this._applyEdits(e)}async queryFeatures(e={},t={}){return await this._waitSnapshotComplete(),this._queryEngine.executeQuery(e,t.signal)}async queryFeatureCount(e={},t={}){return await this._waitSnapshotComplete(),this._queryEngine.executeQueryForCount(e,t.signal)}async queryObjectIds(e={},t={}){return await this._waitSnapshotComplete(),this._queryEngine.executeQueryForIds(e,t.signal)}async queryExtent(e={},t={}){return await this._waitSnapshotComplete(),this._queryEngine.executeQueryForExtent(e,t.signal)}async querySnapping(e,t={}){return await this._waitSnapshotComplete(),await this._queryEngine.executeQueryForSnapping(e,t.signal)}async queryAttributeBins(e,t={}){return await this._waitSnapshotComplete(),this._queryEngine.executeAttributeBinsQuery(e,t.signal)}async refresh(e){var s;this._loadOptions.customParameters=e,(s=this._snapshotTask)==null||s.abort(),this._snapshotTask=G(this._snapshotFeatures),this._snapshotTask.promise.then(i=>{this._queryEngine.featureStore.clear(),this._objectIdGenerator=this._createObjectIdGenerator(this._queryEngine,i);const o=this._normalizeFeatures(i);o&&this._queryEngine.featureStore.addMany(o)},i=>{this._queryEngine.featureStore.clear(),M(i)||B.getLogger("esri.layers.GeoJSONLayer").error(new E("geojson-layer:refresh","An error occurred during refresh",{error:i}))}),await this._waitSnapshotComplete();const{fullExtent:t,timeExtent:r}=await this._queryEngine.fetchRecomputedExtents();return{extent:t,timeExtent:r}}_createFeatures(e){if(e==null)return[];const{geometryType:t,hasZ:r,objectIdField:s}=this._queryEngine,i=te(e,{geometryType:t,hasZ:r,objectIdField:s});if(!W(this._queryEngine.spatialReference,I))for(const o of i)o.geometry!=null&&(o.geometry=z(T(J(o.geometry,this._queryEngine.geometryType,this._queryEngine.hasZ,!1),I,this._queryEngine.spatialReference)));return i}async _waitSnapshotComplete(){if(this._snapshotTask&&!this._snapshotTask.finished){try{await this._snapshotTask.promise}catch{}return this._waitSnapshotComplete()}}async _fetch(e){const{url:t,customParameters:r}=this._loadOptions,s=(await H(t??"",{responseType:"json",query:{...r},signal:e})).data;return se(s),s}_normalizeFeatures(e,t){const{objectIdField:r,fieldsIndex:s}=this._queryEngine,i=[];for(const o of e){const l=this._createDefaultAttributes(),d=w(s,l,o.attributes,!0);d?t==null||t.push(d):(this._assignObjectId(l,o.attributes,!0),o.attributes=l,o.objectId=l[r],i.push(o))}return i}async _applyEdits(e){const{adds:t,updates:r,deletes:s}=e,i={addResults:[],deleteResults:[],updateResults:[],uidToObjectId:{}};if(t!=null&&t.length&&this._applyAddEdits(i,t),r!=null&&r.length&&this._applyUpdateEdits(i,r),s==null?void 0:s.length){for(const d of s)i.deleteResults.push(q(d));this._queryEngine.featureStore.removeManyById(s)}const{fullExtent:o,timeExtent:l}=await this._queryEngine.fetchRecomputedExtents();return{extent:o,timeExtent:l,featureEditResults:i}}_applyAddEdits(e,t){const{addResults:r}=e,{geometryType:s,hasM:i,hasZ:o,objectIdField:l,spatialReference:d,featureStore:f,fieldsIndex:m}=this._queryEngine,u=[],p={type:"object-id",fieldName:l};for(const n of t){if(n.geometry&&s!==O(n.geometry)){r.push(F("Incorrect geometry type."));continue}const c=this._createDefaultAttributes(),h=w(m,c,n.attributes);if(h)r.push(h);else{if(this._assignObjectId(c,n.attributes),n.attributes=c,n.uid!=null){const y=n.attributes[l];e.uidToObjectId[n.uid]=y}if(n.geometry!=null){const y=n.geometry.spatialReference??d;n.geometry=T($(n.geometry,y),y,d)}u.push(n),r.push(q(n.attributes[l]))}}f.addMany(L([],u,s,o,i,p))}_applyUpdateEdits({updateResults:e},t){const{geometryType:r,hasM:s,hasZ:i,objectIdField:o,spatialReference:l,featureStore:d,fieldsIndex:f}=this._queryEngine,m={type:"object-id",fieldName:o};for(const u of t){const{attributes:p,geometry:n}=u,c=p==null?void 0:p[o];if(c==null){e.push(F(`Identifier field ${o} missing`));continue}if(!d.has(c)){e.push(F(`Feature with object id ${c} missing`));continue}const h=U(d.getFeature(c),r,i,s);if(n!=null){if(r!==O(n)){e.push(F("Incorrect geometry type."));continue}const y=n.spatialReference??l;h.geometry=T($(n,y),y,l)}if(p){const y=w(f,h.attributes,p);if(y){e.push(y);continue}}d.add(V(h,r,i,s,m)),e.push(q(c))}}_createObjectIdGenerator(e,t){const r=e.fieldsIndex.get(e.objectIdField);if(r.type==="esriFieldTypeString")return()=>r.name+"-"+Date.now().toString(16);let s=Number.NEGATIVE_INFINITY;for(const i of t)i.objectId&&(s=Math.max(s,i.objectId));return s=Math.max(0,s)+1,()=>s++}_assignObjectId(e,t,r=!1){const s=this._queryEngine.objectIdField;e[s]=r&&s in t?t[s]:this._objectIdGenerator()}async _checkProjection(e){try{await b(I,e)}catch{throw new E("geojson-layer","Projection not supported")}}}export{qe as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.