UNPKG

@arcgis/core

Version:

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

3 lines (2 loc) 7.57 kB
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */ import{__decorate as t}from"tslib";import e from"../../core/Accessor.js";import{property as i,subclass as o}from"../../core/accessorSupport/decorators.js";import{fromValues as s,create as a}from"../../core/libs/gl-matrix-2/factories/mat3f64.js";import{fromValues as r,create as l}from"../../core/libs/gl-matrix-2/factories/vec3f64.js";import{multiply as n,transpose as h}from"../../core/libs/gl-matrix-2/math/mat3.js";import{dot as m,scaleAndAdd as g,subtract as u,transformMat3 as c}from"../../core/libs/gl-matrix-2/math/vec3.js";import p from"../../geometry/Point.js";import d from"../../geometry/SpatialReference.js";import{WGS84ECEFSpatialReference as f}from"../../geometry/spatialReferenceEllipsoidUtils.js";import{projectBuffer as v}from"../../geometry/projection/projectBuffer.js";import{earth as _}from"../../geometry/support/Ellipsoid.js";import{videoMetadataEntryId as A}from"./videoUtils.js";const M=Math.PI/180;let V=class extends e{constructor(t){super(),this.averageElevation=0,this.imageHeight=0,this.imageWidth=0,this.metadataSupportsTransforms=!1,this.platformHeadingAngle=0,this.platformPitchAngle=0,this.platformRollAngle=0,this.sensorHeadingAngle=0,this.sensorAltitude=0,this.sensorHorizontalFieldOfView=0,this.sensorLatitude=0,this.sensorLongitude=0,this.sensorPitchAngle=0,this.sensorRollAngle=0,this.sensorVerticalFieldOfView=0,this.vttMetadata=new Map,this._createMat3FromValues=t=>{const e=t[0],i=t[1],o=t[2];return s(e[0],i[0],o[0],e[1],i[1],o[1],e[2],i[2],o[2])},this._multiplyMat3=(t,e)=>{const i=a();return n(i,t,e),i},this._transposeMat3=t=>{const e=a();return h(e,t),e},this._calculateCameraFovForward=()=>this._createMat3FromValues([[0,0,1],[Math.tan(.5*this.sensorHorizontalFieldOfView*M),0,0],[0,Math.tan(.5*this.sensorVerticalFieldOfView*M),0]]),this._calculateCameraFovReverse=()=>this._createMat3FromValues([[0,1/Math.tan(.5*this.sensorHorizontalFieldOfView*M),0],[0,0,1/Math.tan(.5*this.sensorVerticalFieldOfView*M)],[1,0,0]]),this._calculateCameraLook=()=>this._getRotationMatrixZYX(this.sensorHeadingAngle*M,this.sensorPitchAngle*M,this.sensorRollAngle*M),this._calculateImageDimensionsForward=()=>this._createMat3FromValues([[2/this.imageWidth,0,-1],[0,-2/this.imageHeight,-1],[0,0,1]]),this._calculateImageDimensionsReverse=()=>this._createMat3FromValues([[this.imageWidth/2,0,this.imageWidth/2],[0,-this.imageHeight/2,-this.imageHeight/2],[0,0,1]]),this._calculatePlatformPositionMatrix=()=>{const t=Math.sin(this.sensorLatitude*M),e=Math.cos(this.sensorLatitude*M),i=Math.sin(this.sensorLongitude*M),o=Math.cos(this.sensorLongitude*M);return this._createMat3FromValues([[-t*o,-i,-e*o],[-t*i,o,-e*i],[e,0,-t]])},this._calculatePlatformOrientation=()=>this._getRotationMatrixZYX(this.platformHeadingAngle*M,this.platformPitchAngle*M,this.platformRollAngle*M),this._extractValues=t=>{this.imageWidth=t.get(A.EsriVideoWidth)?.value,this.imageHeight=t.get(A.EsriVideoHeight)?.value;const e=t.get(A.SensorEllipsoidHeight)?.value;this.sensorAltitude=e??t.get(A.SensorTrueAltitude)?.value,this.sensorLatitude=t.get(A.SensorLatitude)?.value,this.sensorLongitude=t.get(A.SensorLongitude)?.value,this.sensorHeadingAngle=t.get(A.SensorAzimuthAngle)?.value,this.sensorPitchAngle=t.get(A.SensorElevationAngle)?.value,this.sensorRollAngle=t.get(A.SensorRollAngle)?.value,this.sensorHorizontalFieldOfView=t.get(A.SensorHorizontalFOV)?.value,this.sensorVerticalFieldOfView=t.get(A.SensorVerticalFOV)?.value,this.platformHeadingAngle=t.get(A.PlatformHeadingAngle)?.value,this.platformPitchAngle=t.get(A.PlatformPitchAngle)?.value,this.platformRollAngle=t.get(A.PlatformRollAngle)?.value,this.averageElevation=t.get(A.FrameCenterElevation)?.value||0},this._getRotationMatrixZYX=(t,e,i)=>{const o=Math.cos(t),s=Math.sin(t),a=Math.cos(e),r=Math.sin(e),l=Math.cos(i),n=Math.sin(i);return this._createMat3FromValues([[o*a,o*r*n-l*s,s*n+o*l*r],[a*s,o*l+s*r*n,l*s*r-o*n],[-r,a*n,a*l]])},this._initCameraSensor=()=>{const t=this._calculateCameraFovForward(),e=this._calculateCameraFovReverse(),i=this._calculateCameraLook(),o=this._calculateImageDimensionsForward(),s=this._calculateImageDimensionsReverse(),a=this._calculatePlatformPositionMatrix(),r=this._calculatePlatformOrientation(),l=this._multiplyMat3(this._multiplyMat3(a,r),i);this._imageToEarthTransform=this._multiplyMat3(this._multiplyMat3(l,t),o);const n=this._multiplyMat3(s,e);this._earthToImageTransform=this._multiplyMat3(n,this._transposeMat3(l)),this._platformPositionEcef=this._projectPointToECEF(this.sensorLongitude,this.sensorLatitude,this.sensorAltitude||this.averageElevation)},this._metadataSupportsTransforms=t=>{if(!t?.size)return!1;const e=t.get(A.EsriVideoWidth)?.value??0,i=t.get(A.EsriVideoHeight)?.value??0;if(e<=0||i<=0)return!1;const o=t.get(A.SensorEllipsoidHeight)?.value,s=t.get(A.SensorTrueAltitude)?.value,a=t.get(A.SensorLatitude)?.value,r=t.get(A.SensorLongitude)?.value;if(null==o&&null==s||null==a||null==r)return!1;const l=t.get(A.PlatformHeadingAngle)?.value,n=t.get(A.PlatformPitchAngle)?.value,h=t.get(A.PlatformRollAngle)?.value;if(null==l||null==n||null==h)return!1;const m=t.get(A.SensorHorizontalFOV)?.value,g=t.get(A.SensorVerticalFOV)?.value;if(null==m||null==g)return!1;const u=t.get(A.SensorAzimuthAngle)?.value,c=t.get(A.SensorElevationAngle)?.value,p=t.get(A.SensorRollAngle)?.value;return null!=u&&null!=c&&null!=p},this._projectPointToECEF=(t,e,i)=>{const o=[];return v([t,e,i],d.WGS84,0,o,f,0),new p({x:o[0],y:o[1],z:o[2],spatialReference:f})},this._projectImageVectorToEllipsoid=(t,e)=>{const i=_.semiMajorAxis+e,o=_.semiMinorAxis+e,s=o/i,a=i/o,{x:n,y:h,z:u}=this._platformPositionEcef,c=u??this.averageElevation,p=r(n,h,a*c),d=m(t,t),f=m(t,p),v=m(p,p)-i*i,A=(-f-Math.sqrt(f*f-d*v))/d;if(A<0)return[NaN,NaN,NaN];const M=l();return g(M,p,t,A),M[2]=M[2]*s,M};const e=t?.videoMetadata;this.updateSensorModel(e)}updateSensorModel(t){t?.size&&(this._set("metadataSupportsTransforms",this._metadataSupportsTransforms(t)),this.metadataSupportsTransforms&&(this._extractValues(t),this._initCameraSensor()))}transformGeoToImage(t,e,i){const o=this._platformPositionEcef;if(!o)return[0,0];const{x:s,y:a,z:n}=o,h=r(s,a,n),m=this._projectPointToECEF(t,e,i||this.averageElevation),g=l(),p=r(m.x,m.y,m.z);u(g,p,h),c(g,g,this._earthToImageTransform);const d=g[0],f=g[1],v=g[2];let _=r(NaN,NaN,NaN);return isNaN(v)||(_=r(d/v,f/v,v/v)),[_[0],_[1]]}transformImageToGeo(t,e){const i=r(t,e,1),o=l();c(o,i,this._imageToEarthTransform);const s=this._projectImageVectorToEllipsoid(o,this.averageElevation);let a;if(!isNaN(s[0])){const t=[];v([s[0],s[1],s[2]],f,0,t,d.WGS84,0),a=new p({x:t[0],y:t[1],z:t[2],spatialReference:d.WGS84})}return a}};t([i()],V.prototype,"averageElevation",void 0),t([i()],V.prototype,"imageHeight",void 0),t([i()],V.prototype,"imageWidth",void 0),t([i({readOnly:!0})],V.prototype,"metadataSupportsTransforms",void 0),t([i()],V.prototype,"platformHeadingAngle",void 0),t([i()],V.prototype,"platformPitchAngle",void 0),t([i()],V.prototype,"platformRollAngle",void 0),t([i()],V.prototype,"sensorHeadingAngle",void 0),t([i()],V.prototype,"sensorAltitude",void 0),t([i()],V.prototype,"sensorHorizontalFieldOfView",void 0),t([i()],V.prototype,"sensorLatitude",void 0),t([i()],V.prototype,"sensorLongitude",void 0),t([i()],V.prototype,"sensorPitchAngle",void 0),t([i()],V.prototype,"sensorRollAngle",void 0),t([i()],V.prototype,"sensorVerticalFieldOfView",void 0),t([i()],V.prototype,"vttMetadata",void 0),V=t([o("esri.layers.video.VideoCameraSensorModel")],V);export{V as default};