@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 5.05 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{createScreenPointArray as e,screenPointObjectToArray as n,castScreenPointArray as r}from"../../../../core/screenUtils.js";import{create as t}from"../../../../core/libs/gl-matrix-2/factories/vec2f64.js";import{h as o,d as l,l as s,c,e as i,g as a,f as u}from"../../../../chunks/vec32.js";import{create as p}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import m from"../../../../geometry/Point.js";import{projectPoint as f}from"../../../../geometry/projectionUtils.js";import{intersectRay as d,create as g,getNormal as E,fromPositionAndNormal as y}from"../../../../geometry/support/plane.js";import{create as S,closestPoints as j}from"../../../../geometry/support/ray.js";import{projectPoint as v}from"../../../../geometry/support/vector.js";import{sv2d as R}from"../../../../geometry/support/vectorStacks.js";import{getZForElevationMode as b}from"../../../../support/elevationInfoUtils.js";import{fromScreen as w}from"../../support/geometryUtils/ray.js";import{Intersector as x}from"../../webgl-engine/lib/Intersector.js";import{StoreResults as I}from"../../webgl-engine/lib/IntersectorInterfaces.js";import{IntersectorType as U}from"../../webgl-engine/lib/IntersectorType.js";import{terrainId as H}from"../../webgl-engine/lib/verticalOffsetUtils.js";import{EventPipeline as O}from"../../../interactive/dragEventPipeline.js";function T(e,n){return P(e,(()=>n))}function C(e){return P(e,(e=>e.plane))}function P(e,t){const o=p(),l=p();let s=!1;return c=>{const i=t(c);if("start"===c.action){const t=n(c.screenStart,r(R.get())),l=w(e.state.camera,t,Q);null!=l&&(s=d(i,l,o))}if(!s)return null;const a=n(c.screenEnd,r(R.get())),u=w(e.state.camera,a,Q);return null==u?null:d(i,u,l)?{...c,renderStart:o,renderEnd:l,plane:i,ray:u}:null}}function D(n,r,t=0,o=null,l=null){let s=null;return c=>{if("start"===c.action&&(s=n.sceneIntersectionHelper.intersectElevationFromScreen(e(c.screenStart.x,c.screenStart.y),r,t,l),null!=s&&null!=o&&!f(s,s,o)))return null;if(null==s)return null;const i=n.sceneIntersectionHelper.intersectElevationFromScreen(e(c.screenEnd.x,c.screenEnd.y),r,t,l);return null!=i&&(null==o||f(i,i,o))?{...c,mapStart:s,mapEnd:i}:null}}function M(e,n,r,t=null,o=null){return D(e,r,b(n,e,r),t,o)}function N(e,n,r,t){const o=r.toMap(e.screenStart);return null!=o?M(n,o,r.elevationInfo,t):null}function h(e,n){const r=K,t=L,s=g();e.renderCoordsHelper.worldUpAtPosition(n,r);const c=o(E(s),r,l(t,n,e.state.camera.eye));return o(c,c,r),y(n,c,s)}function G(e,n,r){let t=null;const o=new O;return o.next(T(e,h(e,n))).next(k(e,n)).next(F(e,r)).next((e=>{e.mapEnd.x=e.mapStart.x,e.mapEnd.y=e.mapStart.y,t=e})),e=>(t=null,o.execute(e),t)}function k(e,n){const r=p(),t=s(n);e.renderCoordsHelper.worldUpAtPosition(n,r);const o=p(),m=p(),f=o=>{if(l(o,o,n),v(r,o,o),"global"===e.viewingMode){s(o)*Math.sign(i(r,o))<.001-t&&l(o,a(o,r,.001),n)}return u(o,o,n),o};return e=>(e.renderStart=f(c(o,e.renderStart)),e.renderEnd=f(c(m,e.renderEnd)),e)}function A(e,t){const o=o=>{const l=n(o,r(J)),s=w(e.state.camera,l,Q);if(null==s)return null;const c=j(t,s,K,L);return c?.[0]};return e=>{const n=o(e.screenStart);if(null==n)return null;const r=o(e.screenEnd);return null==r?null:{...e,renderStart:n,renderEnd:r}}}function F(e,n){const r=e.renderCoordsHelper;return e=>{const t=r.fromRenderCoords(e.renderStart,new m({spatialReference:n})),o=r.fromRenderCoords(e.renderEnd,new m({spatialReference:n}));return null!=t&&null!=o?{...e,mapStart:t,mapEnd:o}:null}}var q;function z(e){let n=null;return r=>{switch(r.action){case"start":n=e.disableDisplay();break;case"end":case"cancel":null!=n&&(n.remove(),n=null)}return r}}function B(r,t=null){const o=new x(r.state.viewingMode);o.options.selectionMode=!0,o.options.store=I.MIN,o.options.hud=!1;const l=e(),s={requiresGroundFeedback:!0,enableDraped:!0,exclude:new Set},c=p(),i=t??r.spatialReference,a=e=>{r.map.ground&&r.map.ground.opacity<1?s.exclude.add(H):s.exclude.delete(H),r.sceneIntersectionHelper.intersectIntersectorScreen(n(e,l),o,s);const t=o.results.min;let a;if(t.getIntersectionPoint(c))a=t.intersector===U.TERRAIN?q.GROUND:q.OTHER;else{if(!o.results.ground.getIntersectionPoint(c))return null;a=q.GROUND}return{location:r.renderCoordsHelper.fromRenderCoords(c,new m({spatialReference:i})),surfaceType:a}};let u;return e=>{if("start"===e.action){const n=a(e.screenStart);u=null!=n?n.location:null}if(null==u)return null;const n=a(e.screenEnd);return null!=n?.location?{...e,mapStart:u,mapEnd:n.location,surfaceType:n.surfaceType}:null}}!function(e){e[e.GROUND=0]="GROUND",e[e.OTHER=1]="OTHER"}(q||(q={}));const J=t(),K=p(),L=p(),Q=S();export{q as SurfaceType,F as convertToMapCoordinates,z as hideManipulatorWhileDragging,k as projectToWorldUp,B as screenToMap3D,M as screenToMapXYAtLocation,N as screenToMapXYForManipulatedObject,T as screenToRenderPlane,C as screenToRenderPlaneFromEvent,A as screenToRenderRay,G as screenToZConstrained};