UNPKG

@arcgis/core

Version:

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

3 lines (2 loc) • 11.2 kB
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */ import{__decorate as e}from"tslib";import t from"../../core/Accessor.js";import{isSome as i,equals as s}from"../../core/arrayUtils.js";import{createTask as r}from"../../core/asyncUtils.js";import{deprecateUnnecessaryViewModel as n}from"../../core/deprecate.js";import"../../core/has.js";import o from"../../core/Logger.js";import{abortMaybe as a,destroyMaybe as l}from"../../core/maybe.js";import{after as d,throwIfAborted as p}from"../../core/promiseUtils.js";import{watch as u,syncAndInitial as c}from"../../core/reactiveUtils.js";import{createScreenPointArray as h,createRenderScreenPointArray as m}from"../../core/screenUtils.js";import{convertTime as g,offsetDateUTC as y}from"../../core/timeUtils.js";import{property as f,subclass as _}from"../../core/accessorSupport/decorators.js";import{create as v}from"../../core/libs/gl-matrix-2/factories/vec3f64.js";import{g as w}from"../../chunks/boundedPlane.js";import{longitudeToTimezone as D}from"../../views/3d/support/earthUtils.js";import{computeDirectionsOverTime as T}from"../../views/3d/support/sunUtils.js";import O from"./DiscreteOptions.js";import b from"./DurationOptions.js";import{ShadowTooltipViewModel as C}from"./ShadowTooltipViewModel.js";import U from"./ThresholdOptions.js";import{breadthFirstBinaryPartitioning as P}from"../support/traversalUtils.js";const V=[],z=v(),x=[],j=255,R=g(1,"hours","milliseconds"),S=500;let E=class extends t{constructor(e){super(e),this.view=null,this.tooltip=new C({getDuration:e=>this.getDuration(e)}),this.startTimeOfDay=g(10,"hours","milliseconds"),this.endTimeOfDay=g(16,"hours","milliseconds"),this.visualizationType="threshold",this.thresholdOptions=new U({suppressDeprecationWarning:!0}),this.durationOptions=new b({suppressDeprecationWarning:!0}),this.discreteOptions=new O({suppressDeprecationWarning:!0}),this._running=!0,this._stopPreviewingTask=null,this._updatedRecently=!1,this._autoRestoreForcePreviewEnabled=!0,this._utcOffset=null,e?.suppressDeprecationWarning||n(o.getLogger(this),"Shadow Cast","arcgis-shadow-cast",{version:"5.0"}),this.date=new Date}normalizeCtorArgs(e){const{suppressDeprecationWarning:t,...i}=e??{};return i}initialize(){this.addHandles([u(()=>({view:this.view,tooltipEnabled:this._tooltipEnabled}),({view:e,tooltipEnabled:t})=>{this.tooltip.view=e,this.tooltip.enabled=t},c),u(()=>({dependencies:this._previewDependencies,sceneUpdating:this._sceneUpdating}),()=>{a(this._stopPreviewingTask),this._updatedRecently=!0,this._autoRestoreForcePreviewEnabled&&(this._stopPreviewingTask=r(async e=>{await d(S,e),p(e),this._updatedRecently=!1}))},{sync:!0,initial:!0,equals:(e,t)=>N(e.dependencies,t.dependencies)&&(e.sceneUpdating===t.sceneUpdating||!e.sceneUpdating)}),u(()=>({renderer:this.renderer,parameters:this._visualizationParameters}),e=>L(e.renderer,e.parameters),c),u(()=>({renderer:this.renderer,lightDirections:this._lightDirections,lightDirectionsContext:this._lightDirectionsContext}),e=>L(e.renderer,{lightDirections:e.lightDirections,lightDirectionsContext:e.lightDirectionsContext}),c),u(()=>({renderer:this.renderer,parameters:{enabled:this._running}}),e=>L(e.renderer,e.parameters),c),u(()=>({renderer:this.renderer,parameters:{previewing:this._previewing}}),e=>L(e.renderer,e.parameters),c)])}destroy(){this.stop(),L(this.renderer,{enabled:!1}),l(this.tooltip),this._stopPreviewingTask=a(this._stopPreviewingTask)}get state(){return null!=this.view&&this.view.ready&&null!=this._referencePosition?"ready":"disabled"}set date(e){const t=new Date(e);t.setHours(0,0,0,0),this._set("date",t)}get utcOffset(){return this._utcOffset??this._utcOffsetAuto}set utcOffset(e){this._utcOffset=e}get testData(){}get _previewing(){return this._updatedRecently||this._sceneUpdating}get _sceneUpdating(){const{view:e,_shadowLayerViews:t}=this;if(null==e?.allLayerViews)return!0;const{stationary:i,graphicsView:s}=e;return!i||t?.some(e=>e.updating)||!s?.suspended&&!!s?.updating}get _utcOffsetAuto(){const e=this._referencePosition;return null!=e?D(e[0],!1):0}get _dateUTCOffset(){let e=this.date;return e=y(e,-e.getTimezoneOffset(),"minutes"),e=y(e,-this.utcOffset,"hours"),e}get _startDateTimeUTC(){return y(this._dateUTCOffset,this.startTimeOfDay)}get _endDateTimeUTC(){return y(this._dateUTCOffset,this.endTimeOfDay)}get _referencePosition(){return this.view?.environmentManager?.referencePositionGeographic}get _durationInterval(){return this._duration>0?Math.floor(this._duration/(j-1)):j}get _interval(){const e=this._durationInterval;switch(this.visualizationType){case"threshold":case"duration":return e;case"discrete":return this.discreteOptions.interval||e}}get _intervalContext(){const{contextEnabled:e,contextOptions:{interval:t}}=this.thresholdOptions;return"threshold"===this.visualizationType&&e?t||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(e){const{view:t}=this;if(null==t||e<=0)return V;const i="global"===t.viewingMode?z:this._referencePosition;if(null==i)return V;const s=T(this._startDateTimeUTC,this._endDateTimeUTC,e,i,t.state.viewingMode,j),r=s.length;x.length=0;const n=P(0,r,x),o=new Array(r);for(let a=0;a<r;++a)o[a]=s[n[a]];return o}get _tooltipEnabled(){return"ready"===this.state&&"discrete"!==this.visualizationType&&this._running&&!this._previewing}get _visualizationParameters(){if(!this._running)return null;switch(this.visualizationType){case"threshold":return this._thresholdVisualizationParameters;case"duration":return this._durationVisualizationParameters;case"discrete":return this._discreteVisualizationParameters}}get _thresholdVisualizationParameters(){const{value:e,color:t}=this.thresholdOptions,i=this._duration;return{visualization:2,thresholdColor:t.toUnitRGBA(),threshold:i>0?e/this._duration:0,...this._thresholdDiscreteVisualizationParameters}}get _thresholdDiscreteVisualizationParameters(){const{contextOptions:{color:e},contextEnabled:t}=this.thresholdOptions;return t?{visualization:3,gradientColor:e.toUnitRGBA()}:{}}get _durationVisualizationParameters(){const{color:e,mode:t}=this.durationOptions,i=this._duration,s=i>0&&"hourly"===t?R/i:0,r=e.toUnitRGBA();return 0===s?{...this._discreteVisualizationParameters,gradientColor:r}:{bandedGradientColor:r,visualization:1,bandSize:s}}get _discreteVisualizationParameters(){return{gradientColor:this.discreteOptions.color.toUnitRGBA(),visualization:0}}get _shadowLayerViews(){return this.view?.allLayerViews.items.filter(A)}get _previewDependencies(){const{view:e,_shadowLayerViews:t}=this;if(null==e||null==t)return null;const s=e.slice.plane,r=t,n=r.map(e=>e.layer).filter(i),o=r.map(e=>e.suspended),a=n.map(e=>e.visible),l=n.map(e=>e.opacity),d=!!e.graphicsView?.suspended,p=n.filter(e=>"definitionExpression"in e).map(e=>e.definitionExpression),u=r.filter(e=>"filter"in e).map(e=>e.filter);return{slicePlane:s,startDateUTC:this._startDateTimeUTC,endDateUTC:this._endDateTimeUTC,layerViewSuspended:o,graphicsViewSuspended:d,layerVisibilities:a,layerOpacities:l,filters:u,definitionExpressions:p}}get renderer(){const{view:e}=this;if(null==e)return null;const t=e.stage;return null==t?null:t.renderer}start(){this.setRunning(!0)}stop(){this.setRunning(!1)}setRunning(e){this._running=e}async getDuration(e){const{view:t,renderer:i,_durationSampleCount:s}=this;if(null==t||null==i||0===s)return 0;const r=t.state.camera.screenToRender(h(e.x,e.y),m());return i.readAccumulatedShadow(r)*this._duration}};function L(e,t){null!=e&&null!=t&&e.setParameters({shadowCast:t})}function A(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 N(e,t){if(e===t)return!0;if(null==e&&null==t)return!0;if(null==e||null==t)return!1;const i=w(e.slicePlane,t.slicePlane),r=e.startDateUTC.valueOf()===t.startDateUTC.valueOf()&&e.endDateUTC.valueOf()===t.endDateUTC.valueOf(),n=s(e.layerViewSuspended,t.layerViewSuspended)&&e.graphicsViewSuspended===t.graphicsViewSuspended,o=s(e.layerVisibilities,t.layerVisibilities),a=s(e.layerOpacities,t.layerOpacities),l=s(e.filters,t.filters),d=s(e.definitionExpressions,t.definitionExpressions);return i&&r&&n&&o&&a&&l&&d}e([f()],E.prototype,"state",null),e([f()],E.prototype,"view",void 0),e([f()],E.prototype,"tooltip",void 0),e([f({type:Date,nonNullable:!0})],E.prototype,"date",null),e([f({type:Number,nonNullable:!0})],E.prototype,"utcOffset",null),e([f({type:Number,nonNullable:!0})],E.prototype,"startTimeOfDay",void 0),e([f({type:Number,nonNullable:!0})],E.prototype,"endTimeOfDay",void 0),e([f({type:["threshold","duration","discrete"],nonNullable:!0})],E.prototype,"visualizationType",void 0),e([f({type:U,nonNullable:!0})],E.prototype,"thresholdOptions",void 0),e([f({type:b,nonNullable:!0})],E.prototype,"durationOptions",void 0),e([f({type:O,nonNullable:!0})],E.prototype,"discreteOptions",void 0),e([f()],E.prototype,"_running",void 0),e([f()],E.prototype,"_stopPreviewingTask",void 0),e([f()],E.prototype,"_updatedRecently",void 0),e([f()],E.prototype,"_autoRestoreForcePreviewEnabled",void 0),e([f()],E.prototype,"_sceneUpdating",null),e([f()],E.prototype,"_utcOffset",void 0),e([f()],E.prototype,"_utcOffsetAuto",null),e([f()],E.prototype,"_dateUTCOffset",null),e([f()],E.prototype,"_startDateTimeUTC",null),e([f()],E.prototype,"_endDateTimeUTC",null),e([f()],E.prototype,"_referencePosition",null),e([f()],E.prototype,"_interval",null),e([f()],E.prototype,"_intervalContext",null),e([f()],E.prototype,"_durationSampleCount",null),e([f()],E.prototype,"_duration",null),e([f()],E.prototype,"_lightDirections",null),e([f()],E.prototype,"_lightDirectionsContext",null),e([f()],E.prototype,"_tooltipEnabled",null),e([f()],E.prototype,"_visualizationParameters",null),e([f()],E.prototype,"_thresholdVisualizationParameters",null),e([f()],E.prototype,"_thresholdDiscreteVisualizationParameters",null),e([f()],E.prototype,"_durationVisualizationParameters",null),e([f()],E.prototype,"_discreteVisualizationParameters",null),e([f()],E.prototype,"_shadowLayerViews",null),e([f()],E.prototype,"_previewDependencies",null),e([f()],E.prototype,"renderer",null),E=e([_("esri.widgets.ShadowCast.ShadowCastViewModel")],E);const k=E;export{k as default};