You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
20 lines
8.2 KiB
20 lines
8.2 KiB
// All material copyright Esri, All Rights Reserved, unless otherwise specified. |
|
// See https://js.arcgis.com/4.30/esri/copyright.txt for details. |
|
//>>built |
|
define("require ../../chunks/tslib.es6 ../../TimeExtent ../../TimeInterval ../../core/Collection ../../core/deprecate ../../core/Evented ../../core/Logger ../../core/promiseUtils ../../core/reactiveUtils ../../core/timeUtils ../../core/accessorSupport/decorators/property ../../core/accessorSupport/ensureType ../../core/RandomLCG ../../core/has ../../core/accessorSupport/decorators/subclass ../../webdoc/Widgets ../../webdoc/widgets/TimeSlider".split(" "),function(B,g,l,C,w,D,e,x,y,p,E,h,z,I,J,F,G, |
|
H){function v(a){return null!=a&&void 0!==a.count}function u(a){return null!=a&&void 0!==a.interval}e=class extends e.EventedAccessor{constructor(a){super(a);this._animationController=null;this._isViewTimeExtentInitialized=!1;this._timerId=null;this.actions=new w;this.fullTimeExtent=null;this.loop=!1;this.mode="time-window";this.stops={count:10};this.view=this.timeExtent=null}initialize(){this.addHandles([p.watch(()=>this.effectiveStops,()=>{null==this.timeExtent&&(this.timeExtent=this._getDefaultTimeExtent())}, |
|
p.initial),p.watch(()=>this.view,(a,b)=>{this._unregisterWidget(b);this._registerWidget(a)},p.syncAndInitial),p.watch(()=>this.timeExtent,a=>{if(null!=this.view){var b=this.view.timeExtent;if(null!=a&&!a.isAllTime||null!=b&&!b.isAllTime)null!=a&&null!=b&&a.equals(b)||(this.view.timeExtent=a)}},p.initial),p.watch(()=>this.view?.timeExtent,a=>{if(!this._isViewTimeExtentInitialized)this._isViewTimeExtentInitialized=!0;else if(null!=a&&!a.isAllTime||null!=this.timeExtent&&!this.timeExtent.isAllTime)null!= |
|
a&&null!=this.timeExtent&&a.equals(this.timeExtent)||(this.timeExtent=a)})])}destroy(){null!=this._timerId&&(clearInterval(this._timerId),this._timerId=null);this._unregisterWidget(this.view);this.view=null;null!=this._animationController&&(this._animationController.abort(),this._animationController=null)}get effectiveStops(){const {fullTimeExtent:a,stops:b}=this;if(null!=b&&void 0!==b.dates){var {dates:d}=b;if(null==d||0===d.length)return null;d=d.sort((m,n)=>m.getTime()-n.getTime());if(null==a)return d; |
|
const {start:c,end:k}=a;return null==c||null==k?d:d.filter(m=>!(m.getTime()<c.getTime()||m.getTime()>k.getTime()))}return v(b)?this._divideTimeExtentByCount(b.timeExtent??a,b.count):u(b)?this._divideTimeExtentByInterval(b.timeExtent??a,b.interval):[]}set playRate(a){0>=a||36E5<a||("playing"===this.state&&this._startAnimation(),this._set("playRate",a))}get state(){return null==this.fullTimeExtent?"disabled":null!=this._animationController?"playing":"ready"}get timeExtentValues(){const {mode:a,timeExtent:b}= |
|
this;if(null==b||b.isAllTime||b.isEmpty)return null;const {start:d,end:c}=b;switch(a){case "cumulative-from-end":case "instant":return null!=d?[d.getTime()]:null;case "cumulative-from-start":return null!=c?[c.getTime()]:null;case "time-window":return null!=d&&null!=c?[d.getTime(),c.getTime()]:null}}static async getPropertiesFromWebMap(a,b){D.deprecatedFunction(x.getLogger("esri.widgets.TimeSlider.TimeSliderViewModel"),"`TimeSliderViewModel.getPropertiesFromWebMap` is deprecated in favor of 'timeUtils.getTimeSliderSettingsFromWebDocument'", |
|
{replacement:"timeUtils.getTimeSliderSettingsFromWebDocument",version:"4.29",see:"https://developers.arcgis.com/javascript/latest/api-reference/esri-support-timeUtils.html#getTimeSliderSettingsFromWebDocument",warnOnce:!0});const {getTimeSliderSettingsFromWebDocument:d}=await new Promise((c,k)=>B(["../../support/timeUtils"],c,k));return d(a,b)}next(){this._step({forward:!0,allowRestart:!1})}play(){this._startAnimation()}previous(){this._step({forward:!1,allowRestart:!1})}stop(){this._stopAnimation()}triggerAction(a){this.emit("trigger-action", |
|
{action:a})}updateWebDocument(a){var b=this.timeExtent,d=this.fullTimeExtent,c=this.loop,k=v(this.stops)?this.stops.count:null,m="time-window"===this.mode?2:1,n=this.playRate,t=u(this.stops)?this.stops.interval:null,f=this.stops;b=new H({currentTimeExtent:b,fullTimeExtent:d,loop:c,numStops:k,numThumbs:m,stopDelay:n,stopInterval:t,stops:null!=f&&void 0!==f.dates?this.stops.dates:null});a.widgets?a.widgets.timeSlider=b:a.widgets=new G({timeSlider:b})}valuesToTimeExtent(a){if(null==a)return null;var b= |
|
a.sort((d,c)=>d-c).map(d=>new Date(d));a=0<b.length?b[0]:null;b=1<b.length?b[1]:null;switch(this.mode){case "time-window":return new l({start:a,end:b});case "instant":return new l({start:a,end:a});case "cumulative-from-start":return new l({start:null,end:a});case "cumulative-from-end":return new l({start:a,end:null});default:return l.allTime}}async _animate(){try{const a=this.view,b=this._animationController?.signal;await Promise.all([y.after(this.playRate,null,b),null!=a&&p.whenOnce(()=>!1===a.updating, |
|
b)])}catch(a){y.isAbortError(a)||x.getLogger(this).error(a);this._animationController=null;return}this._step({forward:!0,allowRestart:!1});null!=this._animationController&&this._animate()}_divideTimeExtentByCount(a,b=10){if(!a||!b)return[];const {start:d,end:c}=a;if(null==d||null==c)return[];if(1E4<b)return this._divideTimeExtentByCount(a);a=[];const k=d.getTime(),m=c.getTime()-k;for(let n=0;n<=b;n++)a.push(new Date(k+n/b*m));return a}_divideTimeExtentByInterval(a,b,d=1E4){if(!a||!b)return[];const {start:c, |
|
end:k}=a;if(null==c||null==k)return[];const m=k.getTime()-c.getTime(),n=b.toMilliseconds();if(0>=n||m/n>d)return this._divideTimeExtentByCount(a);a=[];const {value:t,unit:f}=b;for(b=c;b.getTime()<=k.getTime();)a.push(new Date(b.getTime())),b=E.offsetDate(b,t,f);return a}_getDefaultTimeExtent(){const {effectiveStops:a,mode:b}=this;if(null==a||!b)return null;switch(b){case "time-window":return 1<a.length?new l({start:a[0],end:a[1]}):null;case "cumulative-from-start":return 0<a.length?new l({start:null, |
|
end:a[0]}):null;case "cumulative-from-end":return 0<a.length?new l({start:a[0],end:null}):null;case "instant":return 0<a.length?new l({start:a[0],end:a[0]}):null;default:return null}}_registerWidget(a){null!=a&&(a.persistableViewModels.includes(this)||a.persistableViewModels.add(this))}_startAnimation(){this._stopAnimation();this._animationController=new AbortController;this._step({forward:!0,allowRestart:!0});this._animate()}_step(a){const {forward:b,allowRestart:d}=a;({effectiveStops:a}=this);if(null!= |
|
this.timeExtentValues&&null!=a){var c=a.map(f=>f.getTime());a=this.timeExtentValues.map(f=>{var r=c.indexOf(f);if(-1!==r)return r;r=c.reduce((q,A)=>Math.abs(A-f)<Math.abs(q-f)?A:q);return c.indexOf(r)});var k=a.map(f=>f+=b?1:-1),m=k.some(f=>0>f||f>c.length-1),{loop:n,state:t}=this;if(m)if(n||d){const f=Math.min(...a),r=Math.max(...a);a=(b?a.map(q=>q-f):a.map(q=>q+(c.length-1-r))).map(q=>c[q]);this.timeExtent=this.valuesToTimeExtent(a)}else"playing"===t&&this.stop();else a=k.map(f=>c[f]),this.timeExtent= |
|
this.valuesToTimeExtent(a)}}_stopAnimation(){null!=this._animationController&&(this._animationController.abort(),this._animationController=null)}_unregisterWidget(a){null!=a&&a.persistableViewModels.remove(this)}};g.__decorate([h.property()],e.prototype,"_animationController",void 0);g.__decorate([h.property({type:w})],e.prototype,"actions",void 0);g.__decorate([h.property({readOnly:!0})],e.prototype,"effectiveStops",null);g.__decorate([h.property({type:l})],e.prototype,"fullTimeExtent",void 0);g.__decorate([h.property({nonNullable:!0})], |
|
e.prototype,"loop",void 0);g.__decorate([h.property({nonNullable:!0})],e.prototype,"mode",void 0);g.__decorate([h.property({nonNullable:!0,value:1E3})],e.prototype,"playRate",null);g.__decorate([h.property({readOnly:!0})],e.prototype,"state",null);g.__decorate([h.property({cast:a=>{if(null==a)return null;u(a)&&(a.interval=z.ensureType(C,a.interval));if(u(a)||v(a))a.timeExtent=z.ensureType(l,a.timeExtent);return a}})],e.prototype,"stops",void 0);g.__decorate([h.property({type:l})],e.prototype,"timeExtent", |
|
void 0);g.__decorate([h.property({readOnly:!0})],e.prototype,"timeExtentValues",null);g.__decorate([h.property()],e.prototype,"view",void 0);g.__decorate([h.property()],e.prototype,"next",null);g.__decorate([h.property()],e.prototype,"play",null);g.__decorate([h.property()],e.prototype,"previous",null);g.__decorate([h.property()],e.prototype,"stop",null);g.__decorate([h.property()],e.prototype,"updateWebDocument",null);return e=g.__decorate([F.subclass("esri.widgets.TimeSlider.TimeSliderViewModel")], |
|
e)}); |