@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 12.4 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{createTask as e}from"../core/asyncUtils.js";import{abortMaybe as i,destroyMaybe as s}from"../core/maybe.js";import{memoize as n}from"../core/memoize.js";import{throwIfAborted as r,createAbortError as o}from"../core/promiseUtils.js";import{watch as a,initial as l}from"../core/reactiveUtils.js";import{property as c}from"../core/accessorSupport/decorators/property.js";import"../core/has.js";import"../core/Logger.js";import"../core/RandomLCG.js";import{subclass as h}from"../core/accessorSupport/decorators/subclass.js";import d from"./Widget.js";import{css as p}from"./ElevationProfile/css.js";import u from"./ElevationProfile/ElevationProfileViewModel.js";import m from"./ElevationProfile/ElevationProfileVisibleElements.js";import{Legend as _}from"./ElevationProfile/components/Legend.js";import{SettingsButton as C}from"./ElevationProfile/components/SettingsButton.js";import{ElevationProfileErrorState as v,ElevationProfileState as g,getConfig as f}from"./ElevationProfile/support/constants.js";import{loadCalciteComponents as y}from"./support/componentsUtils.js";import{globalCss as b}from"./support/globalCss.js";import"./support/widgetUtils.js";import{messageBundle as k}from"./support/decorators/messageBundle.js";import{tsx as w,tsxFragment as S}from"./support/jsxFactory.js";var M;!function(t){t.Sketch="sketch",t.SketchCancel="sketch-cancel",t.SketchDone="sketch-done",t.Select="select",t.SelectCancel="select-cancel"}(M||(M={}));const B=[{type:M.Select},{type:M.Sketch}],P={[v.None]:null,[v.NoValidInput]:"noProfile",[v.NoVisibleProfiles]:"noProfile",[v.RefinedButNoChartData]:"noProfile",[v.TooComplex]:"tooComplex",[v.UnknownError]:"unknown",[v.InvalidGeometry]:"invalidGeometry",[v.InvalidElevationInfo]:"invalidElevationInfo"};let E=class extends d{constructor(t,e){super(t,e),this.viewModel=null,this.visibleElements=new m,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=n(((t,e,i,s)=>({chart:t,data:e,stationary:i,messages:s}))),this._onZoomOutButtonClick=()=>{this._chart?.zoomOut()},this._onClearButtonClick=()=>{this.viewModel.clear()},t?.viewModel||(this._defaultViewModel=new u({view:t?.view}),this.viewModel=this._defaultViewModel)}loadDependencies(){return y({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([a((()=>({container:this._chartContainer})),(({container:t})=>{this._destroyChart(),null!=t&&this._initializeChart(t)}),l),a((()=>this._chartUpdateParams),(()=>this._updateChart(this._chartUpdateParams)),l)])}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 w("div",{"aria-label":this.messages.widgetLabel,class:this.classes({[p.base]:e,[b.widget]:e,[b.panel]:e,[b.widgetDisabled]:e&&"disabled"===t.state,[p.refined]:1===t.progress}),key:this},w("div",{bind:this,key:"content-wrapper"},e?this._renderContentForState():null))}_renderContentForState(){switch(this.viewModel.state){case g.Ready:return this._renderContentForReadyState();case g.Selecting:return this._renderContentForSelectingState();case g.Creating:return this._renderContentForCreatingState();case g.Selected:return this._renderContentForSelectedState();case g.Created:return this._renderContentForCreatedState();case g.Disabled:return this._renderContentForReadyState()}}_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:B})}_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:M.SelectCancel}]})}_renderContentForCreatingState(){const{view:t,viewModel:e}=this;if(null==t)return null;const i=e.hasVertices?[{type:M.SketchCancel},{type:M.SketchDone,disabled:!e.tool.interaction.canStopCreating}]:[{type:M.Select},{type:M.Sketch,disabled:!0}];if(e.errorState===v.NoValidInput){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:B,prompt:t}):this._renderContent({chart:!0,actions:B})}_renderContentForCreatedState(){const t=this._getErrorMessage();return t?this._renderContent({chart:!1,actions:B,prompt:t}):this._renderContent({chart:!0,actions:B})}_getErrorMessage(){const t=P[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 w(S,null,w("header",{class:p.header,key:"header"},this._zoomOutButtonVisible?this._renderZoomOutButton():null,this.visibleElements.clearButton&&s?this._renderClearButton():null,this.visibleElements.settingsButton?w(C,{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),w("div",{class:p.mainContainer,key:"main-container"},e),this.visibleElements.legend?w(_,{effectiveUnits:i.effectiveUnits,messages:this.messages,profiles:this._profilesArray}):null,this._renderActions(t))}_renderZoomOutButton(){const t=this.messages.zoomOut;return w("calcite-action",{appearance:"transparent",class:p.zoomOutButton,"data-testid":"zoom-out-button",icon:"magnifying-glass-minus",key:"zoom-out",onclick:this._onZoomOutButtonClick,scale:"s",text:t,title:t})}_renderClearButton(){const t=this.messages.clearProfile;return w("calcite-action",{appearance:"transparent",class:p.clearButton,"data-testid":"clear-button",icon:"trash",key:"clear-profile",onclick:this._onClearButtonClick,scale:"s",text:t,title:t})}_renderPrompt(t){return[w("div",{bind:this,class:p.promptContainer,key:"prompt-container"},w("p",null,t))]}_renderChart(){if(!this.visibleElements.chart)return w("div",{class:p.chartContainer,key:"empty-chart-container"});const{chartData:t,progress:e}=this.viewModel,i=this._chartIsRefined||this._canRenderChart(),s=null!=t&&e<1;return i?w(S,null,this._renderSpinner({size:i?"small":"large",visible:s}),w("div",{afterCreate:this._onChartContainerUpdate,afterRemoved:this._onChartContainerRemoved,afterUpdate:this._onChartContainerUpdate,bind:this,class:p.chartContainer,key:"chart-container"})):w(S,null,this._renderSpinner({size:"large",visible:s}),w("div",{class:p.chartContainer,key:"chart-container-empty"}))}_renderSpinner(t){const e="small"===t.size,i=t.visible??!0;return w("calcite-loader",{class:this.classes(p.chartSpinner,e&&p.chartSpinnerSmall,i&&p.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<=f().largeChartSamples}_renderActions({actions:t}){const e=t.map((t=>{switch(t.type){case M.Sketch:return this.visibleElements.sketchButton&&this._renderAction({action:t,className:p.sketchButton,label:this.messages.sketchButtonLabel,onClick:this._onSketchButtonClick,primary:!0});case M.SketchCancel:return this.visibleElements.sketchButton&&this._renderAction({action:t,onClick:this._onCancelButtonClick,className:p.sketchCancelButton,label:this.messagesCommon.cancel,primary:!1});case M.SketchDone:return this.visibleElements.sketchButton&&this._renderAction({action:t,onClick:this._onDoneButtonClick,className:p.sketchDoneButton,label:this.messagesCommon.done,primary:!0});case M.Select:return this._selectButtonVisible&&this._renderAction({action:t,onClick:this._onSelectButtonClick,className:p.selectButton,label:this.messages.selectButtonLabel,primary:!1});case M.SelectCancel:return this._selectButtonVisible&&this._renderAction({action:t,onClick:this._onCancelButtonClick,className:p.selectCancelButton,label:this.messagesCommon.cancel,primary:!1})}})).filter(Boolean);return e.length?w("footer",{class:p.footer,key:"footer"},e):null}_renderAction({action:t,className:e,label:i,onClick:s,primary:n}){return w("calcite-button",{appearance:n?"solid":"outline-fill",bind:this,class:this.classes(p.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){i(this._chartInitTask),this._chartInitTask=e((async e=>{const{createChart:i}=await import("./ElevationProfile/support/chartUtils.js");r(e);const n=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 s(n),o();this._chart=n,this._updateChart(this._chartUpdateParams)}))}_destroyChart(){this._chartInitTask=i(this._chartInitTask),this._chart=s(this._chart),this._chartIsRefined=!1}};t([c({type:u})],E.prototype,"viewModel",void 0),t([c()],E.prototype,"view",null),t([c()],E.prototype,"input",null),t([c()],E.prototype,"profiles",null),t([c()],E.prototype,"unitOptions",null),t([c()],E.prototype,"unit",null),t([c({type:m,nonNullable:!0})],E.prototype,"visibleElements",void 0),t([c()],E.prototype,"icon",null),t([c()],E.prototype,"label",null),t([c()],E.prototype,"visible",null),t([c(),k("esri/widgets/ElevationProfile/t9n/ElevationProfile")],E.prototype,"messages",void 0),t([c(),k("esri/t9n/common")],E.prototype,"messagesCommon",void 0),t([c(),k("esri/core/t9n/Units")],E.prototype,"messagesUnits",void 0),t([c()],E.prototype,"_chartContainer",void 0),t([c()],E.prototype,"_chart",void 0),t([c()],E.prototype,"_chartInitTask",void 0),t([c()],E.prototype,"_chartIsRefined",void 0),t([c()],E.prototype,"_zoomOutButtonVisible",void 0),t([c()],E.prototype,"_selectButtonVisible",null),t([c()],E.prototype,"_chartUpdateParams",null),t([c()],E.prototype,"_chartMessages",null),t([c()],E.prototype,"_profilesArray",null),E=t([h("esri.widgets.ElevationProfile")],E);const U=E;export{U as default};