UNPKG

@arcgis/core

Version:

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

6 lines (5 loc) 2.38 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.32/esri/copyright.txt for details. */ import{clone as e}from"../../../core/lang.js";import{signalFromSignalOrOptions as t}from"../../../core/promiseUtils.js";import{fromJSON as r}from"../../../geometry/support/jsonUtils.js";import{normalizeCentralMeridian as a}from"../../../geometry/support/normalizeUtils.js";import{equals as i}from"../../../geometry/support/spatialReferenceUtils.js";import{checkProjectionSupport as s,project as n}from"./projectionSupport.js";import{getQueryBBoxes as o}from"./QueryEngine.js";import{QueryEngineResult as l}from"./QueryEngineResult.js";import{normalizeQueryLike as p}from"./queryUtils.js";import{validateQuery as m}from"./queryValidationUtils.js";import{getSpatialQueryOperator as c}from"./spatialQuerySupport.js";async function u(c,u,y){const d=t(y),{point:x,distance:g,returnEdge:R,vertexMode:j}=u;if(!R&&"none"===j)return{candidates:[]};let w=e(u.query);w=await c.schedule((()=>p(w,c.definitionExpression,c.spatialReference)),d),w=await c.reschedule((()=>m(w,{availableFields:c.availableFields,fieldsIndex:c.fieldsIndex,geometryType:c.geometryType,spatialReference:c.spatialReference})),d);const h=!i(x.spatialReference,c.spatialReference);h&&await s(x.spatialReference,c.spatialReference);const b="number"==typeof g?g:g.x,Q="number"==typeof g?g:g.y,S={xmin:x.x-b,xmax:x.x+b,ymin:x.y-Q,ymax:x.y+Q,spatialReference:x.spatialReference},U=h?n(S,c.spatialReference):S;if(!U)return{candidates:[]};const q=(await a(r(x),null,{signal:d}))[0],E=(await a(r(U),null,{signal:d}))[0];if(null==q||null==E)return{candidates:[]};const F=new l(await c.reschedule((()=>c.searchFeatures(o(E.toJSON()))),d),w,c);await c.reschedule((()=>c.executeObjectIdsQuery(F)),d),await c.reschedule((()=>c.executeTimeQuery(F)),d),await c.reschedule((()=>c.executeAttributesQuery(F)),d),await c.reschedule((()=>f(c,F,d)),d);const T=q.toJSON(),v=h?n(T,c.spatialReference):T,I=h?Math.max(U.xmax-U.xmin,U.ymax-U.ymin)/2:g;return F.createSnappingResponse({...u,point:v,distance:I},x.spatialReference)}async function f(e,t,r){const{query:a}=t,{spatialRel:i}=a;if(!t?.items?.length||!a.geometry||!i)return;const s=await c(i,a.geometry,e.geometryType,e.hasZ,e.hasM),n=await e.runSpatialFilter(t.items,(e=>s(e.geometry)),r);t.items=n}export{u as executeQueryForSnapping};