@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 8.62 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{_ as t}from"../../chunks/tslib.es6.js";import e from"../../Graphic.js";import i from"../../core/Accessor.js";import{isSome as r,min as o}from"../../core/arrayUtils.js";import{ByteSizeUnit as s}from"../../core/ByteSizeUnit.js";import l from"../../core/Collection.js";import{referenceSetter as n}from"../../core/collectionUtils.js";import u from"../../core/Logger.js";import{LRUCache as a}from"../../core/LRUCache.js";import{destroyMaybe as p}from"../../core/maybe.js";import{memoize as h}from"../../core/memoize.js";import{watch as c,syncAndInitial as d}from"../../core/reactiveUtils.js";import{adaptiveLengthUnit as f,adaptiveVerticalLengthUnit as m,measurementLengthUnits as v}from"../../core/unitUtils.js";import{property as y}from"../../core/accessorSupport/decorators/property.js";import"../../core/has.js";import{subclass as g}from"../../core/accessorSupport/decorators/subclass.js";import{ElevationQueryTileCache as b}from"../../layers/support/ElevationQueryTileCache.js";import{defaultUnitPropertyMetadata as _}from"../../properties/defaultUnit.js";import{ElevationProfileController as U}from"./ElevationProfileController.js";import P from"./ElevationProfileLineGround.js";import{ElevationProfileLineCollection as j}from"./elevationProfileLineTypes.js";import{ElevationProfileTool as w}from"./ElevationProfileTool.js";import{ElevationProfileState as E,ElevationProfileErrorState as C}from"./support/constants.js";import{isPolyline as O,isValidInputPath as S}from"./support/geometryUtils.js";import{isProfileGenerationError as T,ProfileGenerationErrorCause as D}from"./support/ProfileGenerationError.js";import{createProfileQueue as G}from"./support/profileUtils.js";import{getBoundsInMeters as L,mergeStatistics as I}from"./support/statisticsUtils.js";let k=class extends i{constructor(t){super(t),this.view=null,this.input=null,this._getEffectiveUnitsMemoized=h(((t,e)=>({distance:t,elevation:e}))),this.hoveredChartPosition=null,this.uniformChartScaling=!1,this.defaultUnit=null,this.queue=null,this._currentTileCache=null,this.error=null,this._defaultProfileLineGround=new P,this._userUnitOptions=null,this._userUnit=null,t?.profiles||(this.profiles=new l([this._defaultProfileLineGround]))}initialize(){this.addHandles(c((()=>this.view),(t=>{if(null==t)return void u.getLogger(this).warnOnce("no view. Widget will be disabled until a view is provided.");this.removeHandles(R);const e="3d"===t.type?t.resourceController:void 0;this.queue?.destroy(),this.queue=G(e?.scheduler);const i=e?.addUpdatingObject(this);i&&this.addHandles(i,R)}),d)),this.tool=new w({viewModel:this}),this._controller=new U({viewModel:this})}destroy(){this._defaultProfileLineGround=p(this._defaultProfileLineGround),this._controller=p(this._controller),this._currentTileCache=p(this._currentTileCache),this.tool=p(this.tool),this.queue=p(this.queue)}get profiles(){return this._get("profiles")}set profiles(t){const e=this._get("profiles"),i=t??new l;this._set("profiles",n(i,e))}get state(){const t=this.view;return null!=t&&t.ready?this.tool.state:E.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=L(this.visibleProfiles.map((t=>t.result))),e=f(t.maxDistance,"meters",this.unit),i=m(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=this.input?.geometry;return O(t)&&t.paths.reduce(((t,e)=>t+e.length),0)>0}get hoveredPoints(){return null!=this.input&&this.visible&&this.tool.editable?this.visibleProfiles.map((t=>{const e=t.hoveredPoint;return null!=e?{hoveredPoint:e,color:t.color}:null})).filter(r):[]}get statistics(){return I(this.visibleProfiles.map((t=>t.statistics)))}get chartData(){if(null==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)null!=e&&t.push(e);return t}get minDemResolution(){return o(this.minDemResolutions)}get errorState(){const t=this.input?.geometry;if(!S(t))return C.NoValidInput;if(null!=this.error){if(T(this.error))switch(this.error.cause){case D.TooComplex:return C.TooComplex;case D.InvalidGeometry:return C.InvalidGeometry;case D.InvalidElevationInfo:return C.InvalidElevationInfo;case D.ElevationQueryError:return C.NoValidInput}return C.UnknownError}return 0===this.visibleProfiles.length?C.NoVisibleProfiles:null==this.chartData&&1===this.progress?C.RefinedButNoChartData:C.None}get tileCache(){this._currentTileCache=p(this._currentTileCache);const t=this.view;if(null!=t&&"3d"===t?.type){const e=t.basemapTerrain?.elevationQueryCache;if(null!=e)return e}return null==this._currentTileCache&&(this._currentTileCache=new b(new a(20*s.MEGABYTES))),this._currentTileCache}get visible(){return this.tool.visible}set visible(t){this.tool.visible=t}get selectAvailable(){for(const t of this.view?.map?.allLayers??[]){if("graphics"===t.type&&!t.internal&&t.graphics.some((t=>"polyline"===t.geometry?.type)))return!0;if("geometryType"in t&&"polyline"===t.geometryType)return!0}return!!this.view?.graphics?.some((t=>"polyline"===t.geometry?.type))}get inputIsSketched(){return this.tool.interaction.isSketchedGraphic(this.input)}get elevationProvider(){const t=this.view;return null!=t&&"3d"===t.type?t.elevationProvider:null}get updating(){const{progress:t}=this,e=!!this.queue?.updating;return t>0&&t<1||e}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 null!=t&&i.includes(t)?t:e?this._findSelectableUnit(e):i[0]}_filteredOrAllUnits(t){const e=(null!=t?t:[]).filter((t=>v.includes(t)));return 0===e.length?v.slice():e}};t([y()],k.prototype,"view",void 0),t([y({type:e})],k.prototype,"input",void 0),t([y({type:j,nonNullable:!0})],k.prototype,"profiles",null),t([y({readOnly:!0})],k.prototype,"state",null),t([y({readOnly:!0})],k.prototype,"progress",null),t([y()],k.prototype,"unitOptions",null),t([y()],k.prototype,"unit",null),t([y({readOnly:!0})],k.prototype,"effectiveUnits",null),t([y()],k.prototype,"hoveredChartPosition",void 0),t([y()],k.prototype,"uniformChartScaling",void 0),t([y()],k.prototype,"highlightEnabled",null),t([y({readOnly:!0})],k.prototype,"hoveredPoints",null),t([y({readOnly:!0})],k.prototype,"statistics",null),t([y()],k.prototype,"chartData",null),t([y()],k.prototype,"visibleProfiles",null),t([y()],k.prototype,"minDemResolutions",null),t([y({readOnly:!0})],k.prototype,"minDemResolution",null),t([y({readOnly:!0})],k.prototype,"errorState",null),t([y(_)],k.prototype,"defaultUnit",void 0),t([y()],k.prototype,"queue",void 0),t([y()],k.prototype,"tileCache",null),t([y()],k.prototype,"tool",void 0),t([y()],k.prototype,"visible",null),t([y()],k.prototype,"error",void 0),t([y()],k.prototype,"selectAvailable",null),t([y()],k.prototype,"inputIsSketched",null),t([y()],k.prototype,"elevationProvider",null),t([y()],k.prototype,"updating",null),t([y()],k.prototype,"_defaultProfileLineGround",void 0),t([y()],k.prototype,"_userUnitOptions",void 0),t([y()],k.prototype,"_controller",void 0),t([y()],k.prototype,"_userUnit",void 0),k=t([g("esri.widgets.ElevationProfile.ElevationProfileViewModel")],k);const R=Symbol("updating-object"),A=k;export{A as default};