@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
3 lines (2 loc) • 8.49 kB
JavaScript
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */
import{__decorate as t}from"tslib";import e from"../../Graphic.js";import i from"../../core/Accessor.js";import{isSome as r,min as o}from"../../core/arrayUtils.js";import s from"../../core/Collection.js";import{referenceSetter as l}from"../../core/collectionUtils.js";import{deprecateUnnecessaryViewModel as n}from"../../core/deprecate.js";import a from"../../core/Logger.js";import{LRUCache as u}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/units.js";import{property as g,subclass as y}from"../../core/accessorSupport/decorators.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 w}from"./elevationProfileLineTypes.js";import{ElevationProfileTool as j}from"./ElevationProfileTool.js";import{isPolyline as O,isValidInputPath as C}from"./support/geometryUtils.js";import{isProfileGenerationError as E}from"./support/ProfileGenerationError.js";import{createProfileQueue as S}from"./support/profileUtils.js";import{getBoundsInMeters as T,mergeStatistics as D}from"./support/statisticsUtils.js";let L=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({isDefaultLine:!0}),this._userUnitOptions=null,this._userUnit=null,t?.suppressDeprecationWarning||n(a.getLogger(this),"Elevation Profile","arcgis-elevation-profile",{version:"5.0"}),t?.profiles||(this.profiles=new s([this._defaultProfileLineGround]))}normalizeCtorArgs(t){const{suppressDeprecationWarning:e,...i}=t??{};return i}initialize(){this.addHandles(c(()=>this.view,t=>{if(null==t)return void a.getLogger(this).warnOnce("no view. Widget will be disabled until a view is provided.");this.removeHandles(G);const e="3d"===t.type?t.resourceController:void 0;this.queue?.destroy(),this.queue=S(e?.scheduler);const i=e?.addUpdatingObject(this);i&&this.addHandles(i,G)},d)),this.tool=new j({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 s;this._set("profiles",l(i,e))}get state(){const t=this.view;return null!=t&&t.ready?this.tool.state:"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=T(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 D(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(!C(t))return"no-valid-input";if(null!=this.error){if(E(this.error))switch(this.error.cause){case"too-complex":return"too-complex";case"invalid-geometry":return"invalid-geometry";case"invalid-elevation-info":return"invalid-elevation-info";case"elevation-query-error":return"no-valid-input"}return"unknown-error"}return 0===this.visibleProfiles.length?"no-visible-profiles":null==this.chartData&&1===this.progress?"refined-but-no-chart-data":"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 u(20971520))),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([g()],L.prototype,"view",void 0),t([g({type:e})],L.prototype,"input",void 0),t([g({type:w,nonNullable:!0})],L.prototype,"profiles",null),t([g({readOnly:!0})],L.prototype,"state",null),t([g({readOnly:!0})],L.prototype,"progress",null),t([g()],L.prototype,"unitOptions",null),t([g()],L.prototype,"unit",null),t([g({readOnly:!0})],L.prototype,"effectiveUnits",null),t([g()],L.prototype,"hoveredChartPosition",void 0),t([g()],L.prototype,"uniformChartScaling",void 0),t([g()],L.prototype,"highlightEnabled",null),t([g({readOnly:!0})],L.prototype,"hoveredPoints",null),t([g({readOnly:!0})],L.prototype,"statistics",null),t([g()],L.prototype,"chartData",null),t([g()],L.prototype,"visibleProfiles",null),t([g()],L.prototype,"minDemResolutions",null),t([g({readOnly:!0})],L.prototype,"minDemResolution",null),t([g({readOnly:!0})],L.prototype,"errorState",null),t([g(_)],L.prototype,"defaultUnit",void 0),t([g()],L.prototype,"queue",void 0),t([g()],L.prototype,"tileCache",null),t([g()],L.prototype,"tool",void 0),t([g()],L.prototype,"visible",null),t([g()],L.prototype,"error",void 0),t([g()],L.prototype,"selectAvailable",null),t([g()],L.prototype,"inputIsSketched",null),t([g()],L.prototype,"elevationProvider",null),t([g()],L.prototype,"updating",null),t([g()],L.prototype,"_defaultProfileLineGround",void 0),t([g()],L.prototype,"_userUnitOptions",void 0),t([g()],L.prototype,"_controller",void 0),t([g()],L.prototype,"_userUnit",void 0),L=t([y("esri.widgets.ElevationProfile.ElevationProfileViewModel")],L);const G=Symbol("updating-object"),k=L;export{k as default};