@doegis/core
Version:
DOE GIS API
3 lines (1 loc) • 2.62 kB
JavaScript
import t from"../../../request.js";import{isSome as e}from"../../../core/maybe.js";import{urlToObject as r,join as o}from"../../../core/urlUtils.js";import{getJsonType as n}from"../../../geometry/support/jsonUtils.js";import{normalizeCentralMeridian as i}from"../../../geometry/support/normalizeUtils.js";import{mapParameters as s}from"../../operations/urlUtils.js";import{applyFeatureSetZUnitScaling as u}from"./queryZScale.js";const l="Layer does not support extent calculation.";function y(t,r){const o=t.geometry,i=t.toJSON(),s=i;if(e(o)&&(s.geometry=JSON.stringify(o),s.geometryType=n(o),s.inSR=o.spatialReference.wkid||JSON.stringify(o.spatialReference)),i.topFilter?.groupByFields&&(s.topFilter.groupByFields=i.topFilter.groupByFields.join(",")),i.topFilter?.orderByFields&&(s.topFilter.orderByFields=i.topFilter.orderByFields.join(",")),i.topFilter&&(s.topFilter=JSON.stringify(s.topFilter)),i.objectIds&&(s.objectIds=i.objectIds.join(",")),i.orderByFields&&(s.orderByFields=i.orderByFields.join(",")),i.outFields&&!(r?.returnCountOnly||r?.returnExtentOnly||r?.returnIdsOnly)?i.outFields.includes("*")?s.outFields="*":s.outFields=i.outFields.join(","):delete s.outFields,i.outSR?s.outSR=i.outSR.wkid||JSON.stringify(i.outSR):o&&i.returnGeometry&&(s.outSR=s.inSR),i.returnGeometry&&delete i.returnGeometry,i.timeExtent){const t=i.timeExtent,{start:e,end:r}=t;null==e&&null==r||(s.time=e===r?e:`${e??"null"},${r??"null"}`),delete i.timeExtent}return s}async function d(t,e,r,o){const n=await c(t,e,"json",o);return u(e,r,n.data),n}async function m(t,r,o){return e(r.timeExtent)&&r.timeExtent.isEmpty?{data:{objectIds:[]}}:c(t,r,"json",o,{returnIdsOnly:!0})}async function p(t,r,o){return e(r.timeExtent)&&r.timeExtent.isEmpty?{data:{count:0,extent:null}}:c(t,r,"json",o,{returnExtentOnly:!0,returnCountOnly:!0}).then((t=>{const e=t.data;if(e.hasOwnProperty("extent"))return t;if(e.features)throw new Error(l);if(e.hasOwnProperty("count"))throw new Error(l);return t}))}function a(t,r,o){return e(r.timeExtent)&&r.timeExtent.isEmpty?Promise.resolve({data:{count:0}}):c(t,r,"json",o,{returnIdsOnly:!0,returnCountOnly:!0})}function c(n,u,l,d={},m={}){const p="string"==typeof n?r(n):n,a=u.geometry?[u.geometry]:[];return d.responseType="pbf"===l?"array-buffer":"json",i(a,null,d).then((r=>{const n=r&&r[0];e(n)&&((u=u.clone()).geometry=n);const i=s({...p.query,f:l,...m,...y(u,m)});return t(o(p.path,"queryTopFeatures"),{...d,query:{...i,...d.query}})}))}export{a as executeQueryForTopCount,p as executeQueryForTopExtents,m as executeQueryForTopIds,d as executeTopFeaturesQuery,y as queryToQueryStringParameters};