// All material copyright Esri, All Rights Reserved, unless otherwise specified. // See https://js.arcgis.com/4.30/esri/copyright.txt for details. //>>built define("../../chunks/tslib.es6 ../../core/Accessor ../../core/handleUtils ../../core/Logger ../../core/maybe ../../core/reactiveUtils ../../core/scheduling ../../core/timeUtils ../../core/accessorSupport/decorators/property ../../core/has ../../core/RandomLCG ../../core/accessorSupport/decorators/subclass ../../views/SceneView ../../views/3d/environment/SunLighting ../../views/3d/environment/VirtualLighting ../../views/3d/support/earthUtils ./support/daylightUtils ./support/SliderWithDropdownViewModel ../support/timeWidgetUtils".split(" "), function(e,d,v,n,r,h,w,l,f,B,C,x,y,t,z,A,k,u,p){d=class extends d{constructor(a){super(a);this.view=null;this.timeSliderViewModel=new u.SliderWithDropdownViewModel({min:0,max:1439,values:[0],labelFormatFunction:p.formatSliderLabel,inputFormatFunction:p.formatSliderLabel});this.lightingUpdateInterval=200;this._oldLighting=null;this.playSpeedMultiplier=1;this._sunset=this._sunrise=this._lastTime=null;this._cachedLightingDateUTC=new Date(0);this._cachedDisplayUTCOffset=0;this._firstInteraction=!0;this._lastLightingUpdate= 0;this._lightingUpdateHandle=null}initialize(){this.addHandles([h.when(()=>this.view,a=>a.when(()=>this._updateLighting()),h.initial),h.watch(()=>{const a=this._lighting;return"sun"===a?.type?this._ensureValidDate(a):null},a=>this._scheduleLightingUpdate(a)),h.on(()=>this._lighting,"timezone-will-change",a=>this._timezoneWillChange(a),{onListenerAdd:()=>this._timezoneWillChange(null)}),h.watch(()=>!0===this.view?.stationary,()=>{(this.dayPlaying||this.yearPlaying)&&this._updateSunriseAndSunset()}, h.initial),h.watch(()=>{const a=this.timeSliderViewModel;return{vm:a,state:a.state,sliderPosition:this.timeSliderPosition}},({vm:a,state:b,sliderPosition:c})=>{"ready"===b&&a.setValue(0,c)}),h.watch(()=>this.timeSliderViewModel?.utcOffset,a=>{null!=a&&(this.utcOffset=a)}),h.watch(()=>({utcOffset:this.utcOffset,sliderViewModel:this.timeSliderViewModel}),({utcOffset:a,sliderViewModel:b})=>{b&&(b.utcOffset=a)},h.syncAndInitial),h.watch(()=>this.timeSliderViewModel.timezonePickerOpen,()=>this.stopPlaying()), h.watch(()=>this.timeSliderViewModel.values,a=>this._setTimeSliderPosition(a?.[0]??0,{forceLightingUpdate:!1}))])}destroy(){this._cancelLightingUpdate();this.view=null}get isSupported(){return null==this.view||"3d"===this.view.type}get utcOffset(){return this._cachedDisplayUTCOffset}set utcOffset(a){a!==this.utcOffset&&null!=this._lighting&&"virtual"!==this._lighting.type&&(this._lighting.displayUTCOffset=a,this._updateLighting())}get localDate(){return l.truncateLocalTime(this._lightingDateDisplay)}set localDate(a){this.view?.ready? l.isValidDate(a)&&a.getTime()!==this.localDate.getTime()&&(this._lightingDateDisplay=l.resetUTCDate(this._lightingDateDisplay,a)):n.getLogger(this).error("The localDate property cannot be set before the view and the widget are ready.")}get timeSliderPosition(){return k.dateTimeToSliderPos(this._lightingDateDisplay)}set timeSliderPosition(a){this.view?.ready&&"ready"===this.timeSliderViewModel?.state?this._setTimeSliderPosition(a,{forceLightingUpdate:!0}):n.getLogger(this).error("The timeSliderPosition property cannot be set before the view and the widget are ready.")}_setTimeSliderPosition(a, b){Math.abs(a-this.timeSliderPosition)<=1/60||(this.stopPlaying(),this._enableDirectShadowsIfFirstInteraction(),b.forceLightingUpdate&&(this._cancelLightingUpdate(),this._updateLighting()),this._lightingDateDisplay=k.sliderPosToDateTime(this._lightingDateDisplay,a))}_timezoneFromCamera(a,b){if(null==b||!a.cameraTrackingEnabled)return 0;a=A.positionToTimezoneInfo([b.longitude,b.latitude]);return null==a?0:Math.round(a.hours+a.minutes/60+a.seconds/3600)}get directShadowsEnabled(){return this._lighting?.directShadowsEnabled?? !1}set directShadowsEnabled(a){const b=this._lighting;b&&(b.directShadowsEnabled=a)}get sunLightingEnabled(){return"sun"===this._lightingType}set sunLightingEnabled(a){const b=this._environment;if(a!==this._get("sunLightingEnabled")&&null!=b){var c=b.lighting,g=this._oldLighting;this._oldLighting=c;c={directShadowsEnabled:c.directShadowsEnabled,cameraTrackingEnabled:c.cameraTrackingEnabled};g=null!=g&&g.type===(a?"sun":"virtual")?g:a?new t:new z;g.set(c);b.lighting=g;a||(this.stopPlaying(),this.timeSliderViewModel.timezonePickerOpen= !1)}}set playingState(a){this.playingState!==a&&(this._set("playingState",a),"none"!==a&&this.sunLightingEnabled&&(this._updateSunriseAndSunset(),this._lastTime=Date.now(),this._play(),this._enableDirectShadowsIfFirstInteraction()))}get dayPlaying(){return"day"===this.playingState}set dayPlaying(a){a?this.playingState="day":this.dayPlaying&&(this.playingState="none")}get yearPlaying(){return"year"===this.playingState}set yearPlaying(a){a?this.playingState="year":this.yearPlaying&&(this.playingState= "none")}get currentSeason(){return k.getSeasonFromDate(this.localDate,this._currentHemisphere)}set currentSeason(a){this.stopPlaying();a=k.getNorthernHemisphereSeason(a,this._currentHemisphere);this.localDate=k.getSeasonDate(this.localDate,a,k.Hemisphere.NORTHERN)}get _currentHemisphere(){const a=this.view?.camera?.position?.latitude;return null==a||0<=a?k.Hemisphere.NORTHERN:k.Hemisphere.SOUTHERN}get _environment(){return this.view?.environment}get _lighting(){return this._environment?.lighting}get _lightingType(){return this._lighting?.type}get _lightingDateDisplay(){return l.offsetDate(this._cachedLightingDateUTC, this._cachedDisplayUTCOffset,"hours")}set _lightingDateDisplay(a){const b=this._lighting;if(null!=b&&this.sunLightingEnabled&&"virtual"!==b.type&&l.isValidDate(a)){var c=this._ensureValidDate(b);a=l.offsetDate(a,-this._cachedDisplayUTCOffset,"hours");a.getTime()!==c.getTime()&&(b.date=a,this._updateLighting())}}stopPlaying(){this.playingState="none"}toggleDayPlaying(){this.dayPlaying=!this.dayPlaying}toggleYearPlaying(){this.yearPlaying=!this.yearPlaying}toggleSunLightingEnabled(){this.stopPlaying(); this.sunLightingEnabled=!this.sunLightingEnabled}toggleDirectShadowsEnabled(){this.stopPlaying();this.directShadowsEnabled=!this.directShadowsEnabled}onDateChange(a){this.dayPlaying=!1;this.localDate=a}_enableDirectShadowsIfFirstInteraction(){this._firstInteraction&&(this._firstInteraction=!1,this.directShadowsEnabled=!0)}_updateLighting(a){this._lastLightingUpdate=Date.now();var {view:b}=this;const c=this._lighting;if(null!=b&&null!=c&&"virtual"!==c.type){a??=this._ensureValidDate(c);var g=c.displayUTCOffset; b=null!==g?g:this._timezoneFromCamera(c,b.camera?.position);this._cachedLightingDateUTC.getTime()!==a.getTime()&&(this._cachedLightingDateUTC=new Date(a.getTime()));this._cachedDisplayUTCOffset!==b&&(this._cachedDisplayUTCOffset=b)}}_timezoneWillChange(a){const b=this._lighting;if(null!=b&&"virtual"!==b.type&&b.cameraTrackingEnabled){if(a)a=a.timezoneOffset;else{if(null!=b.displayUTCOffset)return;a=t.calculateTimezoneOffset(b.positionTimezoneInfo)}b.displayUTCOffset=a;this._scheduleLightingUpdate()}}_scheduleLightingUpdate(a){if(a&& (this._lightingUpdateHandle=r.removeMaybe(this._lightingUpdateHandle),!l.isValidDate(a)))return;if(!this._lightingUpdateHandle){var b=Date.now()-this._lastLightingUpdate;b=this.lightingUpdateInterval-b;var c=null,g=()=>{this._updateLighting(a);this._lightingUpdateHandle===c&&(this._lightingUpdateHandle=null)};if(0>=b)this._lightingUpdateHandle=c=w.schedule(g);else{const m=setTimeout(g,b);this._lightingUpdateHandle=c=v.makeHandle(()=>clearTimeout(m))}}}_cancelLightingUpdate(){this._lightingUpdateHandle= r.removeMaybe(this._lightingUpdateHandle)}_play(){const a=this._lighting;if(null!=a&&this.sunLightingEnabled&&"virtual"!==a.type){var b=this._ensureValidDate(a);if(this.dayPlaying||this.yearPlaying){var c=Date.now()-(this._lastTime??0);if(this.dayPlaying){if(this._lastTime=Date.now(),c*=k.calculatePlaySpeed(this._sunrise,this._sunset,b)*this.playSpeedMultiplier/100,0this._play())}}}_updateSunriseAndSunset(){var a=this._lighting;if(null!=a&&"virtual"!==a.type&&this.sunLightingEnabled){var b=this.view?.camera?.position;if(null!=b){var {latitude:c,longitude:g}=b,{date:m,displayUTCOffset:q}=a;if(a=p.getSunriseAndSunsetTimes(m,c,g,q??0))this._sunrise=new Date(a.sunrise),this._sunset= new Date(a.sunset)}}}_ensureValidDate(a){l.isValidDate(a.date)||(n.getLogger(this).warn("Invalid date. Reverting to the current date/time."),a.date=new Date);return a.date}};e.__decorate([f.property({type:y})],d.prototype,"view",void 0);e.__decorate([f.property({type:u.SliderWithDropdownViewModel,nonNullable:!0})],d.prototype,"timeSliderViewModel",void 0);e.__decorate([f.property()],d.prototype,"isSupported",null);e.__decorate([f.property()],d.prototype,"lightingUpdateInterval",void 0);e.__decorate([f.property()], d.prototype,"utcOffset",null);e.__decorate([f.property()],d.prototype,"localDate",null);e.__decorate([f.property()],d.prototype,"timeSliderPosition",null);e.__decorate([f.property()],d.prototype,"directShadowsEnabled",null);e.__decorate([f.property()],d.prototype,"sunLightingEnabled",null);e.__decorate([f.property({type:["none","day","year"],value:"none"})],d.prototype,"playingState",null);e.__decorate([f.property()],d.prototype,"dayPlaying",null);e.__decorate([f.property()],d.prototype,"yearPlaying", null);e.__decorate([f.property()],d.prototype,"playSpeedMultiplier",void 0);e.__decorate([f.property()],d.prototype,"currentSeason",null);e.__decorate([f.property()],d.prototype,"_lastTime",void 0);e.__decorate([f.property()],d.prototype,"_sunrise",void 0);e.__decorate([f.property()],d.prototype,"_sunset",void 0);e.__decorate([f.property()],d.prototype,"_cachedLightingDateUTC",void 0);e.__decorate([f.property()],d.prototype,"_cachedDisplayUTCOffset",void 0);e.__decorate([f.property()],d.prototype, "_firstInteraction",void 0);e.__decorate([f.property()],d.prototype,"_currentHemisphere",null);e.__decorate([f.property()],d.prototype,"_environment",null);e.__decorate([f.property()],d.prototype,"_lighting",null);e.__decorate([f.property()],d.prototype,"_lightingType",null);e.__decorate([f.property()],d.prototype,"_lightingDateDisplay",null);return d=e.__decorate([x.subclass("esri.widgets.Daylight.DaylightViewModel")],d)});