@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
3 lines (2 loc) • 10.1 kB
JavaScript
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */
import{__decorate as e}from"tslib";import{isSome as t,equals as i}from"../../../core/arrayUtils.js";import{createTask as s}from"../../../core/asyncUtils.js";import"../../../core/has.js";import{abortMaybe as r,destroyMaybe as n}from"../../../core/maybe.js";import{after as a,throwIfAborted as o}from"../../../core/promiseUtils.js";import{watch as l,syncAndInitial as u}from"../../../core/reactiveUtils.js";import{createScreenPointArray as c,createRenderScreenPointArray as d}from"../../../core/screenUtils.js";import{offsetDateUTC as p,convertTime as h}from"../../../core/timeUtils.js";import{property as m,subclass as g}from"../../../core/accessorSupport/decorators.js";import{create as _}from"../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{g as y}from"../../../chunks/boundedPlane.js";import f from"./AnalysisView3D.js";import{registerAnalysisView as v,hideOtherAnalysisViews as w}from"./ShadowCast/analysisViewRegister.js";import{ShadowCastTooltip as D}from"./ShadowCast/ShadowCastTooltip.js";import{longitudeToTimezone as C}from"../support/earthUtils.js";import{computeDirectionsOverTime as b}from"../support/sunUtils.js";import{breadthFirstBinaryPartitioning as U}from"../../../widgets/support/traversalUtils.js";let T=class extends f{constructor(e){super(e),this.type="shadow-cast-view-3d",this.analysis=null,this._stopPreviewingTask=null,this._updatedRecently=!1,this._tooltip=null}initialize(){this.addHandles([v(this.view,this),l(()=>({dependencies:this._previewDependencies,sceneUpdating:this._sceneUpdating}),()=>{r(this._stopPreviewingTask),this._updatedRecently=!0,this._stopPreviewingTask=s(async e=>{await a(j,e),o(e),this._updatedRecently=!1})},{sync:!0,initial:!0,equals:(e,t)=>x(e.dependencies,t.dependencies)&&(e.sceneUpdating===t.sceneUpdating||!e.sceneUpdating)}),l(()=>({renderer:this._renderer,visible:this.visible}),({renderer:e,visible:t})=>{t&&w(this.view,this),e?.setParameters({shadowCast:{enabled:t}})},u),l(()=>({renderer:this._renderer,parameters:this._visualizationParameters,visible:this.visible}),({renderer:e,parameters:t,visible:i})=>{O(e,i,t)},u),l(()=>({renderer:this._renderer,lightDirections:this._lightDirections,lightDirectionsContext:this._lightDirectionsContext,visible:this.visible}),({renderer:e,lightDirections:t,lightDirectionsContext:i,visible:s})=>{O(e,s,{lightDirections:t,lightDirectionsContext:i})},u),l(()=>({renderer:this._renderer,previewing:this._previewing,visible:this.visible}),({renderer:e,previewing:t,visible:i})=>{O(e,i,{previewing:t})},u)]),this.interactive=!0,this._tooltip=new D({getDuration:this.getDurationAtScreen.bind(this),isVisible:()=>this.interactive&&this.visible,view:this.view})}destroy(){this.visible&&O(this._renderer,!0,{enabled:!1}),this._tooltip=n(this._tooltip),this._stopPreviewingTask=r(this._stopPreviewingTask)}get interactive(){return super.interactive}set interactive(e){super.interactive=e}get updating(){return this._previewing||null!=this._stopPreviewingTask&&!this._stopPreviewingTask.finished||!0===this._tooltip?.updating}get visible(){return super.visible}set visible(e){super.visible=e}get _previewing(){return this._updatedRecently||this._sceneUpdating}get _sceneUpdating(){const{view:e}=this;if(null==e?.allLayerViews)return!0;const{stationary:t,graphicsView:i}=e;return!t||this._shadowLayerViews.some(e=>e.updating)||!i?.suspended&&!!i?.updating}get _effectiveUtcOffset(){return this.analysis.utcOffset??this._utcOffsetAuto}get _utcOffsetAuto(){const e=this._referencePosition;return null!=e?C(e[0],!1):0}get _dateUTCOffset(){let e=this.analysis.date;return e=p(e,-e.getTimezoneOffset(),"minutes"),e=p(e,-this._effectiveUtcOffset,"hours"),e}get _startDateTimeUTC(){return p(this._dateUTCOffset,this.analysis.startTimeOfDay)}get _endDateTimeUTC(){return p(this._dateUTCOffset,this.analysis.endTimeOfDay)}get _referencePosition(){return this.view?.environmentManager?.referencePositionGeographic}get _totalDurationInterval(){return this._totalDuration>0?Math.floor(this._totalDuration/(S-1)):S}get _interval(){const e=this._totalDurationInterval;switch(this.analysis.mode){case"min-duration":return this._totalDuration>0?e:0;case"total-duration":return e;case"discrete":return this.analysis.discreteOptions.interval||e}}get _intervalContext(){const{mode:e,minDurationOptions:t}=this.analysis;return"min-duration"===e&&t.contextEnabled?t.contextOptions.interval||this._totalDurationInterval:-1}get _totalDurationSampleCount(){return this._lightDirections.length}get _totalDuration(){const{startTimeOfDay:e,endTimeOfDay:t}=this.analysis;return t-e}get _lightDirections(){return this._calculateLightDirections(this._interval)}get _lightDirectionsContext(){return this._calculateLightDirections(this._intervalContext)}_calculateLightDirections(e){const{view:t}=this;if(e<=0)return[];const i="global"===t.viewingMode?A:this._referencePosition;if(null==i)return[];const s=b(this._startDateTimeUTC,this._endDateTimeUTC,e,i,t.state.viewingMode,S),r=s.length;L.length=0;const n=U(0,r,L),a=new Array(r);for(let o=0;o<r;++o)a[o]=s[n[o]];return a}get _visualizationParameters(){if(!this.visible)return null;switch(this.analysis.mode){case"min-duration":return this._minDurationVisualizationParameters;case"total-duration":return this._durationVisualizationParameters;case"discrete":return this._discreteVisualizationParameters}}get _minDurationVisualizationParameters(){const{minDuration:e,color:t}=this.analysis.minDurationOptions,i=this._totalDuration;return{visualization:2,thresholdColor:t.toUnitRGBA(),threshold:i>0?e/this._totalDuration:0,...this._minDurationContextVisualizationParameters}}get _minDurationContextVisualizationParameters(){const{minDurationOptions:e}=this.analysis;return e.contextEnabled?{visualization:3,gradientColor:e.contextOptions.color.toUnitRGBA()}:{}}get _durationVisualizationParameters(){const{color:e,mode:t}=this.analysis.totalDurationOptions,i=this._totalDuration,s=i>0&&"hourly"===t?z/i:0,r=e.toUnitRGBA();return 0===s?{...this._discreteVisualizationParameters,gradientColor:r}:{bandedGradientColor:r,visualization:1,bandSize:s}}get _discreteVisualizationParameters(){return{gradientColor:this.analysis.discreteOptions.color.toUnitRGBA(),visualization:0}}get _shadowLayerViews(){return this.view.allLayerViews.items.filter(V)}get _previewDependencies(){const{view:e}=this,i=e.slice.plane,s=this._shadowLayerViews,r=s.map(e=>e.layer).filter(t),n=s.map(e=>e.suspended),a=r.map(e=>e.visible),o=r.map(e=>e.opacity),l=!!e.graphicsView?.suspended,u=r.filter(e=>"definitionExpression"in e).map(e=>e.definitionExpression),c=s.filter(e=>"filter"in e).map(e=>e.filter);return{slicePlane:i,startDateUTC:this._startDateTimeUTC,endDateUTC:this._endDateTimeUTC,layerViewSuspended:n,graphicsViewSuspended:l,layerVisibilities:a,layerOpacities:o,filters:c,definitionExpressions:u}}get _renderer(){return this.view?.stage?.renderer}get testData(){}async getDurationAtScreen(e){const{_renderer:t,_totalDurationSampleCount:i}=this;if(null==t||0===i)return 0;const s=this.view.state.camera.screenToRender(c(e.x,e.y),d());return t.readAccumulatedShadow(s)*this._totalDuration}};e([m({readOnly:!0,type:["shadow-cast-view-3d"]})],T.prototype,"type",void 0),e([m({constructOnly:!0,nonNullable:!0})],T.prototype,"analysis",void 0),e([m({readOnly:!0})],T.prototype,"updating",null),e([m()],T.prototype,"_stopPreviewingTask",void 0),e([m()],T.prototype,"_updatedRecently",void 0),e([m()],T.prototype,"_tooltip",void 0),e([m()],T.prototype,"_sceneUpdating",null),e([m()],T.prototype,"_effectiveUtcOffset",null),e([m()],T.prototype,"_utcOffsetAuto",null),e([m()],T.prototype,"_dateUTCOffset",null),e([m()],T.prototype,"_startDateTimeUTC",null),e([m()],T.prototype,"_endDateTimeUTC",null),e([m()],T.prototype,"_referencePosition",null),e([m()],T.prototype,"_interval",null),e([m()],T.prototype,"_intervalContext",null),e([m()],T.prototype,"_totalDurationSampleCount",null),e([m()],T.prototype,"_totalDuration",null),e([m()],T.prototype,"_lightDirections",null),e([m()],T.prototype,"_lightDirectionsContext",null),e([m()],T.prototype,"_visualizationParameters",null),e([m()],T.prototype,"_minDurationVisualizationParameters",null),e([m()],T.prototype,"_minDurationContextVisualizationParameters",null),e([m()],T.prototype,"_durationVisualizationParameters",null),e([m()],T.prototype,"_discreteVisualizationParameters",null),e([m()],T.prototype,"_shadowLayerViews",null),e([m()],T.prototype,"_previewDependencies",null),e([m()],T.prototype,"_renderer",null),T=e([g("esri.views.3d.analysis.ShadowCastAnalysisView3D")],T);const P=T;function O(e,t,i){t&&null!=i&&e?.setParameters({shadowCast:i})}function V(e){if(e.suspended)return!1;switch(e.type){case"building-scene-3d":case"csv-3d":case"elevation-3d":case"feature-3d":case"geojson-3d":case"integrated-mesh-3d":case"integrated-mesh-3dtiles":case"ogc-feature-3d":case"route-3d":case"scene-layer-3d":case"scene-layer-graphics-3d":case"stream-3d":case"wms-3d":case"catalog-footprint-3d":return!0;case"base-dynamic-3d":case"catalog-3d":case"catalog-dynamic-group-3d":case"dimension-3d":case"gaussian-splat-3d":case"imagery-3d":case"imagery-tile-3d":case"line-of-sight-3d":case"map-image-3d":case"point-cloud-3d":case"tile-3d":case"vector-tile-3d":case"viewshed-3d":case"voxel-3d":case"wfs-3d":case"wmts-3d":case"media-3d":case"group":default:return!1;case"graphics-3d":return e.layer.graphics.some(e=>{const{symbol:t}=e;return null==t||"text"!==t.type&&!("symbolLayers"in t)||"text"!==t.type&&t.symbolLayers.some(e=>"text"!==e.type)})}}function x(e,t){if(e===t)return!0;if(null==e&&null==t)return!0;if(null==e||null==t)return!1;const s=y(e.slicePlane,t.slicePlane),r=e.startDateUTC.valueOf()===t.startDateUTC.valueOf()&&e.endDateUTC.valueOf()===t.endDateUTC.valueOf(),n=i(e.layerViewSuspended,t.layerViewSuspended)&&e.graphicsViewSuspended===t.graphicsViewSuspended,a=i(e.layerVisibilities,t.layerVisibilities),o=i(e.layerOpacities,t.layerOpacities),l=i(e.filters,t.filters),u=i(e.definitionExpressions,t.definitionExpressions);return s&&r&&n&&a&&o&&l&&u}const z=h(1,"hours","milliseconds"),j=500,S=255,A=_(),L=[];export{P as default};