UNPKG

@arcgis/core

Version:

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

3 lines (2 loc) • 12.1 kB
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.19/LICENSE.txt */ import{__decorate as t}from"tslib";import e from"../Graphic.js";import{createTask as i}from"../core/asyncUtils.js";import{deprecateWidget as s}from"../core/deprecate.js";import n from"../core/Logger.js";import{abortMaybe as r,destroyMaybe as o}from"../core/maybe.js";import{memoize as a}from"../core/memoize.js";import{throwIfAborted as l,createAbortError as c}from"../core/promiseUtils.js";import{watch as h,initial as d}from"../core/reactiveUtils.js";import{property as p,subclass as u}from"../core/accessorSupport/decorators.js";import m from"./Widget.js";import{css as _}from"./ElevationProfile/css.js";import{ElevationProfileLineCollection as v}from"./ElevationProfile/elevationProfileLineTypes.js";import C from"./ElevationProfile/ElevationProfileViewModel.js";import g from"./ElevationProfile/ElevationProfileVisibleElements.js";import{Legend as f}from"./ElevationProfile/components/Legend.js";import{SettingsButton as y}from"./ElevationProfile/components/SettingsButton.js";import{getConfig as b}from"./ElevationProfile/support/constants.js";import{loadCalciteComponents as w}from"./support/componentsUtils.js";import{globalCss as k}from"./support/globalCss.js";import{messageBundle as M,tsx as B,tsxFragment as S}from"./support/widget.js";const P=[{type:"select"},{type:"sketch"}],E={none:null,"no-valid-input":"noProfile","no-visible-profiles":"noProfile","refined-but-no-chart-data":"noProfile","too-complex":"tooComplex","unknown-error":"unknown","invalid-geometry":"invalidGeometry","invalid-elevation-info":"invalidElevationInfo"};let U=class extends m{constructor(t,e){super(t,e),this.viewModel=null,this.visibleElements=new g,this.messages=null,this.messagesCommon=null,this.messagesUnits=null,this._chartContainer=null,this._chart=null,this._chartInitTask=null,this._chartIsRefined=!1,this._zoomOutButtonVisible=!1,this._getChartUpdateParamsMemoized=a((t,e,i,s)=>({chart:t,data:e,stationary:i,messages:s})),this._onZoomOutButtonClick=()=>{this._chart?.zoomOut()},this._onClearButtonClick=()=>{this.viewModel.clear()},s(n.getLogger(this),"Elevation Profile","arcgis-elevation-profile",{version:"5.0"}),t?.viewModel||(this._defaultViewModel=new C({view:t?.view,suppressDeprecationWarning:!0}),this.viewModel=this._defaultViewModel)}loadDependencies(){return w({action:()=>import("@esri/calcite-components/dist/components/calcite-action"),button:()=>import("@esri/calcite-components/dist/components/calcite-button"),loader:()=>import("@esri/calcite-components/dist/components/calcite-loader")})}postInitialize(){this.addHandles([h(()=>({container:this._chartContainer}),({container:t})=>{this._destroyChart(),null!=t&&this._initializeChart(t)},d),h(()=>this._chartUpdateParams,()=>this._updateChart(this._chartUpdateParams),d)])}destroy(){this._destroyChart(),null!=this._defaultViewModel&&this.viewModel!==this._defaultViewModel&&this._defaultViewModel.destroy()}get view(){return this.viewModel.view}set view(t){this.viewModel.view=t}get input(){return this.viewModel.input}set input(t){this.viewModel.input=t}get profiles(){return this.viewModel.profiles}set profiles(t){this.viewModel.profiles=t}get unitOptions(){return this.viewModel.unitOptions}set unitOptions(t){this.viewModel.unitOptions=t}get unit(){return this.viewModel.unit}set unit(t){this.viewModel.unit=t}get icon(){return"altitude"}set icon(t){this._overrideIfSome("icon",t)}get label(){return this.messages?.widgetLabel??""}set label(t){this._overrideIfSome("label",t)}get visible(){return this.viewModel.visible}set visible(t){this.viewModel.visible=t}get test(){return{chart:this._chart}}get _selectButtonVisible(){return!0===this.visibleElements.selectButton&&this.viewModel.selectAvailable}get _chartUpdateParams(){const t=this.view;return this._getChartUpdateParamsMemoized(this._chart,this.viewModel.chartData,null==t||t.stationary,this._chartMessages)}get _chartMessages(){return{...this.messagesUnits,...this.messages}}get _profilesArray(){return this.profiles.toArray()}render(){const{viewModel:t,visible:e}=this;return B("div",{"aria-label":this.messages.widgetLabel,class:this.classes({[_.base]:e,[k.widget]:e,[k.panel]:e,[k.widgetDisabled]:e&&"disabled"===t.state,[_.refined]:1===t.progress}),key:this},B("div",{bind:this,key:"content-wrapper"},e?this._renderContentForState():null))}_renderContentForState(){switch(this.viewModel.state){case"ready":case"disabled":return this._renderContentForReadyState();case"selecting":return this._renderContentForSelectingState();case"creating":return this._renderContentForCreatingState();case"selected":return this._renderContentForSelectedState();case"created":return this._renderContentForCreatedState()}}_renderContentForReadyState(){const{messages:t,visibleElements:e,_selectButtonVisible:i}=this,{sketchButton:s}=e;let n;return n=s&&i?t.readyPrompt:s?t.readyPromptCreateOnly:i?t.readyPromptSelectOnly:t.errors?.noProfile,this._renderContent({prompt:n,chart:!1,actions:P})}_renderContentForSelectingState(){const{view:t}=this;if(null==t)return null;const e=this.messages[`selectingPrompt-${t.type}`];return this._renderContent({prompt:e,chart:!1,actions:[{type:"select-cancel"}]})}_renderContentForCreatingState(){const{view:t,viewModel:e}=this;if(null==t)return null;const i=e.hasVertices?[{type:"sketch-cancel"},{type:"sketch-done",disabled:!e.tool.interaction.canStopCreating}]:[{type:"select"},{type:"sketch",disabled:!0}];if("no-valid-input"===e.errorState){const e=this.messages[`creatingPrompt-${t.type}`];return this._renderContent({chart:!1,actions:i,prompt:e})}const s=this._getErrorMessage();return s?this._renderContent({chart:!1,actions:i,prompt:s}):this._renderContent({chart:!0,actions:i})}_renderContentForSelectedState(){const t=this._getErrorMessage();return t?this._renderContent({chart:!1,actions:P,prompt:t}):this._renderContent({chart:!0,actions:P})}_renderContentForCreatedState(){const t=this._getErrorMessage();return t?this._renderContent({chart:!1,actions:P,prompt:t}):this._renderContent({chart:!0,actions:P})}_getErrorMessage(){const t=E[this.viewModel.errorState];return t?this.messages?.errors?.[t]:null}_renderContent(t){const e=null!=t.prompt?this._renderPrompt(t.prompt):t.chart&&this._renderChart(),{viewModel:i}=this,s=null!=i.input;return B(S,null,B("header",{class:_.header,key:"header"},this._zoomOutButtonVisible?this._renderZoomOutButton():null,this.visibleElements.clearButton&&s?this._renderClearButton():null,this.visibleElements.settingsButton?B(y,{messages:this.messages,uniformChartScaling:i.uniformChartScaling,unit:i.unit,unitOptions:i.unitOptions,visibleElements:this.visibleElements,onUniformChartScalingChange:t=>i.uniformChartScaling=t,onUnitChange:t=>i.unit=t}):null),B("div",{class:_.mainContainer,key:"main-container"},e),this.visibleElements.legend?B(f,{effectiveUnits:i.effectiveUnits,messages:this.messages,profiles:this._profilesArray}):null,this._renderActions(t))}_renderZoomOutButton(){const t=this.messages.zoomOut;return B("calcite-action",{class:_.zoomOutButton,"data-testid":"zoom-out-button",icon:"magnifying-glass-minus",key:"zoom-out",onclick:this._onZoomOutButtonClick,text:t,title:t})}_renderClearButton(){const t=this.messages.clearProfile;return B("calcite-action",{class:_.clearButton,"data-testid":"clear-button",icon:"trash",key:"clear-profile",onclick:this._onClearButtonClick,text:t,title:t})}_renderPrompt(t){return[B("div",{bind:this,class:_.promptContainer,key:"prompt-container"},B("p",null,t))]}_renderChart(){if(!this.visibleElements.chart)return B("div",{class:_.chartContainer,key:"empty-chart-container"});const{chartData:t,progress:e}=this.viewModel,i=this._chartIsRefined||this._canRenderChart(),s=null!=t&&e<1;return i?B(S,null,this._renderSpinner({size:i?"small":"large",visible:s}),B("div",{afterCreate:this._onChartContainerUpdate,afterRemoved:this._onChartContainerRemoved,afterUpdate:this._onChartContainerUpdate,bind:this,class:_.chartContainer,key:"chart-container"})):B(S,null,this._renderSpinner({size:"large",visible:s}),B("div",{class:_.chartContainer,key:"chart-container-empty"}))}_renderSpinner(t){const e="small"===t.size,i=t.visible??!0;return B("calcite-loader",{class:this.classes(_.chartSpinner,e&&_.chartSpinnerSmall,i&&_.chartSpinnerVisible),"data-testid":"chart-spinner",inline:e,key:"spinner",label:"",scale:"s"})}_canRenderChart(){const t=this.viewModel.chartData;if(null==t)return!1;if(!this.viewModel.inputIsSketched)return t.refined;let e=0;for(const{samples:i}of t.lines)e+=null!=i?i.length:0;return t.refined||e<=b().largeChartSamples}_renderActions({actions:t}){const e=t.map(t=>{switch(t.type){case"sketch":return this.visibleElements.sketchButton&&this._renderAction({action:t,className:_.sketchButton,label:this.messages.sketchButtonLabel,onClick:this._onSketchButtonClick,primary:!0});case"sketch-cancel":return this.visibleElements.sketchButton&&this._renderAction({action:t,onClick:this._onCancelButtonClick,className:_.sketchCancelButton,label:this.messagesCommon.cancel,primary:!1});case"sketch-done":return this.visibleElements.sketchButton&&this._renderAction({action:t,onClick:this._onDoneButtonClick,className:_.sketchDoneButton,label:this.messagesCommon.done,primary:!0});case"select":return this._selectButtonVisible&&this._renderAction({action:t,onClick:this._onSelectButtonClick,className:_.selectButton,label:this.messages.selectButtonLabel,primary:!1});case"select-cancel":return this._selectButtonVisible&&this._renderAction({action:t,onClick:this._onCancelButtonClick,className:_.selectCancelButton,label:this.messagesCommon.cancel,primary:!1})}}).filter(Boolean);return e.length?B("footer",{class:_.footer,key:"footer"},e):null}_renderAction({action:t,className:e,label:i,onClick:s,primary:n}){return B("calcite-button",{appearance:n?"solid":"outline-fill",bind:this,class:this.classes(_.actionButton,e),disabled:t.disabled,key:`action-${t.type}`,onclick:s},i)}_onSketchButtonClick(){this.viewModel.start({mode:"sketch"})}_onSelectButtonClick(){this.viewModel.start({mode:"select"})}_onCancelButtonClick(){this.viewModel.cancel()}_onDoneButtonClick(){this.viewModel.stop()}_updateChart(t){const{data:e,chart:i,messages:s,stationary:n}=t;null!=i&&null!=s&&n&&this._canRenderChart()&&(i.update(t),this._chartIsRefined=null!=e&&e.refined)}_onChartContainerUpdate(t){this._chartContainer=t}_onChartContainerRemoved(t){this._chartContainer===t&&(this._chartContainer=null)}_initializeChart(t){r(this._chartInitTask),this._chartInitTask=i(async e=>{const{createChart:i}=await import("./ElevationProfile/support/chartUtils.js");l(e);const s=await i({container:t,abortOptions:{signal:e},onRangeChange:(t,e)=>{this._zoomOutButtonVisible=1!==t||1!==e},onCursorPositionChange:t=>{this.viewModel.hoveredChartPosition=t}});if(e.aborted)throw o(s),c();this._chart=s,this._updateChart(this._chartUpdateParams)})}_destroyChart(){this._chartInitTask=r(this._chartInitTask),this._chart=o(this._chart),this._chartIsRefined=!1}};t([p({type:C})],U.prototype,"viewModel",void 0),t([p()],U.prototype,"view",null),t([p({type:e})],U.prototype,"input",null),t([p({type:v})],U.prototype,"profiles",null),t([p()],U.prototype,"unitOptions",null),t([p()],U.prototype,"unit",null),t([p({type:g,nonNullable:!0})],U.prototype,"visibleElements",void 0),t([p()],U.prototype,"icon",null),t([p()],U.prototype,"label",null),t([p()],U.prototype,"visible",null),t([p(),M("esri/widgets/ElevationProfile/t9n/ElevationProfile")],U.prototype,"messages",void 0),t([p(),M("esri/t9n/common")],U.prototype,"messagesCommon",void 0),t([p(),M("esri/core/t9n/Units")],U.prototype,"messagesUnits",void 0),t([p()],U.prototype,"_chartContainer",void 0),t([p()],U.prototype,"_chart",void 0),t([p()],U.prototype,"_chartInitTask",void 0),t([p()],U.prototype,"_chartIsRefined",void 0),t([p()],U.prototype,"_zoomOutButtonVisible",void 0),t([p()],U.prototype,"_selectButtonVisible",null),t([p()],U.prototype,"_chartUpdateParams",null),t([p()],U.prototype,"_chartMessages",null),t([p()],U.prototype,"_profilesArray",null),U=t([u("esri.widgets.ElevationProfile")],U);const j=U;export{j as default};