@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 1.94 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{makeHandle as s}from"../core/handleUtils.js";import has from"../core/has.js";import{getOrCreateMapValue as t}from"../core/MapUtils.js";import{Milliseconds as e,millisecondsFromSeconds as r,Seconds as o}from"../core/time.js";function i(s,t=s=>{},e){return new n(s,t,e)}class n{constructor(s,t=s=>{},e){if(this.onProgress=t,this.taskName=e,this._progressMap=new Map,this._startTime=void 0,this._timingsMap=new Map,"number"==typeof s){this._weights={};for(let t=0;t<s;t++){const e=t,r=1/s;this._weights[e]=r,this._progressMap.set(e,0)}}else this._weights=s;this.emitProgress()}emitProgress(){let s=0;for(const[t,e]of this._progressMap.entries()){s+=e*this._weights[t]}if(1===s&&has("enable-feature:esri-3dofl-upload-timings")){const s=Math.round(performance.now()-(this._startTime??0))/1e3;console.log(`${this.taskName} done in ${s} sec`);for(const[t,e]of this._timingsMap){const r=Math.round(e.end-e.start)/1e3,o=Math.round(r/s*100);console.log(this.taskName??"Task",{stepKey:t,stepTime:r,relativeTime:o})}}this.onProgress(s)}setProgress(s,e){if(this._progressMap.set(s,e),has("enable-feature:esri-3dofl-upload-timings")){const r=performance.now();this._startTime??=r;const o=t(this._timingsMap,s,(()=>({start:r,end:0})));1===e&&(o.end=r)}this.emitProgress()}simulate(s,t){return a((t=>this.setProgress(s,t)),t)}makeOnProgress(s){return t=>this.setProgress(s,t)}}function a(t=s=>{},e=l){const r=performance.now();t(0);const o=setInterval((()=>{const s=performance.now()-r,o=1-Math.exp(-s/e);t(o)}),g);return s((()=>{clearInterval(o),t(1)}))}function h(s,t=c){return r(o(s*f/t))}function m(s,t=p){return r(o(s*f/t))}const c=10,p=10,f=8e-6,g=e(50),l=e(1e3);export{n as ProgressManager,m as estimatedConversionTime,h as estimatedTransferTime,i as makeProgressManager,a as simulateProgress};