@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 3.9 kB
JavaScript
/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.32/esri/copyright.txt for details.
*/
import{isArrayLike as e}from"../../../core/arrayUtils.js";import{clone as r,zeros as a}from"../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{a as t}from"../../../chunks/vec32.js";import i from"../../../geometry/Point.js";import{fromPoints as o,fromValues as n}from"../../../geometry/support/ray.js";import{l as c,j as s}from"../../../chunks/sphere.js";import{isElevationSource as f}from"../core/ElevationSourceDefinitions.js";import{rectifyMapPoint as m,rectifyMapPointPanoramic as l}from"./rectifyMapPoint.js";import{or as p,isUpdateElevationWithElevationSource as y,isElevationSampler as u,scaleWithFactor as h,scaleAndAddWithFactor as d,computeNewReferenceCoordinates as g,projectiveTransform as w,validatePixelsToTransform as v,validateRotationMatrix as x,getWebMercatorScalingFactor as j,computeFarplaneVertices as A,computeHFOVAndVFOV as P,vecToPoint as R,hasAngles as V,convertPixelToHeadingPitch as F,convertHeadingPitchToSphereVertex as M,reducerFn as T}from"./utils.js";import{worldToImage as b}from"./worldToImage.js";import{defaultImageSphereCenter as L}from"../../../widgets/PanoramicViewer/constants.js";async function O(e,r,a){const{verticalFieldOfView:t,imageBoundaries:i,scalingFactor:o,farPlaneVertices:n,cameraLocation:c,pixelsToTransform:s,vecToPoint:f}=z(e,r),m=new Array;return await E(s,n,i,f,r,m,c,o,t,a),Array.isArray(e)?m:m[0]}async function E(e,r,a,t,i,o,n,c,s,f){let l=i.averageElevation;for(const h of e){const e=q(r,a,h,t,i);if(f&&p(u(f.elevationSample),y(f))){l=(await m(t(e),{x:h[0],y:h[1]},{...i,...f,farPlaneVertices:r.map(t)}))[2]}o.push(t(k(e,n,c,l,i.cameraPitch,s)))}}function k(e,i,o,n,c,s){let f=r(e);const m=Math.sqrt((e[2]-i[2])**2+(Math.sqrt((e[0]-i[0])**2+(e[1]-i[1])**2)/o)**2)*o,l=h(t(a(),e,i),1/m,1/o);if(S(e[2],n,c,s)){const e=Math.abs((i[2]-n)/-l[2])*o;f=d(i,l,e,o)}else f[2]=n;return f}function S(e,r,a,t){return e<r||a+t/2<90}function q(e,r,a,t,i){let o=null;const n=9;let c,s=0,f=e,m=r;for(;s<=n;){const e=D(a,m,f,i);if(c=e.error,o=e.transformedPoint,p(c<=1,s===n))break;f=g(f,c,a,r),m=B(f,t,i),s++}return o}function B(e,r,a){return b(e.map(r),a).map((({x:e,y:r})=>[e,r,1]))}function D(e,r,a,t){const{cameraLocation:o}=t,n=w(e,r,a),{x:c,y:s}=b(new i(n,o.spatialReference),t);return{transformedPoint:n,error:H(e,[c,s,1])}}function H(e,r){return Math.abs(e[0]-r[0])+Math.abs(e[1]-r[1])}function z(r,a){const t=e(r)||"items"in r?r:[r],{cameraLocation:o,rotationMatrix:n}=a;if(v(t,o),x(n),9!==n?.length)throw new Error("Rotation matrix is not provided or is not a valid 3x3 matrix");const c=j(o.y,o.spatialReference),s=A({...a,scalingFactor:c}),f=b(s.map((e=>new i(e,o.spatialReference))),a),{vfov:m}=P(a.horizontalFieldOfView,a.verticalFieldOfView,a.cameraRoll);return{cameraLocation:o.toArray(),imageBoundaries:f.map((({x:e,y:r})=>[e,r,1])),verticalFieldOfView:m,farPlaneVertices:s,scalingFactor:c,pixelsToTransform:t.map((e=>[e.x,e.y,1])),vecToPoint:R(o.spatialReference)}}async function I(e,r,t){const{cameraHeading:m,cameraLocation:p,farDistance:y,imageHeight:h,imageWidth:d,verticalFieldOfView:g}=r,w=j(p.y,p.spatialReference),v=new Array,[x,A,P]=p.toArray(),R=c([x,A,P??0],y*w),b=L.toArray(),O=Array.isArray(e)?e:[e];for(const c of O){let e,j;if(V(c))e=c.heading,j=c.pitch;else{const r=F({x:c.x,y:c.y},d,h);e=r.heading,j=r.pitch}e=(e+m)%360;const L=o([b[0],b[1],b[2]],M(e,j)),O=n([x,A,P??0],L.direction),E=a();s(R,O,E);let S=r.averageElevation;if(t&&(f(t)||u(t.elevationSample))&&j+g/2<90){S=(await l(new i(E,p.spatialReference),{heading:e,pitch:j},{...r,...t,farPlaneVertices:T(y,y).map((([e,r])=>new i([p.x+e,p.y+r],p.spatialReference)))}))[2]}v.push(new i(k(E,p.toArray(),w,S,j,g),p.spatialReference))}return Array.isArray(e)?v:v[0]}export{O as imageToWorld,I as imageToWorldPanoramic};