@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 3.92 kB
JavaScript
/*
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"../../../core/Error.js";import{extentContainsPoint as r,extentContainsMultipoint as t}from"../../../geometry/support/contains.js";import{getExtentIntersector as i}from"../../../geometry/support/intersects.js";import{isPolygon as o,isExtent as s,getJsonType as n}from"../../../geometry/support/jsonUtils.js";import{isValid as a}from"../../../geometry/support/spatialReferenceUtils.js";import{polygonContainsPoint as l,polygonContainsMultipoint as p}from"../contains.js";import{convertFromPolygon as m}from"../featureConversionUtils.js";import u from"../OptimizedGeometry.js";import{getGeometry as y}from"./geometryUtils.js";import{checkProjectionSupport as c}from"./projectionSupport.js";const f="unsupported-query",R={spatialRelationship:{esriSpatialRelIntersects:!0,esriSpatialRelContains:!0,esriSpatialRelWithin:!0,esriSpatialRelCrosses:!0,esriSpatialRelDisjoint:!0,esriSpatialRelTouches:!0,esriSpatialRelOverlaps:!0,esriSpatialRelEnvelopeIntersects:!0,esriSpatialRelIndexIntersects:!1,esriSpatialRelRelation:!1},queryGeometry:{esriGeometryPoint:!0,esriGeometryMultiPatch:!1,esriGeometryMultipoint:!0,esriGeometryPolyline:!0,esriGeometryPolygon:!0,esriGeometryEnvelope:!0},layerGeometry:{esriGeometryPoint:!0,esriGeometryMultiPatch:!0,esriGeometryMultipoint:!0,esriGeometryPolyline:!0,esriGeometryPolygon:!0,esriGeometryEnvelope:!1}};function S(e){return null!=e&&!0===R.spatialRelationship[e]}function j(e){return null!=e&&!0===R.queryGeometry[n(e)]}function G(e){return null!=e&&!0===R.layerGeometry[e]}const g={esriSpatialRelIntersects:()=>import("../../../geometry/operators/json/intersectsOperator.js"),esriSpatialRelContains:()=>import("../../../geometry/operators/json/containsOperator.js"),esriSpatialRelCrosses:()=>import("../../../geometry/operators/json/crossesOperator.js"),esriSpatialRelDisjoint:()=>import("../../../geometry/operators/json/disjointOperator.js"),esriSpatialRelEnvelopeIntersects:null,esriSpatialRelIndexIntersects:null,esriSpatialRelOverlaps:()=>import("../../../geometry/operators/json/overlapsOperator.js"),esriSpatialRelTouches:()=>import("../../../geometry/operators/json/touchesOperator.js"),esriSpatialRelWithin:()=>import("../../../geometry/operators/json/withinOperator.js"),esriSpatialRelRelation:null};function h(e){const r=g[e];if(null==r)throw new Error(`Cannot load unsupported spatial operator: ${e}`);return r()}async function I(e,n,a,c,f){if(o(n)){if("esriGeometryPoint"===a&&("esriSpatialRelIntersects"===e||"esriSpatialRelContains"===e)){const e=m(new u,n,!1,!1);return r=>l(e,!1,!1,r)}if("esriGeometryMultipoint"===a){const r=m(new u,n,!1,!1);if("esriSpatialRelContains"===e)return e=>p(r,!1,!1,e,c,f)}}if(s(n)){if("esriGeometryPoint"===a&&("esriSpatialRelIntersects"===e||"esriSpatialRelContains"===e))return e=>r(n,y(a,c,f,e));if("esriGeometryMultipoint"===a&&"esriSpatialRelContains"===e)return e=>t(n,y(a,c,f,e));if("esriSpatialRelIntersects"===e){const e=i(a);return r=>e(n,y(a,c,f,r))}}"esriSpatialRelEnvelopeIntersects"===e&&(e="esriSpatialRelIntersects");const R=await h(e);return e=>R.execute(n,y(a,c,f,e))}async function w(r,t,i){const{spatialRel:o,geometry:s}=r;if(s){if(!S(o))throw new e(f,"Unsupported query spatial relationship",{query:r});if(a(s.spatialReference)&&a(i)){if(!j(s))throw new e(f,"Unsupported query geometry type",{query:r});if(!G(t))throw new e(f,"Unsupported layer geometry type",{query:r});if(r.outSR)return c(r.geometry?.spatialReference,r.outSR)}}}function d(e){if(s(e))return!0;if(o(e)){for(const r of e.rings){if(5!==r.length)return!1;if(r[0][0]!==r[1][0]||r[0][0]!==r[4][0]||r[2][0]!==r[3][0]||r[0][1]!==r[3][1]||r[0][1]!==r[4][1]||r[1][1]!==r[2][1])return!1}return!0}return!1}export{d as canQueryWithRBush,w as checkSpatialQuerySupport,I as getSpatialQueryOperator};