ElevationProfileController.js 4.5 KB

12345
  1. /*
  2. All material copyright ESRI, All Rights Reserved, unless otherwise specified.
  3. See https://js.arcgis.com/4.25/esri/copyright.txt for details.
  4. */
  5. import{_ as e}from"../../chunks/tslib.es6.js";import t from"../../core/Accessor.js";import{createTask as o}from"../../core/asyncUtils.js";import s from"../../core/Handles.js";import{handlesGroup as r}from"../../core/handleUtils.js";import{isSome as i,isNone as a,applySome as l,unwrapOr as n,abortMaybe as p}from"../../core/maybe.js";import{memoize as d}from"../../core/memoize.js";import{ignoreAbortErrors as m,throwIfAborted as h,throwIfAbortError as c}from"../../core/promiseUtils.js";import{watch as u,syncAndInitial as f}from"../../core/reactiveUtils.js";import{throttle as _}from"../../core/throttle.js";import{property as P}from"../../core/accessorSupport/decorators/property.js";import"../../core/arrayUtils.js";import"../../core/accessorSupport/ensureType.js";import{subclass as v}from"../../core/accessorSupport/decorators/subclass.js";import{hasGraphicFeatureExpressionInfo as g,getGraphicEffectiveElevationInfo as M}from"../../support/elevationInfoUtils.js";import{getConfig as y}from"./support/constants.js";import{isPolyline as w,isValidInputPath as j}from"./support/geometryUtils.js";import{generateProfiles as T}from"./support/profileUtils.js";const U="line-change";let b=class extends t{constructor(e){super(e),this._handles=new s,this._updateTask=null,this._paramsPerProfile=new Map,this._getUpdateParametersMemoized=d(((e,t,o)=>({stationary:e,visibleProfiles:t,generationParameters:o}))),this._getGenerationParametersMemoized=d(((e,t,o,s,r,i,l)=>w(t)&&j(t)&&!a(s)?{view:e,geometry:t,elevationInfo:o,options:i,queue:s,cache:r,slicePlane:l}:null)),this._getElevationInfoMemoized=d(((e,t)=>({mode:e,offset:t}))),this._getOptionsMemoized=d(((e,t,o)=>{const{densificationMaxSamples:s,maxTotalSamples:r}=y();return{geodesicDistanceThreshold:e,samplingDistance:t,densificationMaxSamples:Math.round(s/o),maxTotalSamples:r}})),this._updateThrottled=_((e=>m(this._update(e))),y().updateThrottleMillis)}initialize(){const e=this.viewModel;this._handles.add([u((()=>e.profiles.toArray()),(e=>{this._abortUpdate(),this._paramsPerProfile.clear(),this._handles.remove(U),this._handles.add(e.map((e=>r([e.attach(this.viewModel),e.on("change",(()=>{this._invalidateProfile(e)}))]))),U)}),f),this._updateThrottled,u((()=>this._updateParameters),this._updateThrottled,f)])}destroy(){this._handles.destroy(),this._paramsPerProfile.clear()}get _updateParameters(){const{viewModel:e}=this,t=e.view;return this._getUpdateParametersMemoized(!i(t)||t.stationary,this.viewModel.visibleProfiles,this._generationParameters)}get _generationParameters(){const{view:e,input:t,queue:o,tileCache:s}=this.viewModel;return a(e)||!e.ready?null:this._getGenerationParametersMemoized(e,l(t,(e=>e.geometry)),this._elevationInfo,o,s,this._options,"3d"===e.type?e.slicePlane:null)}get _elevationInfo(){const e=l(this.viewModel.input,(e=>g(e)?null:M(e)));return i(e)?this._getElevationInfoMemoized(e.mode,e.offset):null}get _options(){const e=this.viewModel,t=e.visibleProfiles.length;let o=n(e.minDemResolution,y().defaultDemResolution);return o=parseFloat(o.toFixed(2)),this._getOptionsMemoized(e.geodesicDistanceThreshold,o,t)}async _update({stationary:e,visibleProfiles:t,generationParameters:s}){this._abortUpdate(),e&&(a(s)?this._clearResults():this._updateTask=o((async e=>{this.viewModel.error=null;const o=t.filter((e=>!this._isProfileValid(e,s))),r=T({...s,providers:o},{signal:e});try{for await(const t of r){h(e),this._clearInvalidResults(s);for(let e=0;e<o.length;e++)o[e].result=t[e]}for(const e of o)this._paramsPerProfile.set(e,s)}catch(i){c(i),this._abortUpdate(),this.viewModel.error=i,o.forEach((e=>{e.result=null}))}})))}_abortUpdate(){this._updateTask=p(this._updateTask)}_isProfileValid(e,t){return this._paramsPerProfile.has(e)&&this._paramsPerProfile.get(e)===t}_invalidateProfile(e){this._paramsPerProfile.delete(e),this._updateThrottled(this._updateParameters)}_clearInvalidResults(e){for(const t of this.viewModel.profiles.items)this._isProfileValid(t,e)||(t.result=null,this._paramsPerProfile.delete(t))}_clearResults(){for(const e of this.viewModel.profiles.items)e.result=null,this._paramsPerProfile.delete(e)}};e([P({nonNullable:!0})],b.prototype,"viewModel",void 0),e([P()],b.prototype,"_updateParameters",null),e([P()],b.prototype,"_generationParameters",null),e([P()],b.prototype,"_elevationInfo",null),e([P()],b.prototype,"_options",null),b=e([v("esri.widgets.ElevationProfile.ElevationProfileController")],b);export{b as ElevationProfileController};