@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 3.98 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{isSome as t}from"../../../core/arrayUtils.js";import{invert as r}from"../../../core/libs/gl-matrix-2/math/mat2d.js";import{create as e,clone as s}from"../../../core/libs/gl-matrix-2/factories/mat2df64.js";import{rotationTo as a,invert as o}from"../../../core/libs/gl-matrix-2/math/quat.js";import{create as i}from"../../../core/libs/gl-matrix-2/factories/quatf64.js";import{g as n,e as l,d as h,n as m,h as c,v as f}from"../../../chunks/vec32.js";import{create as p}from"../../../core/libs/gl-matrix-2/factories/vec3f64.js";import d from"../../../geometry/Point.js";import{Axis as u}from"../../../geometry/support/Axis.js";function g(t,r,e=null){return null!=e?[t,r,e]:[t,r]}function w(t,r,e=null){return null!=e?{x:t,y:r,z:e}:{x:t,y:r}}class R{constructor(t){this.spatialReference=t}mapToLocalMultiple(r){return r.map((t=>this.mapToLocal(t))).filter(t)}get doUnnormalization(){return!1}}class v extends R{constructor(t,a,o=null){super(a),this._defaultZ=o,this.transform=e(),this.transformInv=e(),this.transform=s(t),r(this.transformInv,this.transform)}makeMapPoint(t,r){return g(t,r,this._defaultZ)}mapToLocal(t){return w(this.transform[0]*t[0]+this.transform[2]*t[1]+this.transform[4],this.transform[1]*t[0]+this.transform[3]*t[1]+this.transform[5])}localToMap(t){return g(this.transformInv[0]*t.x+this.transformInv[2]*t.y+this.transformInv[4],this.transformInv[1]*t.x+this.transformInv[3]*t.y+this.transformInv[5],this._defaultZ)}}class W extends R{constructor(t,r){super(t.spatialReference),this.view=t,this.defaultZ=null,this.pWS=p(),this.tangentFrameUpWS=p(),this.tangentFrameRightWS=p(),this.tangentFrameForwardWS=p(),this.localFrameRightWS=p(),this.localFrameUpWS=p(),this.worldToLocalTransform=i(),this.localToWorldTransform=i(),this.scale=1,this.scale=t.resolution,this.referenceMapPoint=r,this.defaultZ=r.hasZ?r.z:null;const e=t.state.camera.viewRight;this.view.renderCoordsHelper.toRenderCoords(this.referenceMapPoint,this.pWS),this.view.renderCoordsHelper.worldBasisAtPosition(this.pWS,u.X,this.tangentFrameRightWS),this.view.renderCoordsHelper.worldBasisAtPosition(this.pWS,u.Y,this.tangentFrameUpWS),this.view.renderCoordsHelper.worldBasisAtPosition(this.pWS,u.Z,this.tangentFrameForwardWS);const s=p();n(s,this.tangentFrameForwardWS,l(e,this.tangentFrameForwardWS)),h(this.localFrameRightWS,e,s),m(this.localFrameRightWS,this.localFrameRightWS),c(this.localFrameUpWS,this.tangentFrameForwardWS,this.localFrameRightWS),a(this.worldToLocalTransform,this.localFrameRightWS,this.tangentFrameRightWS),o(this.localToWorldTransform,this.worldToLocalTransform)}get doUnnormalization(){return"global"===this.view.viewingMode}makeMapPoint(t,r){return g(t,r,this.defaultZ)}mapToLocal(t){const r=p();this.view.renderCoordsHelper.toRenderCoords(new d({x:t[0],y:t[1],spatialReference:this.spatialReference}),r),f(r,r,this.worldToLocalTransform);const e=this.view.renderCoordsHelper.fromRenderCoords(r,new d({spatialReference:this.view.spatialReference}));return null!=e?w(e.x/this.scale,e.y/this.scale):null}localToMap(t){const r=p();this.view.renderCoordsHelper.toRenderCoords(new d({x:t.x*this.scale,y:t.y*this.scale,spatialReference:this.spatialReference}),r),f(r,r,this.localToWorldTransform);const e=this.view.renderCoordsHelper.fromRenderCoords(r,new d({spatialReference:this.view.spatialReference}));return null!=e?g(e.x,e.y,this.defaultZ):null}}function F(t,r){if("2d"===t.type)return new v(t.state.transform,t.spatialReference,r.length>2?r[2]:null);if("3d"===t.type){const e=r.length>2?new d({x:r[0],y:r[1],z:r[2],spatialReference:t.spatialReference}):new d({x:r[0],y:r[1],spatialReference:t.spatialReference});return new W(t,e)}return null}export{v as AffineCoordinateSystem,W as SceneViewCoordinateSystem,R as SurfaceCoordinateSystem,F as createViewAlignedCoordinateSystem,g as makeMapPoint,w as makeSurfacePoint};