/* COPYRIGHT Esri - https://js.arcgis.com/5.1.0/LICENSE.txt */
import t from"../../Graphic.js";import r from"../../request.js";import o from"../../core/Collection.js";import e from"../../core/Error.js";import{rad2deg as n,deg2rad as s}from"../../core/mathUtils.js";import{throwIfAborted as i}from"../../core/promiseUtils.js";import a from"../../geometry/support/MeshMaterial.js";import m from"../../geometry/support/MeshTexture.js";import{createSphere as c}from"../../geometry/support/meshUtils.js";import l from"../../symbols/FillSymbol3DLayer.js";import u from"../../symbols/MeshSymbol3D.js";import{defaultImageSphereCenter as p,defaultImageSphereSize as f}from"./constants.js";import{loadRasterFactory as h,loadPanoramicTilePyramid as w}from"./support/importUtils.js";function y({data:t,center:r=p,size:o=f,horizonPitch:e=0,horizonYaw:n=0,horizonRoll:s=0}){const i=r.clone();i.z=-o/2;const l=c(i,{size:o,densificationFactor:2,vertexSpace:"georeferenced",material:new a({colorTexture:new m({data:t})})});if(l.components[0].trustSourceNormals=!0,l.vertexAttributes.uv){const t=l.vertexAttributes.uv.length??0;for(let r=0;r<t;r++)l.vertexAttributes.uv[2*r+0]=1-l.vertexAttributes.uv[2*r+0]}return l.rotate(e,s,n,{origin:l.extent.center}),l.centerAt(i),l}function j(r){return new t({geometry:r,symbol:new u({symbolLayers:new o([new l])})})}function d(t,r){return 2*n(Math.atan(Math.tan(s(t/2))*Math.sqrt((1/r)**2+1)))}async function g(t,r){const o=await h(),e=await o.open({url:t,ioConfig:{skipExtensions:["jgw","aux.xml"],skipMapInfo:!0},...r});return i(r),x(e,{url:t})}const x=(t,r)=>{if(!t)throw new e("panoramic-viewer:missing-raster","Raster data could not be loaded",r);return t};async function b(t,r,o){const e=await w();return i(o),new e({raster:t,horizonPitch:r.pitch,horizonYaw:r.yaw,horizonRoll:r.roll})}async function v(t,r){return t?.length?await Promise.all(t.map(t=>t.loadMesh(r))):[]}async function z(t,o){try{const e=await r(t,{...o,method:"head"});return i(o),e?.getHeader?.("Content-Type")}catch{return null}}export{y as createImageSphere,d as findDiagonalFOV,z as getContentType,v as loadMeshes,b as loadPyramid,g as loadRaster,j as meshToGraphic};
