UNPKG

@arcgis/core

Version:

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

3 lines (2 loc) 3.08 kB
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */ import{__decorate as e}from"tslib";import t from"./Analysis.js";import n from"./Viewshed.js";import{equals as r}from"../core/arrayUtils.js";import i from"../core/Collection.js";import{referenceSetter as s,castForReferenceSetter as o}from"../core/collectionUtils.js";import{cyclicalDegrees as l}from"../core/Cyclical.js";import{deg2rad as a,clamp as u}from"../core/mathUtils.js";import{watch as p,syncAndInitial as c}from"../core/reactiveUtils.js";import{property as m,subclass as h}from"../core/accessorSupport/decorators.js";import d from"../geometry/Extent.js";import{projectOrLoadMany as f}from"../geometry/projectionUtils.js";const v=i.ofType(n);let y=class extends t{constructor(e){super(e),this.type="viewshed",this._extent=null}initialize(){this.addHandles(p(()=>this._computeExtent(),e=>{null==e.pending&&(this._extent=e.extent)},c))}get viewsheds(){return this._get("viewsheds")||new v}set viewsheds(e){this._set("viewsheds",s(e,this.viewsheds,v))}get spatialReference(){for(const e of this.viewsheds)if(null!=e.observer)return e.observer.spatialReference;return null}get extent(){return this._extent}get valid(){return this.viewsheds.every(e=>e.valid)}async waitComputeExtent(){const e=this._computeExtent();null!=e.pending&&await e.pending}_computeExtent(){const{spatialReference:e}=this;if(null==e)return{pending:null,extent:null};const t=this.viewsheds.filter(e=>null!=e.observer),n=t.map(e=>e.observer).toArray(),r=f(n,e);if(null!=r.pending)return{pending:r.pending,extent:null};return{pending:null,extent:r.geometries.map((e,n)=>{const r=t.at(n);return null!=e&&null!=r?this._computeViewshedExtent(this.viewsheds.at(n),e):null}).filter(e=>null!=e).reduce((e,t)=>x(e,t),null)}}_computeViewshedExtent(e,t){const{farDistance:n,heading:r,tilt:i,horizontalFieldOfView:s,verticalFieldOfView:o}=e,{spatialReference:p}=t,c=s/2,m=o/2,h=n/p.metersPerUnit,f=[l.normalize(r-c),r,l.normalize(r+c)],v=d.fromPoint(t),y=e=>{const t=f.map(t=>l.normalize(t-e));if(t[0]>t[2]||360===s)return h;const n=t.map(e=>Math.abs(e>180?360-e:e)).reduce((e,t)=>e>t?t:e);return n>90?0:h*Math.cos(a(n))};v.xmax+=y(90),v.xmin-=y(-90),v.ymax+=y(0),v.ymin-=y(180);const x=t.z;if(null!=x){let e=x,t=x;const r=i-90,s=u(r+m,-90,90),o=u(r-m,-90,90),l=p?.isGeographic?n:h;e+=l*g(s),t+=l*g(o);const a=w(m)*l,d=g(r)*a*(1-w(c));i<90&&(e-=d),i>90&&(t-=d),v.zmax=Math.max(e,x),v.zmin=Math.min(t,x)}return v}equals(e){return this===e||super.equals(e)&&r(this.viewsheds.toArray(),e.viewsheds.toArray(),(e,t)=>e.equals(t))}clear(){this.viewsheds.removeAll()}};function x(e,t){return null==e?t:null==t?e:e.union(t)}function w(e){return Math.cos(a(e))}function g(e){return Math.sin(a(e))}e([m({type:["viewshed"]})],y.prototype,"type",void 0),e([m({cast:o,type:v,nonNullable:!0})],y.prototype,"viewsheds",null),e([m({readOnly:!0})],y.prototype,"spatialReference",null),e([m()],y.prototype,"_extent",void 0),e([m()],y.prototype,"extent",null),e([m({readOnly:!0})],y.prototype,"valid",null),y=e([h("esri.analysis.ViewshedAnalysis")],y);export{y as default};