UNPKG

thematic-earth

Version:

HTML-based, whole-Earth thematic maps using locally hosted data layers

2 lines 1.24 kB
/* Copyright (c) 2023 Read Write Tools. Legal use subject to the Thematic Earth Software License Agreement. */ export default class Animation{constructor(s,t,e,i,h){this.name=s,this.earth=t,this.getCallback=e,this.setCallback=i,this.timeLapse=Number(h.timeLapse||0),this.increment=Number(h.increment||0),this.maxThreshold=h.maxThreshold||null,this.minThreshold=h.minThreshold||null,this.thresholdWrap=h.thresholdWrap??!1,this.mostRecentAnimation=0,this.isPaused=!0}setTimeLapse(s){s=Number(s),isNaN(s)&&(s=0),s<0&&(s=0),this.timeLapse=s,0==this.timeLapse?this.pause():this.resume(),this.earth.invalidateCanvas()}setIncrement(s){s=Number(s),isNaN(s)&&(s=0),this.increment=s,0==this.increment?this.pause():this.resume()}pause(){this.isPaused=!0}resume(){this.isPaused=!1}fire(s){if(1!=this.isPaused&&!(s-this.mostRecentAnimation<1e3*this.timeLapse)){var t=this.getCallback(),e=t+this.increment;null!=this.maxThreshold&&e>this.maxThreshold&&(1==this.thresholdWrap?e=this.minThreshold:(e=this.maxThreshold,this.isPaused=!0)),null!=this.minThreshold&&e<this.minThreshold&&(1==this.thresholdWrap?e=this.maxThreshold:(e=this.minThreshold,this.isPaused=!0)),this.setCallback(e),e!=t&&this.earth.invalidateCanvas(),this.mostRecentAnimation=s}}}