GeoJSONSourceWorker.8d5def53.js 9.0 KB

1
  1. import{eT as _,ca as x,g as I,gs as k,eR as C,an as D,m as $,s as Q,bC as G,a as F,bH as M,c0 as P,U as Z,as as S,c2 as A,c4 as v,gt as N}from"./index.6c049565.js";import{u as z}from"./FeatureStore.cb9b2be9.js";import{f as b,g as w}from"./projectionSupport.2b4a8796.js";import{Y as B}from"./QueryEngine.05824aeb.js";import{L,I as U,T as H}from"./geojson.eccb99e5.js";import{o as J,a as V,i as W}from"./clientSideDefaults.e21714f1.js";import{w as Y,m as T,f as j,a as E,g as R}from"./sourceUtils.3b4ff83d.js";import"./PooledRBush.f1e26fa4.js";import"./centroid.0c969b82.js";import"./json.879c9adc.js";import"./QueryEngineResult.fe74257f.js";import"./quantizationUtils.4f3ed95a.js";import"./WhereClause.39c9a123.js";import"./utils.5216fcae.js";import"./generateRendererUtils.03b1f269.js";import"./utils.9592ea84.js";import"./QueryEngineCapabilities.78217f95.js";import"./timeSupport.4d8d3d9b.js";const X={hasAttachments:!1,capabilities:"query, editing, create, delete, update",useStandardizedQueries:!0,supportsCoordinatesQuantization:!0,supportsReturningQueryGeometry:!0,advancedQueryCapabilities:{supportsQueryAttachments:!1,supportsStatistics:!0,supportsPercentileStatistics:!0,supportsReturningGeometryCentroid:!0,supportsQueryWithDistance:!0,supportsDistinct:!0,supportsReturningQueryExtent:!0,supportsReturningGeometryProperties:!1,supportsHavingClause:!0,supportsOrderBy:!0,supportsPagination:!0,supportsQueryWithResultType:!1,supportsSqlExpression:!0,supportsDisjointSpatialRel:!0}};class _e{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._fieldsIndex=this._createDefaultAttributes=null}async load(e,t={}){this._loadOptions={url:e.url,customParameters:e.customParameters};const s=[];await this._checkProjection(e.spatialReference);let i=null;e.url&&(i=await this._fetch(t==null?void 0:t.signal));const a=L(i,{geometryType:e.geometryType}),l=e.fields||a.fields||[],u=e.hasZ!=null?e.hasZ:a.hasZ,d=a.geometryType;let c=e.objectIdField||a.objectIdFieldName||"__OBJECTID";const m=e.spatialReference||_;let r=e.timeInfo;l===a.fields&&a.unknownFields.length>0&&s.push({name:"geojson-layer:unknown-field-types",message:"Some fields types couldn't be inferred from the features and were dropped",details:{unknownFields:a.unknownFields}});let n=new x(l).get(c);n?(n.type!=="esriFieldTypeString"&&(n.type="esriFieldTypeOID"),n.editable=!1,n.nullable=!1,c=n.name):(n={alias:c,name:c,type:a.objectIdFieldType==="string"?"esriFieldTypeString":"esriFieldTypeOID",editable:!1,nullable:!1},l.unshift(n));const p={};for(const o of l){if(o.name==null&&(o.name=o.alias),o.alias==null&&(o.alias=o.name),!o.name)throw new I("geojson-layer:invalid-field-name","field name is missing",{field:o});if(!k.jsonValues.includes(o.type))throw new I("geojson-layer:invalid-field-type",`invalid type for field "${o.name}"`,{field:o});if(o.name!==n.name){const g=C(o);g!==void 0&&(p[o.name]=g)}}this._fieldsIndex=new x(l);const y=this._fieldsIndex.requiredFields.indexOf(n);if(y>-1&&this._fieldsIndex.requiredFields.splice(y,1),r){if(r.startTimeField){const o=this._fieldsIndex.get(r.startTimeField);o?(r.startTimeField=o.name,o.type="esriFieldTypeDate"):r.startTimeField=null}if(r.endTimeField){const o=this._fieldsIndex.get(r.endTimeField);o?(r.endTimeField=o.name,o.type="esriFieldTypeDate"):r.endTimeField=null}if(r.trackIdField){const o=this._fieldsIndex.get(r.trackIdField);o?r.trackIdField=o.name:(r.trackIdField=null,s.push({name:"geojson-layer:invalid-timeInfo-trackIdField",message:"trackIdField is missing",details:{timeInfo:r}}))}r.startTimeField||r.endTimeField||(s.push({name:"geojson-layer:invalid-timeInfo",message:"startTimeField and endTimeField are missing",details:{timeInfo:r}}),r=null)}const h=d?J(d):null,f={warnings:s,featureErrors:[],layerDefinition:{...X,drawingInfo:h,templates:V(p),extent:null,geometryType:d,objectIdField:c,fields:l,hasZ:!!u,timeInfo:r}};this._queryEngine=new B({fields:l,geometryType:d,hasM:!1,hasZ:u,objectIdField:c,spatialReference:m,timeInfo:r,featureStore:new z({geometryType:d,hasM:!1,hasZ:u}),cacheSpatialQueries:!0}),this._createDefaultAttributes=W(p,c);const q=await this._createFeatures(i);this._objectIdGenerator=this._createObjectIdGenerator(this._queryEngine,q);const O=this._normalizeFeatures(q,f.warnings,f.featureErrors);if(this._queryEngine.featureStore.addMany(O),f.layerDefinition.extent=this._queryEngine.fullExtent,f.layerDefinition.timeInfo){const{start:o,end:g}=this._queryEngine.timeExtent;f.layerDefinition.timeInfo.timeExtent=[o,g]}return f}async applyEdits(e){const{spatialReference:t,geometryType:s}=this._queryEngine;return await Promise.all([Y(t,s),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(),this._queryEngine.executeQueryForSnapping(e,t.signal)}async refresh(e){var t;return this._loadOptions.customParameters=e,(t=this._snapshotTask)==null||t.abort(),this._snapshotTask=D(this._snapshotFeatures),this._snapshotTask.promise.then(s=>{this._queryEngine.featureStore.clear(),this._objectIdGenerator=this._createObjectIdGenerator(this._queryEngine,s);const i=this._normalizeFeatures(s);i&&this._queryEngine.featureStore.addMany(i)},s=>{this._queryEngine.featureStore.clear(),$(s)||Q.getLogger("esri.layers.GeoJSONLayer").error(new I("geojson-layer:refresh","An error occurred during refresh",{error:s}))}),await this._waitSnapshotComplete(),{extent:this._queryEngine.fullExtent,timeExtent:this._queryEngine.timeExtent}}async _createFeatures(e){const{geometryType:t,hasZ:s,objectIdField:i}=this._queryEngine,a=U(e,{geometryType:t,hasZ:s,objectIdField:i});if(!G(this._queryEngine.spatialReference,_))for(const l of a)F(l.geometry)&&(l.geometry=M(w(P(l.geometry,this._queryEngine.geometryType,this._queryEngine.hasZ,!1),_,this._queryEngine.spatialReference)));return a}async _waitSnapshotComplete(){if(this._snapshotTask&&!this._snapshotTask.finished){try{await this._snapshotTask.promise}catch{}return this._waitSnapshotComplete()}}async _fetch(e){const{url:t,customParameters:s}=this._loadOptions,i=(await Z(t,{responseType:"json",query:{...s},signal:e})).data;return await H(i),i}_normalizeFeatures(e,t,s){const{objectIdField:i}=this._queryEngine,a=[];for(const l of e){const u=this._createDefaultAttributes(),d=T(this._fieldsIndex,u,l.attributes,!0,t);d?s==null||s.push(d):(this._assignObjectId(u,l.attributes,!0),l.attributes=u,l.objectId=u[i],a.push(l))}return a}_applyEdits(e){const{adds:t,updates:s,deletes:i}=e,a={addResults:[],deleteResults:[],updateResults:[],uidToObjectId:{}};if(t&&t.length&&this._applyAddEdits(a,t),s&&s.length&&this._applyUpdateEdits(a,s),i&&i.length){for(const l of i)a.deleteResults.push(j(l));this._queryEngine.featureStore.removeManyById(i)}return{extent:this._queryEngine.fullExtent,timeExtent:this._queryEngine.timeExtent,featureEditResults:a}}_applyAddEdits(e,t){var r;const{addResults:s}=e,{geometryType:i,hasM:a,hasZ:l,objectIdField:u,spatialReference:d,featureStore:c}=this._queryEngine,m=[];for(const n of t){if(n.geometry&&i!==S(n.geometry)){s.push(E("Incorrect geometry type."));continue}const p=this._createDefaultAttributes(),y=T(this._fieldsIndex,p,n.attributes);if(y)s.push(y);else{if(this._assignObjectId(p,n.attributes),n.attributes=p,n.uid!=null){const h=n.attributes[u];e.uidToObjectId[n.uid]=h}if(F(n.geometry)){const h=(r=n.geometry.spatialReference)!=null?r:d;n.geometry=w(R(n.geometry,h),h,d)}m.push(n),s.push(j(n.attributes[u]))}}c.addMany(A([],m,i,l,a,u))}_applyUpdateEdits({updateResults:e},t){var c;const{geometryType:s,hasM:i,hasZ:a,objectIdField:l,spatialReference:u,featureStore:d}=this._queryEngine;for(const m of t){const{attributes:r,geometry:n}=m,p=r&&r[l];if(p==null){e.push(E(`Identifier field ${l} missing`));continue}if(!d.has(p)){e.push(E(`Feature with object id ${p} missing`));continue}const y=v(d.getFeature(p),s,a,i);if(F(n)){if(s!==S(n)){e.push(E("Incorrect geometry type."));continue}const h=(c=n.spatialReference)!=null?c:u;y.geometry=w(R(n,h),h,u)}if(r){const h=T(this._fieldsIndex,y.attributes,r);if(h){e.push(h);continue}}d.add(N(y,s,a,i,l)),e.push(j(p))}}_createObjectIdGenerator(e,t){const s=e.fieldsIndex.get(e.objectIdField);if(s.type==="esriFieldTypeString")return()=>s.name+"-"+Date.now().toString(16);let i=Number.NEGATIVE_INFINITY;for(const a of t)a.objectId&&(i=Math.max(i,a.objectId));return i=Math.max(0,i)+1,()=>i++}_assignObjectId(e,t,s=!1){const i=this._queryEngine.objectIdField;e[i]=s&&i in t?t[i]:this._objectIdGenerator()}async _checkProjection(e){try{await b(_,e)}catch{throw new I("geojson-layer","Projection not supported")}}}export{_e as default};