UNPKG

@arcgis/core

Version:

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

6 lines (5 loc) • 8.9 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.33/esri/copyright.txt for details. */ import e from"../../request.js";import t from"../../core/Error.js";import n from"../../core/Logger.js";import{makeAbsolute as i,addQueryParameters as r,urlToObject as o}from"../../core/urlUtils.js";import s from"../../geometry/SpatialReference.js";import{wgs84 as a}from"../../geometry/support/spatialReferenceUtils.js";import{project as l}from"../../geometry/support/webMercatorUtils.js";import{convertToFeatureSet as c,convertToGeometry as u,convertFromGeometry as d}from"../graphics/featureConversionUtils.js";import f from"../graphics/OptimizedFeatureSet.js";import{validateGeoJSON as m,inferLayerProperties as p,createOptimizedFeatures as g}from"../graphics/sources/geojson/geojson.js";import{createDrawingInfo as y}from"../graphics/sources/support/clientSideDefaults.js";import{mixAttributes as w}from"../graphics/sources/support/sourceUtils.js";import j from"../support/FieldsIndex.js";import{kebabDict as h}from"../support/fieldType.js";import{utc as b}from"../../time/constants.js";const F=()=>n.getLogger("esri.layers.ogc.ogcFeatureUtils"),I="startindex",T=new Set([I,"offset"]),k="http://www.opengis.net/def/crs/",x=`${k}OGC/1.3/CRS84`;var S;async function v(n,o,s={},a=5){const{links:l}=n,c=U(l,"items",S.geojson)||U(l,"http://www.opengis.net/def/rel/ogc/1.0/items",S.geojson);if(null==c)throw new t("ogc-feature-layer:missing-items-page","Missing items url");const{apiKey:u,customParameters:d,signal:f}=s,g=i(c.href,n.landingPage.url),w={limit:a,...d,token:u},T=r(g,w),k={accept:S.geojson},{data:x}=await e(T,{signal:f,headers:k}),v=A(T,a,x.links)??I;m(x);const O=p(x,{geometryType:o.geometryType}),P=o.fields||O.fields||[],q=null!=o.hasZ?o.hasZ:O.hasZ,N=O.geometryType,C=o.objectIdField||O.objectIdFieldName||"OBJECTID";let R=o.timeInfo;const $=P.find((({name:e})=>e===C));if($)$.editable=!1,$.nullable=!1;else{if(!O.objectIdFieldType)throw new t("ogc-feature-layer:missing-feature-id","Collection geojson require a feature id as a unique identifier");P.unshift({name:C,alias:C,type:"number"===O.objectIdFieldType?"esriFieldTypeOID":"esriFieldTypeString",editable:!1,nullable:!1})}if(C!==O.objectIdFieldName){const e=P.find((({name:e})=>e===O.objectIdFieldName));e&&(e.type="esriFieldTypeInteger")}P===O.fields&&O.unknownFields.length>0&&F().warn({name:"ogc-feature-layer:unknown-field-types",message:"Some fields types couldn't be inferred from the features and were dropped",details:{unknownFields:O.unknownFields}});for(const e of P){if(null==e.name&&(e.name=e.alias),null==e.alias&&(e.alias=e.name),"esriFieldTypeOID"!==e.type&&"esriFieldTypeGlobalID"!==e.type&&(e.editable=null==e.editable||!!e.editable,e.nullable=null==e.nullable||!!e.nullable),!e.name)throw new t("ogc-feature-layer:invalid-field-name","field name is missing",{field:e});if(!h.jsonValues.includes(e.type))throw new t("ogc-feature-layer:invalid-field-type",`invalid type for field "${e.name}"`,{field:e})}if(R){const e=new j(P);if(R.startTimeField){const t=e.get(R.startTimeField);t?(R.startTimeField=t.name,t.type="esriFieldTypeDate"):R.startTimeField=null}if(R.endTimeField){const t=e.get(R.endTimeField);t?(R.endTimeField=t.name,t.type="esriFieldTypeDate"):R.endTimeField=null}if(R.trackIdField){const t=e.get(R.trackIdField);t?R.trackIdField=t.name:(R.trackIdField=null,F().warn({name:"ogc-feature-layer:invalid-timeInfo-trackIdField",message:"trackIdField is missing",details:{timeInfo:R}}))}R.timeReference||={timeZoneIANA:b},R.startTimeField||R.endTimeField||(F().warn({name:"ogc-feature-layer:invalid-timeInfo",message:"startTimeField and endTimeField are missing",details:{timeInfo:R}}),R=void 0)}return{drawingInfo:N?y(N):null,extent:L(n),geometryType:N,fields:P,hasZ:!!q,objectIdField:C,paginationParameter:v,timeInfo:R}}async function O(n,r={}){const{links:o,url:s}=n,a=U(o,"data",S.json)||U(o,"http://www.opengis.net/def/rel/ogc/1.0/data",S.json);if(null==a)throw new t("ogc-feature-layer:missing-collections-page","Missing collections url");const{apiKey:l,customParameters:c,signal:u}=r,d=i(a.href,s),{data:f}=await e(d,{signal:u,headers:{accept:S.json},query:{...c,token:l}});for(const e of f.collections)e.landingPage=n;return f}async function P(n,r={}){const{links:o,url:s}=n,a=U(o,"conformance",S.json)||U(o,"http://www.opengis.net/def/rel/ogc/1.0/conformance",S.json);if(null==a)throw new t("ogc-feature-layer:missing-conformance-page","Missing conformance url");const{apiKey:l,customParameters:c,signal:u}=r,d=i(a.href,s),{data:f}=await e(d,{signal:u,headers:{accept:S.json},query:{...c,token:l}});return f}async function q(t,n={}){const{apiKey:i,customParameters:r,signal:o}=n,{data:s}=await e(t,{signal:o,headers:{accept:S.json},query:{...r,token:i}});return s.url=t,s}async function N(t,n={}){const{links:r,url:o}=t,s=U(r,"service-desc",S.openapi);if(null==s)return F().warn("ogc-feature-layer:missing-openapi-page","The OGC API-Features server does not have an OpenAPI page."),null;const{apiKey:a,customParameters:l,signal:c}=n,u=i(s.href,o),{data:d}=await e(u,{signal:c,headers:{accept:S.openapi},query:{...l,token:a}});return d}function C(e){const t=/^http:\/\/www\.opengis.net\/def\/crs\/(?<authority>.*)\/(?<version>.*)\/(?<code>.*)$/i.exec(e),n=t?.groups;if(!n)return null;const{authority:i,code:r}=n;switch(i.toLowerCase()){case"ogc":switch(r.toLowerCase()){case"crs27":return s.GCS_NAD_1927.wkid;case"crs83":return 4269;case"crs84":case"crs84h":return s.WGS84.wkid;default:return null}case"esri":case"epsg":{const e=Number.parseInt(r,10);return Number.isNaN(e)?null:e}default:return null}}async function R(e,t,n){const i=await $(e,t,n);return c(i)}async function $(n,r,o){const{collection:{links:c,landingPage:{url:m}},layerDefinition:p,maxRecordCount:y,queryParameters:{apiKey:h,customParameters:b},spatialReference:F,supportedCrs:I}=n,T=U(c,"items",S.geojson)||U(c,"http://www.opengis.net/def/rel/ogc/1.0/items",S.geojson);if(null==T)throw new t("ogc-feature-layer:missing-items-page","Missing items url");const{geometry:k,num:x,start:v,timeExtent:O,where:P}=r;if(r.objectIds)throw new t("ogc-feature-layer:query-by-objectids-not-supported","Queries with object ids are not supported");const q=s.fromJSON(F),N=r.outSpatialReference??q,C=N.isWGS84?null:W(N,I),R=K(k,I),$=M(O),G=Z(P),D=x??(null==v?y:10),L=0===v?void 0:v,{fields:A,geometryType:J,hasZ:z,objectIdField:E,paginationParameter:_}=p,B=i(T.href,m),{data:Q}=await e(B,{...o,query:{...b,...R,crs:C,datetime:$,query:G,limit:D,[_]:L,token:h},headers:{accept:S.geojson}}),V=g(Q,{geometryType:J,hasZ:z,objectIdField:E}),H=V.length===D&&!!U(Q.links??[],"next",S.geojson),X=new j(A);for(const e of V){const t={};w(X,t,e.attributes,!0);for(const e of X.fields)e.nullable&&!(e.name in t)&&(t[e.name]=null);t[E]=e.attributes[E],e.attributes=t}if(!C&&N.isWebMercator)for(const e of V)if(null!=e.geometry&&null!=J){const t=u(e.geometry,J,z,!1);t.spatialReference=s.WGS84,e.geometry=d(l(t,N))}for(const e of V)e.objectId=e.attributes[E];const Y=C||!C&&N.isWebMercator?N.toJSON():a,ee=new f;return ee.exceededTransferLimit=H,ee.features=V,ee.fields=A,ee.geometryType=J,ee.hasZ=z,ee.spatialReference=Y,ee}function G(e){return null!=e&&"extent"===e.type}function W(e,t){const{isWebMercator:n,wkid:i}=e;if(!i)return null;const r=n?t[3857]??t[102100]??t[102113]??t[900913]:t[e.wkid];return r?`${k}${r}`:null}function D(e){if(null==e)return"";const{xmin:t,ymin:n,xmax:i,ymax:r}=e;return`${t},${n},${i},${r}`}function M(e){if(null==e)return null;const{start:t,end:n}=e;return`${null!=t?t.toISOString():".."}/${null!=n?n.toISOString():".."}`}function Z(e){return null!=e&&e&&"1=1"!==e?e:null}function K(e,t){if(!G(e))return null;const{spatialReference:n}=e;if(!n||n.isWGS84)return{bbox:D(e)};const i=W(n,t);return null!=i?{bbox:D(e),"bbox-crs":i}:n.isWebMercator?{bbox:D(l(e,s.WGS84))}:null}function L(e){const t=e.extent?.spatial;if(!t)return null;const n=t.bbox[0],i=4===n.length,[r,o]=n,a=i?void 0:n[2];return{xmin:r,ymin:o,xmax:i?n[2]:n[3],ymax:i?n[3]:n[4],zmin:a,zmax:i?void 0:n[5],spatialReference:s.WGS84.toJSON()}}function U(e,t,n){return e.find((({rel:e,type:i})=>e===t&&i===n))??e.find((({rel:e,type:n})=>e===t&&!n))}function A(e,t,n){if(!n)return;const i=U(n,"next",S.geojson),r=o(i?.href)?.query;if(!r)return;const s=o(e).query,a=Object.keys(s??{}),l=Object.entries(r).filter((([e])=>!a.includes(e))).find((([e,n])=>T.has(e.toLowerCase())&&Number.parseInt(n,10)===t)),c=l?.[0];return c}!function(e){e.json="application/json",e.geojson="application/geo+json",e.openapi="application/vnd.oai.openapi+json;version=3.0"}(S||(S={}));export{x as crsDefault,k as crsPrefix,v as getCollectionDefinition,O as getServerCollections,P as getServerConformance,q as getServerLandingPage,N as getServerOpenApi,C as getSpatialReferenceWkid,R as queryFeatureSetJSON,$ as queryOptimizedFeatureSet};