UNPKG

@arcgis/core

Version:

ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API

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