12345 |
- /*
- All material copyright ESRI, All Rights Reserved, unless otherwise specified.
- See https://js.arcgis.com/4.25/esri/copyright.txt for details.
- */
- import{_ as t}from"../../chunks/tslib.es6.js";import e from"../../Graphic.js";import i from"../../core/Accessor.js";import{min as r}from"../../core/arrayUtils.js";import{ByteSizeUnit as o}from"../../core/byteSizeEstimations.js";import s from"../../core/Collection.js";import{referenceSetter as l}from"../../core/collectionUtils.js";import n from"../../core/Handles.js";import a from"../../core/Logger.js";import p from"../../core/LRUCache.js";import{isNone as h,destroyMaybe as u,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{property as b}from"../../core/accessorSupport/decorators/property.js";import"../../core/accessorSupport/ensureType.js";import{subclass as U}from"../../core/accessorSupport/decorators/subclass.js";import{ElevationQueryTileCache as P}from"../../layers/support/ElevationQueryTileCache.js";import{defaultUnitPropertyMetadata as j}from"../../properties/defaultUnit.js";import{ElevationProfileController as E}from"./ElevationProfileController.js";import w from"./ElevationProfileLineGround.js";import{ElevationProfileLineCollection as C}from"./elevationProfileLineTypes.js";import{ElevationProfileTool as O}from"./ElevationProfileTool.js";import{ElevationProfileState as S,ElevationProfileErrorState as T}from"./support/constants.js";import{isPolyline as D,isValidInputPath as G}from"./support/geometryUtils.js";import{isProfileGenerationError as I,ProfileGenerationErrorCause as L}from"./support/ProfileGenerationError.js";import{createProfileQueue as k}from"./support/profileUtils.js";import{getBoundsInMeters as R,mergeStatistics as z}from"./support/statisticsUtils.js";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.defaultUnit=null,this.queue=null,this._currentTileCache=null,this.error=null,this._handles=new n,this._defaultProfileLineGround=new w,this._userUnitOptions=null,this._userUnit=null,t?.profiles||(this.profiles=new s([this._defaultProfileLineGround]))}initialize(){this._handles.add(m((()=>this.view),(t=>{h(t)?a.getLogger(this.declaredClass).warnOnce("no view. Widget will be disabled until a view is provided."):this.queue=k("3d"===t.type?t.resourceController?.scheduler:void 0)}),v)),this.tool=new O({viewModel:this}),this._controller=new E({viewModel:this})}destroy(){this._handles=u(this._handles),this._defaultProfileLineGround=u(this._defaultProfileLineGround),this._controller=u(this._controller),this._currentTileCache=u(this._currentTileCache),this.tool=u(this.tool),this.queue=u(this.queue)}get profiles(){return this._get("profiles")}set profiles(t){const e=this._get("profiles"),i=t??new s;this._set("profiles",l(i,e))}get state(){const t=this.view;return c(t)&&t.ready?this.tool.state:S.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=R(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 highlightEnabled(){return this.tool.highlightEnabled}set highlightEnabled(t){this.tool.highlightEnabled=t}get hasVertices(){const t=d(this.input,(t=>t.geometry));return D(t)&&t.paths.reduce(((t,e)=>t+e.length),0)>0}get hoveredPoints(){return!h(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(h(this.input))return null;const{effectiveUnits:t,progress:e,statistics:i,visibleProfiles:r,uniformChartScaling:o}=this,s=r.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:r.some((t=>"view"===t.type)),uniformScaling:o}}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 r(this.minDemResolutions)}get errorState(){const t=d(this.input,(t=>t.geometry));if(!G(t))return T.NoValidInput;if(c(this.error)){if(I(this.error))switch(this.error.cause){case L.TooComplex:return T.TooComplex;case L.InvalidGeometry:return T.InvalidGeometry;case L.InvalidElevationInfo:return T.InvalidElevationInfo;case L.ElevationQueryError:return T.NoValidInput}return T.UnknownError}return 0===this.visibleProfiles.length?T.NoVisibleProfiles:h(this.chartData)&&1===this.progress?T.RefinedButNoChartData:T.None}get tileCache(){this._currentTileCache=u(this._currentTileCache);const t=this.view;if(c(t)&&"3d"===t?.type){const e=t.basemapTerrain?.elevationQueryCache;if(c(e))return e}return h(this._currentTileCache)&&(this._currentTileCache=new P(new p(20*o.MEGABYTES))),this._currentTileCache}get visible(){return this.tool.visible}set visible(t){this.tool.visible=t}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:C,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([b()],N.prototype,"highlightEnabled",null),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(j)],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([b()],N.prototype,"visible",null),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([U("esri.widgets.ElevationProfile.ElevationProfileViewModel")],N);const V=N;export{V as default};
|