@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 10 kB
JavaScript
/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.33/esri/copyright.txt for details.
*/
import{_ as t}from"../../chunks/tslib.es6.js";import e from"../../Color.js";import i from"../../core/Accessor.js";import{isSome as r}from"../../core/arrayUtils.js";import{createTask as s}from"../../core/asyncUtils.js";import"../../core/has.js";import{abortMaybe as o,destroyMaybe as n}from"../../core/maybe.js";import{after as a,throwIfAborted as l}from"../../core/promiseUtils.js";import{watch as u,syncAndInitial as p}from"../../core/reactiveUtils.js";import{createScreenPointArray as d,createRenderScreenPointArray as h}from"../../core/screenUtils.js";import{convertTime as c,offsetDateUTC as m}from"../../core/timeUtils.js";import{property as f}from"../../core/accessorSupport/decorators/property.js";import"../../core/Logger.js";import{subclass as _}from"../../core/accessorSupport/decorators/subclass.js";import{create as g}from"../../core/libs/gl-matrix-2/factories/vec3f64.js";import{longitudeToTimezone as y}from"../../views/3d/support/earthUtils.js";import{computeDirectionsOverTime as v}from"../../views/3d/support/sunUtils.js";import{ShadowCastVisualization as w}from"../../views/3d/webgl-engine/shaders/ShadowCastVisualizeTechniqueConfiguration.js";import D from"./DiscreteOptions.js";import{DurationMode as T}from"./DurationMode.js";import O from"./DurationOptions.js";import{ShadowCastState as P}from"./ShadowCastState.js";import{ShadowTooltipViewModel as C}from"./ShadowTooltipViewModel.js";import{ShadowVisualizationType as b}from"./ShadowVisualizationType.js";import z from"./ThresholdOptions.js";import{breadthFirstBinaryPartitioning as j}from"../support/traversalUtils.js";const U=[],V=g(),x=[],S=255,E=c(1,"hours","milliseconds"),R=500;let A=class extends i{constructor(t){super(t),this.view=null,this.tooltip=new C({getDuration:(t,e)=>this.getDuration(t,e)}),this.startTimeOfDay=c(10,"hours","milliseconds"),this.endTimeOfDay=c(16,"hours","milliseconds"),this.visualizationType=b.Threshold,this.thresholdOptions=new z,this.durationOptions=new O,this.discreteOptions=new D,this._running=!0,this._stopPreviewingTask=null,this._forcePreview=!1,this._autoRestoreForcePreviewEnabled=!0,this._utcOffset=null,this.date=new Date}initialize(){this.addHandles([u((()=>({view:this.view,tooltipEnabled:this._tooltipEnabled})),(({view:t,tooltipEnabled:e})=>{this.tooltip.view=t,this.tooltip.enabled=e}),p),u((()=>this._forcePreviewDependencies),(()=>{o(this._stopPreviewingTask),this._forcePreview=!0,this._autoRestoreForcePreviewEnabled&&(this._stopPreviewingTask=s((async t=>{await a(R,t),l(t),this._forcePreview=!1})))}),p),u((()=>({renderer:this.renderer,parameters:this._visualizationParameters})),(t=>N(t.renderer,t.parameters)),p),u((()=>({renderer:this.renderer,lightDirections:this._lightDirections,lightDirectionsContext:this._lightDirectionsContext})),(t=>N(t.renderer,{lightDirections:t.lightDirections,lightDirectionsContext:t.lightDirectionsContext})),p),u((()=>({renderer:this.renderer,parameters:{enabled:this._running}})),(t=>N(t.renderer,t.parameters)),p),u((()=>({renderer:this.renderer,parameters:{previewing:this._previewing}})),(t=>N(t.renderer,t.parameters)),p)])}destroy(){this.stop(),N(this.renderer,{enabled:!1}),n(this.tooltip)}get state(){return null!=this.view&&this.view.ready&&null!=this._referencePosition?P.Ready:P.Disabled}set date(t){const e=new Date(t);e.setHours(0,0,0,0),this._set("date",e)}get utcOffset(){return this._utcOffset??this._utcOffsetAuto}set utcOffset(t){this._utcOffset=t}get testData(){}get _previewing(){const{view:t}=this;if(null==t?.allLayerViews)return!0;const{stationary:e,allLayerViews:i,graphicsView:r}=t;return this._forcePreview||!e||i.some((t=>G(t)&&t.updating))||!r?.suspended&&!!r?.updating}get _utcOffsetAuto(){const t=this._referencePosition;return null!=t?y(t[0],!1):0}get _dateUTCOffset(){let t=this.date;return t=m(t,-t.getTimezoneOffset(),"minutes"),t=m(t,-this.utcOffset,"hours"),t}get _startDateTimeUTC(){return m(this._dateUTCOffset,this.startTimeOfDay)}get _endDateTimeUTC(){return m(this._dateUTCOffset,this.endTimeOfDay)}get _referencePosition(){return this.view?.environmentManager?.referencePositionGeographic}get _durationInterval(){return this._duration>0?Math.floor(this._duration/(S-1)):S}get _interval(){const t=this._durationInterval;switch(this.visualizationType){case b.Threshold:case b.Duration:return t;case b.Discrete:return this.discreteOptions.interval||t}}get _intervalContext(){const{contextEnabled:t,contextOptions:{interval:e}}=this.thresholdOptions;return this.visualizationType===b.Threshold&&t?e||this._durationInterval:-1}get _durationSampleCount(){return this._lightDirections.length}get _duration(){return this.endTimeOfDay-this.startTimeOfDay}get _lightDirections(){return this._calculateLightDirections(this._interval)}get _lightDirectionsContext(){return this._calculateLightDirections(this._intervalContext)}_calculateLightDirections(t){const{view:e}=this;if(null==e||t<=0)return U;const i="global"===e.viewingMode?V:this._referencePosition;if(null==i)return U;const r=v(this._startDateTimeUTC,this._endDateTimeUTC,t,i,e.state.viewingMode,S),s=r.length;x.length=0;const o=j(0,s,x),n=new Array(s);for(let a=0;a<s;++a)n[a]=r[o[a]];return n}get _tooltipEnabled(){return this.state===P.Ready&&this.visualizationType!==b.Discrete&&this._running&&!this._previewing}get _visualizationParameters(){if(!this._running)return null;switch(this.visualizationType){case b.Threshold:return this._thresholdVisualizationParameters;case b.Duration:return this._durationVisualizationParameters;case b.Discrete:return this._discreteVisualizationParameters}}get _thresholdVisualizationParameters(){const{value:t,color:i}=this.thresholdOptions,r=this._duration;return{visualization:w.Threshold,thresholdColor:e.toUnitRGBA(i),threshold:r>0?t/this._duration:0,...this._thresholdDiscreteVisualizationParameters}}get _thresholdDiscreteVisualizationParameters(){const{contextOptions:{color:t},contextEnabled:i}=this.thresholdOptions;return i?{visualization:w.ThresholdAndGradient,gradientColor:e.toUnitRGBA(t)}:{}}get _durationVisualizationParameters(){const{color:t,mode:i}=this.durationOptions,r=this._duration,s=r>0&&i===T.Hourly?E/r:0,o=e.toUnitRGBA(t);return 0===s?{...this._discreteVisualizationParameters,gradientColor:o}:{bandedGradientColor:o,visualization:w.BandedGradient,bandSize:s}}get _discreteVisualizationParameters(){return{gradientColor:e.toUnitRGBA(this.discreteOptions.color),visualization:w.Gradient}}get _forcePreviewDependencies(){const{view:t}=this;if(null==t)return null;const e=t.slice.plane,i=t.allLayerViews.toArray().filter(G),s=i.map((t=>t.layer)).filter(r),o=i.map((t=>t.suspended)),n=s.map((t=>t.visible)),a=s.map((t=>t.opacity)),l=!!t.graphicsView?.suspended,u=s.filter((t=>"definitionExpression"in t)).map((t=>t.definitionExpression)),p=i.filter((t=>"filter"in t)).map((t=>t.filter));return{slicePlane:e,startDateUTC:this._startDateTimeUTC,endDateUTC:this._endDateTimeUTC,layerViewSuspended:o,graphicsViewSuspended:l,layerVisibilities:n,layerOpacities:a,filters:p,definitionExpressions:u}}get renderer(){const{view:t}=this;if(null==t)return null;const e=t.stage;return null==e?null:e.renderer}start(){this.setRunning(!0)}stop(){this.setRunning(!1)}setRunning(t){this._running=t}async getDuration(t,e){const{view:i,renderer:r,_durationSampleCount:s}=this;if(null==i||null==r||0===s)return 0;const o=i.state.camera.screenToRender(d(t.x,t.y),h());return r.readAccumulatedShadow(o)*this._duration}};function N(t,e){null!=t&&null!=e&&t.setParameters({shadowCast:e})}function G(t){if(t.suspended)return!1;switch(t.type){case"building-scene-3d":case"csv-3d":case"elevation-3d":case"feature-3d":case"geojson-3d":case"graphics-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;default:return!1}}t([f()],A.prototype,"state",null),t([f()],A.prototype,"view",void 0),t([f()],A.prototype,"tooltip",void 0),t([f({type:Date,nonNullable:!0})],A.prototype,"date",null),t([f({type:Number,nonNullable:!0})],A.prototype,"utcOffset",null),t([f({type:Number,nonNullable:!0})],A.prototype,"startTimeOfDay",void 0),t([f({type:Number,nonNullable:!0})],A.prototype,"endTimeOfDay",void 0),t([f({type:["threshold","duration","discrete"],nonNullable:!0})],A.prototype,"visualizationType",void 0),t([f({type:z,nonNullable:!0})],A.prototype,"thresholdOptions",void 0),t([f({type:O,nonNullable:!0})],A.prototype,"durationOptions",void 0),t([f({type:D,nonNullable:!0})],A.prototype,"discreteOptions",void 0),t([f()],A.prototype,"_running",void 0),t([f()],A.prototype,"_stopPreviewingTask",void 0),t([f()],A.prototype,"_forcePreview",void 0),t([f()],A.prototype,"_autoRestoreForcePreviewEnabled",void 0),t([f()],A.prototype,"_previewing",null),t([f()],A.prototype,"_utcOffset",void 0),t([f()],A.prototype,"_utcOffsetAuto",null),t([f()],A.prototype,"_dateUTCOffset",null),t([f()],A.prototype,"_startDateTimeUTC",null),t([f()],A.prototype,"_endDateTimeUTC",null),t([f()],A.prototype,"_referencePosition",null),t([f()],A.prototype,"_interval",null),t([f()],A.prototype,"_intervalContext",null),t([f()],A.prototype,"_durationSampleCount",null),t([f()],A.prototype,"_duration",null),t([f()],A.prototype,"_lightDirections",null),t([f()],A.prototype,"_lightDirectionsContext",null),t([f()],A.prototype,"_tooltipEnabled",null),t([f()],A.prototype,"_visualizationParameters",null),t([f()],A.prototype,"_thresholdVisualizationParameters",null),t([f()],A.prototype,"_thresholdDiscreteVisualizationParameters",null),t([f()],A.prototype,"_durationVisualizationParameters",null),t([f()],A.prototype,"_discreteVisualizationParameters",null),t([f()],A.prototype,"_forcePreviewDependencies",null),t([f()],A.prototype,"renderer",null),A=t([_("esri.widgets.ShadowCast.ShadowCastViewModel")],A);const L=A;export{L as default};