ElevationProfileViewModel.js 8.0 KB

12345
  1. /*
  2. All material copyright ESRI, All Rights Reserved, unless otherwise specified.
  3. See https://js.arcgis.com/4.24/esri/copyright.txt for details.
  4. */
  5. import{_ as t}from"../../chunks/tslib.es6.js";import e from"../../Graphic.js";import i from"../../core/Accessor.js";import{min as o}from"../../core/arrayUtils.js";import{ByteSizeUnit as r}from"../../core/byteSizeEstimations.js";import s from"../../core/Collection.js";import{referenceSetter as n}from"../../core/collectionUtils.js";import l from"../../core/Handles.js";import a from"../../core/Logger.js";import p from"../../core/LRUCache.js";import{isNone as u,destroyMaybe as h,isSome as c,applySome as d}from"../../core/maybe.js";import{memoize as f}from"../../core/memoize.js";import{watch as m,syncAndInitial as v}from"../../core/reactiveUtils.js";import{preferredLengthUnit as y,preferredVerticalLengthUnit as g,measurementLengthUnits as _}from"../../core/unitUtils.js";import{aliasOf as U}from"../../core/accessorSupport/decorators/aliasOf.js";import"../../core/has.js";import"../../core/accessorSupport/ensureType.js";import{property as b}from"../../core/accessorSupport/decorators/property.js";import{subclass as P}from"../../core/accessorSupport/decorators/subclass.js";import{ElevationQueryTileCache as j}from"../../layers/support/ElevationQueryTileCache.js";import{defaultUnitPropertyMetadata as w}from"../../properties/defaultUnit.js";import{ElevationProfileController as E}from"./ElevationProfileController.js";import C from"./ElevationProfileLineGround.js";import{ElevationProfileLineCollection as O}from"./elevationProfileLineTypes.js";import{ElevationProfileTool as S}from"./ElevationProfileTool.js";import{ElevationProfileState as T,ElevationProfileErrorState as D}from"./support/constants.js";import{isPolyline as G,isValidInputPath as I}from"./support/geometryUtils.js";import{isProfileGenerationError as L,ProfileGenerationErrorCause as k}from"./support/ProfileGenerationError.js";import{createProfileQueue as R}from"./support/profileUtils.js";import{getBoundsInMeters as V,mergeStatistics as z}from"./support/statisticsUtils.js";const M=a.getLogger("esri.widgets.ElevationProfile.ElevationProfileViewModel");let N=class extends i{constructor(t){super(t),this.view=null,this.input=null,this._getEffectiveUnitsMemoized=f(((t,e)=>({distance:t,elevation:e}))),this.geodesicDistanceThreshold=1e5,this.hoveredChartPosition=null,this.uniformChartScaling=!1,this.highlightEnabled=!0,this.defaultUnit=null,this.queue=null,this._currentTileCache=null,this.error=null,this._handles=new l,this._defaultProfileLineGround=new C,this._userUnitOptions=null,this._userUnit=null,t?.profiles||(this.profiles=new s([this._defaultProfileLineGround]))}initialize(){this._handles.add(m((()=>this.view),(t=>{u(t)?M.warnOnce("no view. Widget will be disabled until a view is provided."):this.queue=R("3d"===t.type?t.resourceController?.scheduler:void 0)}),v)),this.tool=new S({viewModel:this}),this._controller=new E({viewModel:this})}destroy(){this._handles=h(this._handles),this._defaultProfileLineGround=h(this._defaultProfileLineGround),this._controller=h(this._controller),this._currentTileCache=h(this._currentTileCache),this.tool=h(this.tool),this.queue=h(this.queue)}set profiles(t){const e=this._get("profiles"),i=t??new s;this._set("profiles",n(i,e))}get state(){const t=this.view;return c(t)&&t.ready?this.tool.state:T.Disabled}get progress(){let t=0,e=0;for(const i of this.visibleProfiles)t++,e+=i.progress;return t>0?e/t:0}set unitOptions(t){this._userUnitOptions=t,this._set("unitOptions",this._filteredOrAllUnits(this._userUnitOptions))}get unitOptions(){return this._filteredOrAllUnits(this._userUnitOptions)}set unit(t){this._userUnit=t?this._findSelectableUnit(t,this._userUnit):null,this.notifyChange("unit")}get unit(){return this._userUnit?(this._userUnit=this._findSelectableUnit(this._userUnit,this.defaultUnit),this._userUnit):this._findSelectableUnit(this.defaultUnit)}get effectiveUnits(){const t=V(this.visibleProfiles.map((t=>t.result))),e=y(t.maxDistance,"meters",this.unit),i=g(t.maxElevation,"meters",this.unit);return this._getEffectiveUnitsMemoized(e,i)}get hasVertices(){const t=d(this.input,(t=>t.geometry));return G(t)&&t.paths.reduce(((t,e)=>t+e.length),0)>0}get hoveredPoints(){return!u(this.input)&&this.visible&&this.tool.editable?this.visibleProfiles.map((t=>{const e=t.hoveredPoint;return c(e)?{hoveredPoint:e,color:t.color}:null})).filter(c):[]}get statistics(){return z(this.visibleProfiles.map((t=>t.statistics)))}get chartData(){if(u(this.input))return null;const{effectiveUnits:t,progress:e,statistics:i,visibleProfiles:o,uniformChartScaling:r}=this,s=o.filter((t=>t.hasZ)).map((t=>({id:t.id,type:t.type,title:t.title,color:t.color,samples:t.samples,progress:t.progress,chartFillEnabled:t.chartFillEnabled,chartStrokeWidth:t.chartStrokeWidth,chartStrokeOffsetY:t.chartStrokeOffsetY,viewVisualizationEnabled:t.viewVisualizationEnabled})));return 0===s.length?null:{lines:s,effectiveUnits:t,statistics:i,refined:1===e,dynamicElevationRange:o.some((t=>"view"===t.type)),uniformScaling:r}}get visibleProfiles(){return this.profiles.toArray().filter((t=>t.available&&t.visible))}get minDemResolutions(){const t=[];for(const{minDemResolution:e}of this.visibleProfiles)c(e)&&t.push(e);return t}get minDemResolution(){return o(this.minDemResolutions)}get errorState(){const t=d(this.input,(t=>t.geometry));if(!I(t))return D.NoValidInput;if(c(this.error)){if(L(this.error))switch(this.error.cause){case k.TooComplex:return D.TooComplex;case k.InvalidGeometry:return D.InvalidGeometry;case k.InvalidElevationInfo:return D.InvalidElevationInfo;case k.ElevationQueryError:return D.NoValidInput}return D.UnknownError}return 0===this.visibleProfiles.length?D.NoVisibleProfiles:u(this.chartData)&&1===this.progress?D.RefinedButNoChartData:D.None}get tileCache(){this._currentTileCache=h(this._currentTileCache);const t=this.view;if(c(t)&&"3d"===t?.type){const e=t.basemapTerrain?.elevationQueryCache;if(c(e))return e}return u(this._currentTileCache)&&(this._currentTileCache=new j(new p(20*r.MEGABYTES))),this._currentTileCache}get inputIsSketched(){return this.tool.interaction.isSketchedGraphic(this.input)}get elevationProvider(){const t=this.view;return c(t)&&"3d"===t.type?t.elevationProvider:null}start(t){this.tool.interaction.start(t)}stop(){this.tool.interaction.stop()}cancel(){this.tool.interaction.cancel()}clear(){this.tool.interaction.clear()}_findSelectableUnit(t,e){const i=this.unitOptions;return c(t)&&i.includes(t)?t:e?this._findSelectableUnit(e):i[0]}_filteredOrAllUnits(t){const e=(c(t)?t:[]).filter((t=>_.includes(t)));return 0===e.length?_.slice():e}};t([b()],N.prototype,"view",void 0),t([b({type:e})],N.prototype,"input",void 0),t([b({type:O,nonNullable:!0})],N.prototype,"profiles",null),t([b({readOnly:!0})],N.prototype,"state",null),t([b({readOnly:!0})],N.prototype,"progress",null),t([b()],N.prototype,"unitOptions",null),t([b()],N.prototype,"unit",null),t([b({readOnly:!0})],N.prototype,"effectiveUnits",null),t([b({type:Number})],N.prototype,"geodesicDistanceThreshold",void 0),t([b()],N.prototype,"hoveredChartPosition",void 0),t([b()],N.prototype,"uniformChartScaling",void 0),t([U("tool.highlightEnabled")],N.prototype,"highlightEnabled",void 0),t([b({readOnly:!0})],N.prototype,"hoveredPoints",null),t([b({readOnly:!0})],N.prototype,"statistics",null),t([b()],N.prototype,"chartData",null),t([b()],N.prototype,"visibleProfiles",null),t([b()],N.prototype,"minDemResolutions",null),t([b({readOnly:!0})],N.prototype,"minDemResolution",null),t([b({readOnly:!0})],N.prototype,"errorState",null),t([b(w)],N.prototype,"defaultUnit",void 0),t([b()],N.prototype,"queue",void 0),t([b()],N.prototype,"tileCache",null),t([b()],N.prototype,"tool",void 0),t([U("tool.visible")],N.prototype,"visible",void 0),t([b()],N.prototype,"error",void 0),t([b()],N.prototype,"inputIsSketched",null),t([b()],N.prototype,"elevationProvider",null),t([b()],N.prototype,"_defaultProfileLineGround",void 0),t([b()],N.prototype,"_userUnitOptions",void 0),t([b()],N.prototype,"_controller",void 0),t([b()],N.prototype,"_userUnit",void 0),N=t([P("esri.widgets.ElevationProfile.ElevationProfileViewModel")],N);const x=N;export{x as default};