UNPKG

@arcgis/core

Version:

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

3 lines (2 loc) 8.1 kB
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */ import e from"../../../../Graphic.js";import{isSome as t}from"../../../../core/arrayUtils.js";import{throwIfAborted as i,waitTick as a}from"../../../../core/promiseUtils.js";import o from"../../../../geometry/Mesh.js";import r from"../../../../geometry/Point.js";import{projectAsync as n}from"../../../../geometry/projectionUtils.js";import s from"../../../../geometry/support/MeshVertexAttributes.js";import{projectVertices as l,updateFrustum as c,createCoveragePolygon as p}from"../../../../layers/orientedImagery/core/coverageUtils.js";import{getMetersPerUnitOfSR as u}from"../../../../layers/orientedImagery/core/utils.js";import{fixedImageSize as m}from"../../constants.js";import{activeFrustumSymbol as d,additionalFrustumSymbol as f}from"../../symbols.js";class v{constructor(r){this.viewModel=r,this._updateBestFeatureFootprintElevation=!1,this._updatedElevationSampler=null,this.createFootprints=async a=>{const{coverageFrustums:r,currentBestFeature:c,isAdditionalCoverageVisible:p,view:u}=this.viewModel,m=r.filter(t);for(const t of m){let r=t.clone();if(!u.spatialReference.equals(r.spatialReference)){const{components:e,spatialReference:t,origin:c,vertexAttributes:p,vertexSpace:m}=r;if("local"===m.type){const e=await n(c,u.spatialReference,a);i(a),r.centerAt(e)}else{const n=p.position,c=Float64Array.from(await l([...n],t.clone(),u.spatialReference.clone(),a));i(a),r=new o({vertexAttributes:new s({position:c}),components:e,spatialReference:u.spatialReference.clone()})}}t.imageID===c.attributes.objectId?(this._updateBestFeatureFootprintElevation=!0,this.viewModel.bestFeatureFootprint=new e({attributes:{imageID:t.imageID},geometry:r,symbol:d.clone(),visible:!1})):this.viewModel.additionalFootprints.push(new e({attributes:{imageID:t.imageID},geometry:r,symbol:f.clone(),visible:p}))}},this.updateFootprint=async(a,o,r)=>{const{bestFeatureFootprint:s,currentBestFeature:l,activeViewer:p,footprintExtent:u,view:f,mode:v}=this.viewModel,y="video"===v?m:p?.imageSize,b=o??l;if(!(l&&s?.geometry&&y&&u&&b&&f?.spatialReference))return void this.viewModel.updateCurrentCoveragePolygon(null);const{attributes:{cameraHeight:F,location:R,cameraPitch:M,horizontalFieldOfView:S,verticalFieldOfView:E,cameraRoll:x},elevationSample:A}=b;let V=null;if(o&&(this._updatedElevationSampler=l.elevationSample,V=await h(o,f.spatialReference),this._updatedElevationSampler)){const e=this._updatedElevationSampler?.extent,t=o.attributes.geometry;if(e&&!e.contains(t)){const e=this.viewModel.selectedPoint;if(!e)return;e.x=o.geometry.x,e.y=o.geometry.y;const t=await this.viewModel.processFeatureElevation([o],e);t&&(this._updatedElevationSampler=t)}const[i]=g([V],this._updatedElevationSampler,o);i&&(V=i)}A&&this._updateBestFeatureFootprintElevation&&(this.updateGroundElevation([s]),this._updateBestFeatureFootprintElevation=!1);const P=R.toArray(),I=o&&V?V:s,{vertexAttributes:{position:_},spatialReference:j}=I.geometry,z=await w(_,j,R.spatialReference),C=await this.viewModel.getMapPoint(a);i(r);let O=C.filter(t);if(!O.length)return;O[0].spatialReference.equals(R.spatialReference)||(O=await Promise.all(O.map(async e=>{const t=await n(e,R.spatialReference,r);return i(r),t})));const B=await c(a.map(({x:e,y:t})=>[e,t]),O.map(e=>e.toArray()),{cameraHeight:F,cameraLocation:P,cameraPitch:M,frustumVertices:z,horizontalFieldOfView:S,imageHeight:y[1],imageWidth:y[0],inSRS:{wkid:R.spatialReference.wkid},outSRS:{wkid:f.spatialReference.wkid},verticalFieldOfView:E,cameraRoll:x??0,options:r});this.viewModel.updateCurrentCoveragePolygon(new e({attributes:{imageID:b.attributes.objectId},geometry:B,symbol:d.clone(),visible:this.viewModel.currentCoverageVisible}))},this.updateVideoFootprint=async a=>{const{points:o,feature:r,scale:s,options:l}=a,{bestFeatureFootprint:p,currentBestFeature:u,activeViewer:f,footprintExtent:v,view:b,mode:F}=this.viewModel,R="video"===F?m:f?.imageSize,M=r??u;if(!(u&&p?.geometry&&R&&v&&M&&b?.spatialReference&&"none"!==F))return void this.viewModel.updateCurrentCoveragePolygon(null);const{attributes:{cameraHeight:S,location:E,cameraPitch:x,horizontalFieldOfView:A,verticalFieldOfView:V,cameraRoll:P},elevationSample:I}=M;let _=null;if(r&&(this._updatedElevationSampler=u.elevationSample,_=await h(r,b.spatialReference),this._updatedElevationSampler)){const e=this._updatedElevationSampler?.extent,t=r.attributes.geometry;if(e&&!e.contains(t)){const e=this.viewModel.selectedPoint;if(!e)return;e.x=r.geometry.x,e.y=r.geometry.y;const t=await this.viewModel.processFeatureElevation([r],e);t&&(this._updatedElevationSampler=t)}const[i]=g([_],this._updatedElevationSampler,r);i&&(_=i)}I&&this._updateBestFeatureFootprintElevation&&(this.updateGroundElevation([p]),this._updateBestFeatureFootprintElevation=!1);const j=E.toArray(),z=r&&_?_:p,{vertexAttributes:{position:C},spatialReference:O}=z.geometry,B=await w(C,O,E.spatialReference),k={feature:M,mode:F,imageSize:R,footprintExtent:v},D=await this.viewModel.getMapPointForFeature(o,k,l);i(l);let H=D.filter(t);if(!H.length)return;H[0].spatialReference.equals(E.spatialReference)||(H=await Promise.all(H.map(async e=>{const t=await n(e,E.spatialReference,l);return i(l),t})));const q=await c(o.map(({x:e,y:t})=>[e,t]),H.map(e=>e.toArray()),{cameraHeight:S,cameraLocation:j,cameraPitch:x,frustumVertices:B,horizontalFieldOfView:A,imageHeight:R[1],imageWidth:R[0],inSRS:{wkid:E.spatialReference.wkid},outSRS:{wkid:b.spatialReference.wkid},verticalFieldOfView:V,cameraRoll:P??0,options:l});if(s&&q){const e=y(q);q.scale(s,{origin:e})}this.viewModel.updateCurrentCoveragePolygon(new e({attributes:{imageID:M.attributes.objectId},geometry:q,symbol:d.clone(),visible:this.viewModel.currentCoverageVisible}))},this.updateFootprintPanorama=async(t,i)=>{await a(i);const{horizontalFieldOfView:o,pitch:r,verticalFieldOfView:s,yaw:l,feature:c}=t,u=c?.clone()??this.viewModel.currentBestFeature?.clone();if(!u)return;const{attributes:m}=u;m.orientedImageryType=null,m.cameraHeading=l,m.cameraPitch=r,m.horizontalFieldOfView=o,m.verticalFieldOfView=s,m.cameraRoll=0;const{frustum:f}=p(m);if(!f)return void this.viewModel.updateCurrentCoveragePolygon(null);const v=this.viewModel.view?.spatialReference.equals(f.spatialReference)?f.clone():await n(f.clone(),this.viewModel.view?.spatialReference,i);this.viewModel.updateCurrentCoveragePolygon(new e({attributes:{imageID:m.objectId},geometry:v,symbol:d.clone(),visible:this.viewModel.currentCoverageVisible}))}}updateGroundElevation(e){const{geometry:t,attributes:{elevation:i}}=this.viewModel.currentBestFeature,a=(i??0)*u(t.spatialReference);e.forEach(e=>{const{geometry:t}=e;switch(t?.type){case"mesh":{const{vertexAttributes:{position:e}}=t,i=Math.floor(e.length/3);for(let o=0;o<i;o+=1)e[3*o+2]+=a/u(t.spatialReference);break}case"point":t.z=(t.z??0)+a/u(t.spatialReference)}})}}async function w(e,t,i,a){return Float64Array.from((await Promise.all(e.reduce((e,t,i)=>{const a=Math.floor(i/3);return e[a]=e[a]??[],e[a].push(t),e},new Array).map(async e=>(await n(new r(e,t),i,a)).toArray()))).flat())}const h=async(t,a,r)=>{const{frustum:c}=p(t.attributes);let u=c.clone();if(!a.equals(u.spatialReference)){const{components:e,spatialReference:t,origin:a,vertexAttributes:c,vertexSpace:p}=u;if("local"===p.type){const e=await n(a,t,r);i(r),u.centerAt(e)}else{const a=c.position,n=Float64Array.from(await l([...a],t.clone(),t.clone(),r));i(r),u=new o({vertexAttributes:new s({position:n}),components:e,spatialReference:t.clone()})}}return new e({attributes:{imageID:c.imageID},geometry:u,symbol:d.clone(),visible:!1})},g=(e,t,i)=>{const{geometry:a}=i,o=t.queryElevation(a);for(const r of e){const{geometry:e}=r;switch(e?.type){case"mesh":{const{vertexAttributes:{position:t}}=e,i=Math.floor(t.length/3);for(let e=0;e<i;e++)t[3*e+2]+=o?.z??0;break}case"point":e.z=(e.z??0)+(o?.z??0)}}return e},y=e=>{const t=e.vertexAttributes.position;let i=0,a=0,o=0;const n=t.length/3;for(let r=0;r<t.length;r+=3)i+=t[r],a+=t[r+1],o+=t[r+2];return new r({x:i/n,y:a/n,z:o/n,spatialReference:e.spatialReference})};export{v as default};