12345 |
- /*
- All material copyright ESRI, All Rights Reserved, unless otherwise specified.
- See https://js.arcgis.com/4.24/esri/copyright.txt for details.
- */
- import{_ as e}from"../chunks/tslib.es6.js";import"../intl.js";import{deprecatedProperty as t}from"../core/deprecate.js";import{on as s,pausable as i}from"../core/events.js";import o from"../core/Handles.js";import r from"../core/Logger.js";import{isNone as n,isSome as a,unwrap as l,unwrapOrValue as c}from"../core/maybe.js";import{watch as d,initial as h,when as u,on as p}from"../core/reactiveUtils.js";import{aliasOf as v}from"../core/accessorSupport/decorators/aliasOf.js";import"../core/arrayUtils.js";import"../core/has.js";import{cast as m}from"../core/accessorSupport/decorators/cast.js";import{property as _}from"../core/accessorSupport/decorators/property.js";import{subclass as g}from"../core/accessorSupport/decorators/subclass.js";import y from"../rest/support/Stop.js";import S from"../symbols/SimpleMarkerSymbol.js";import w from"./Search.js";import M from"./Widget.js";import b from"./Directions/DirectionsViewModel.js";import{SaveLayer as f}from"./Directions/components/SaveLayer.js";import{formatDistance as C,formatTime as T,isTimeUnits as k}from"./Directions/support/directionsUtils.js";import{DepartureTime as D,CSS as I,getIconPath as L}from"./Directions/support/resources.js";import{isArcGISWorldGeocoder as P,meteredArcGISLocatorUrl as R}from"./Search/support/locatorUtils.js";import B from"./support/DatePicker.js";import{Heading as A,incrementHeadingLevel as j}from"./support/Heading.js";import x from"./support/TimePicker.js";import{accessibleHandler as E}from"./support/decorators/accessibleHandler.js";import{messageBundle as H}from"./support/decorators/messageBundle.js";import{tsx as U}from"./support/jsxFactory.js";import"./support/widgetUtils.js";import O from"sortablejs";import{substitute as z}from"../intl/substitute.js";import{formatDate as $,convertDateFormatToIntlOptions as F}from"../intl/date.js";import{formatNumber as N}from"../intl/number.js";const V={departureTime:!0,layerDetails:!0,printButton:!1,saveAsButton:!0,saveButton:!0,stops:!0,traveMode:!0};function W(e){const t=e.getTimezoneOffset(),s=t>0?"-":"+",i=60,o=Math.abs(Math.floor(t/i)),r=Math.abs(Math.floor(t)%i),n={minimumIntegerDigits:2};return`GMT${s}${N(o,n)}${N(r,n)}`}function q(e){return!!e.composedPath?.().find((e=>e.classList?.contains("esri-search__suggestions-list")))}const K={awaitingViewClickStop:"awaiting-view-click-stop"},Y=100,G=500,J=r.getLogger("esri.widgets.Directions");let Q=class extends M{constructor(e,t){super(e,t),this._autoStopRemovalDelay=Y,this._departureTime=D.NOW,this._datePicker=new B,this._handles=new o,this._newPlaceholderStop=null,this._pointerPressedSearchSuggestionStop=null,this._renderSavePopoverFunction=null,this._saveAsButtonNode=null,this._saveLayer=new f,this._sections=null,this._stopsToSearches=new Map,this._timePicker=new x,this.apiKey=null,this.goToOverride=null,this.headingLevel=2,this.iconClass=I.widgetIcon,this.label=void 0,this.lastRoute=null,this.layer=null,this.maxStops=null,this.messages=null,this.messagesCommon=null,this.messagesUnits=null,this.searchProperties=null,this.view=null,this.viewModel=new b,this.visibleElements={...V},this._setUpDragAndDropStops=e=>{this._sortable=O.create(e,{draggable:`.${I.validStopRow}`,ghostClass:I.stopRowGhost,handle:`.${I.stopHandle}`,onEnd:this._handleStopInputDragEnd})},this._handleDragHandlePointerDown=()=>this.viewModel.layer.stops.forEach((e=>this._acquireSearch(e).activeMenu="none")),this._handleStopInputDragEnd=({oldIndex:e,newIndex:t,target:s})=>{if(e===t)return;const{children:i}=s,o=i[t],r=i[e],n=t-e<0;s.insertBefore(o,n?r.nextElementSibling:r);const a=this.viewModel.layer.stops;a.reorder(a.getItemAt(e),t);for(const l of a)l.sequence=null;this._getDirections()}}initialize(){this.own([d((()=>this.viewModel.layer.routeInfo),(()=>{this._activeManeuver=null,this._focusedManeuver=null,this._sections=this._getSections(),this.scheduleRender()}),h),u((()=>this.view),((e,t)=>{if(t&&(this._viewClickHandle=null,this._handles.remove(t)),e){const t=this._prepPointerDownUpClick(),i=this._prepViewClick();t.pause(),i.pause(),this._handles.add([s(e.surface,"mousedown",(()=>this._autoStopRemovalDelay=G)),s(e.surface,"mouseup",(()=>this._autoStopRemovalDelay=Y)),t,i],this.view.surface),this._pointerDownUpHandle=t,this._viewClickHandle=i}}),h),u((()=>n(this.viewModel.serviceDescription)),(()=>{try{this.viewModel.load()}catch{}}),h),d((()=>this._saveLayer.state),(()=>{this.scheduleRender()}))]),this.when((()=>{this.destroyed||(this._renderSavePopoverFunction=this._renderSavePopover.bind(this),this._projector.append(document.body,this._renderSavePopoverFunction))}))}loadDependencies(){return Promise.all([import("@esri/calcite-components/dist/components/calcite-button.js"),import("@esri/calcite-components/dist/components/calcite-link.js"),import("@esri/calcite-components/dist/components/calcite-popover.js")])}destroy(){this._datePicker.destroy(),this._timePicker.destroy();for(const e of this._stopsToSearches.values())e.destroy();this._sortable&&this._sortable.destroy(),a(this._renderSavePopoverFunction)&&this._projector.detach(this._renderSavePopoverFunction)}set routeServiceUrl(e){t(J,"routeServiceUrl",{replacement:"viewModel.layer.url",version:"4.24",warnOnce:!0}),this.viewModel.legacyLayer.url=e}get routeServiceUrl(){return t(J,"routeServiceUrl",{replacement:"viewModel.layer.url",version:"4.24",warnOnce:!0}),this.viewModel.legacyLayer.url}set routeSymbol(e){t(J,"routeSymbol",{replacement:"viewModel.layer.defaultSymbols.directionLines",version:"4.24",warnOnce:!0}),this.viewModel.legacyLayer.defaultSymbols.directionLines=e}get routeSymbol(){return t(J,"routeSymbol",{replacement:"viewModel.layer.defaultSymbols.directionLines",version:"4.24",warnOnce:!0}),this.viewModel.legacyLayer.defaultSymbols.directionLines}set stopSymbols(e){t(J,"stopSymbols",{replacement:"viewModel.layer.defaultSymbols.stops",version:"4.24",warnOnce:!0}),this.viewModel.legacyLayer.defaultSymbols.stops=e}get stopSymbols(){return t(J,"stopSymbols",{replacement:"viewModel.layer.defaultSymbols.stops",version:"4.24",warnOnce:!0}),this.viewModel.legacyLayer.defaultSymbols.stops}castVisibleElements(e){return{...V,...e}}getDirections(){return null}render(){return U("div",{class:this.classes(I.base,I.scroller)},this._renderPanelContent())}save(){return this.viewModel.layer.save()}saveAs(e,t={}){return this.viewModel.layer.saveAs(e,t)}zoomToRoute(){}_renderPanelContent(){const{viewModel:{serviceDescription:e,state:t}}=this,s="initializing"===t,i="error"===t&&!e,o="unauthenticated"===t,r={[I.panelContentLoading]:s,[I.panelContentError]:i,[I.panelContentSignIn]:o},n=s?"presentation":"group",a=o?this._renderSignIn():i?this._renderMessage(this._getErrorMessage()):s?this._renderLoader():this._renderReadyContent();return U("div",{class:this.classes(I.panelContent,r),role:n},a)}_renderReadyContent(){return[this._renderStopsContainer(),this._renderTravelModeOptions(),this._renderDepartureTimeControls(),this._renderSaveContainer(),this._renderSectionSplitter(),this._renderDirectionsContainer()]}_renderSignIn(){return U("div",{key:"sign-in",class:I.signInContent},U(A,{class:I.contentTitle,level:this.headingLevel},this.messages.widgetLabel),this._renderPlaceholder(),U(A,{level:j(this.headingLevel)},this.messages.signInRequired),U("button",{class:this.classes(I.button,I.buttonSecondary,I.signInButton),tabIndex:0,onclick:this._handleSignInClick,bind:this,type:"button"},this.messagesCommon.auth.signIn))}_handleSignInClick(){this.viewModel.load().catch((()=>{}))}_renderTravelModeOptions(){if(!this.visibleElements.traveMode)return null;const{selectedTravelMode:e,travelModes:t}=this.viewModel;if(0===t.length)return null;const s=a(e)?e.name:this.messages.travelMode;return U("div",{"aria-disabled":this._saveLayer.opened.toString(),class:this.classes(I.travelMode,this._saveLayer.opened&&I.buttonDisabled),key:"esri-directions__travel-mode-controls",role:"group"},U("select",{"aria-label":s,bind:this,class:this.classes(I.travelModeSelect,I.select),key:"esri-directions__travel-mode-options",onchange:this._handleTravelModeChange,title:s},t.map((t=>{const s=a(e)&&t.id===e.id;return U("option",{key:`esri-directions__travel-mode-${t.id}`,"data-mode":t,selected:s,value:t.id},t.name)}))))}_handleTravelModeChange(e){const t=e.currentTarget,s=t.item(t.selectedIndex);this.viewModel.selectedTravelMode=s["data-mode"],this._getDirections()}_renderStopsContainer(){return this.visibleElements.stops?U("div",{"aria-disabled":this._saveLayer.opened.toString(),class:this.classes(I.section,this._saveLayer.opened&&I.buttonDisabled),key:"esri-directions__stops-container",role:"group"},this._renderStops()):null}_renderDepartureTimeControls(){if(!this.visibleElements.departureTime)return null;const e=this._departureTime,{messages:t}=this,s=t.departureTime;return U("div",{"aria-disabled":this._saveLayer.opened.toString(),class:this.classes(I.departureTime,this._saveLayer.opened&&I.buttonDisabled),key:"esri-directions__departure-time-controls",role:"group"},U("select",{"aria-label":s,bind:this,class:this.classes(I.departureTimeSelect,I.select),onchange:this._handleDepartureOptionChange,title:s},U("option",{value:D.NOW,selected:e===D.NOW},t.leaveNow),U("option",{value:D.DEPART_BY,selected:e===D.DEPART_BY},t.departBy),U("option",{value:D.UNSPECIFIED,selected:e===D.UNSPECIFIED},t.timeUnspecified)),e===D.DEPART_BY?this._renderTimeControls():null)}_renderStops(){const e=this.viewModel.layer.stops;let t=0;for(const o of this._stopsToSearches.keys())e.includes(o)||this._disposeSearch(o);for(const o of e){const e=this._acquireSearch(o);"none"!==e.activeMenu&&(t+=1),a(o.name)&&(e.searchTerm=o.name)}const s=e.toArray().map(((s,i)=>{const o=e.length,r=i>1&&n(s.geometry),l={[I.stopsIcon]:i>=0&&i<o-1,[I.lastStopIcon]:i===o-1},c={[I.lastStopIconContainer]:i===o-1},d={[I.validStopRow]:!r},h=e.getItemAt(i+1),u=h&&a(h.geometry),p=i===o-1,v=i===o-2,m=2===o&&0===i||o>2&&!p&&!v||o>2&&v&&u||o>2&&p&&n(s.geometry),_=o<3,g=this._acquireSearch(s),{messages:y}=this,{removeStop:S,reverseStops:w,unlocated:M}=y,b=z(y.stopLabelTemplate,{number:i+1,label:a(s.geometry)?s.name:M}),f=`${this.id}__stop--${i}`,C=!!g.searchTerm&&!!g.selectedResult&&a(s.geometry)&&g.selectedResult.name===s.name,T={zIndex:"none"!==g.activeMenu?""+t--:""};return U("li",{"aria-label":b,afterCreate:this._handleStopFieldCreation,bind:this,class:this.classes(I.stopRow,d),id:f,key:i,"data-stop-index":i,styles:T},U("div",{class:I.stopHandle},U("span",{"aria-hidden":"true",class:this.classes(I.stopIcon,I.handleIcon,I.stopHandleIcon,I.interactiveStopIcon),onpointerdown:this._handleDragHandlePointerDown}),U("div",{bind:this,"aria-labelledby":f,class:this.classes(I.stopIconContainer,c),"data-stop-index":i,onclick:this._handleStopIconClick,onkeydown:this._handleStopIconClick,role:"button"},U("span",{class:this.classes(I.stopIcon,l),tabindex:C?"0":null}))),U("div",{class:I.stopInput},g.render()),U("div",{class:I.stopOptions,role:"group"},U("div",{"aria-label":S,class:I.removeStopButton,bind:this,"data-stop-index":i,hidden:_,onkeydown:this._handleRemoveStop,onclick:this._handleRemoveStop,role:"button",tabIndex:0,title:S},U("span",{"aria-hidden":"true",class:this.classes(I.stopIcon,I.removeStop,I.removeStopIcon,I.interactiveStopIcon)}),U("span",{class:I.screenReaderText},"removeStopTitle")),U("div",{"aria-label":w,class:I.reverseStops,bind:this,hidden:m,onkeydown:this._handleReverseStops,onclick:this._handleReverseStops,role:"button",tabIndex:0,title:w},U("span",{"aria-hidden":"true",class:this.classes(I.stopIcon,I.reverseStopIcon,I.interactiveStopIcon)}),U("span",{class:I.screenReaderText},"removeStopTitle"))))})),i=this._renderAddStop();return U("div",null,U("ol",{class:I.stops,role:"group",afterCreate:this._setUpDragAndDropStops},s),i)}_renderAddStop(){const{stops:e}=this.viewModel.layer,t=e.filter((({geometry:e})=>a(e))),s=e.at(-1);return t.length>1&&t.length<this.maxStops&&a(s)&&a(s.geometry)?U("div",{class:I.toolbarSection},U("div",{class:I.toolbarButtons},U("calcite-button",{appearance:"outline",class:I.addStopButton,color:"neutral","icon-start":"plus",key:I.addStopButton,onclick:()=>{this._addNewPlaceholder()},text:this.messages.addStop,width:"half"},this.messages.addStop))):null}_handleStopIconClick(e){const t=e.currentTarget["data-stop-index"],s=this.viewModel.layer.stops.getItemAt(t);s&&a(s.geometry)&&this._centerAtStop(s)}_handleClearRouteClick(){this.viewModel.reset()}_centerAtStop(e){this.viewModel.centerAt(e)}_handleStopFieldCreation(e){const t=this._newPlaceholderStop;if(!t)return;const s=e["data-stop-index"],i=this.viewModel.layer.stops.getItemAt(s);if(t===i){const e=this._acquireSearch(i);e.when((()=>{this.renderNow(),e.focus()}))}this._newPlaceholderStop=null}_handleStopInputBlur(e,t){if(this._saveLayer.opened)return;this._handles.remove(K.awaitingViewClickStop),this.view.cursor=this._previousCursor;if(!!e.selectedResult&&a(t.geometry)&&a(e.selectedResult?.feature.geometry)&&t.geometry===e.selectedResult?.feature.geometry)return void this._pointerDownUpHandle.pause();const s=n(t.geometry)&&n(e.selectedResult?.feature.geometry),i=a(t.geometry)&&a(e.selectedResult?.feature.geometry)&&t.geometry!==e.selectedResult.feature.geometry;if((s||i)&&"none"===e.activeMenu&&e.searchTerm)return e.search(),void this._pointerDownUpHandle.pause();e.searchTerm||(this._viewClickHandle.resume(),clearTimeout(this._autoStopRemovalTimeoutId),this._autoStopRemovalTimeoutId=setTimeout((()=>{this.destroyed||(this._viewClickHandle.pause(),"searching"!==e.viewModel.state?this._pointerPressedSearchSuggestionStop||(a(t.geometry)&&(t.geometry=null,this._getDirections()),this.scheduleRender()):this._pointerDownUpHandle.pause())}),this._autoStopRemovalDelay))}_handleStopInputFocus(e,t){if(this._pointerDownUpHandle.resume(),this._handles.has(K.awaitingViewClickStop))return;const{view:s,view:{cursor:i}}=this;this._previousCursor=i,this._handles.add(d((()=>e.searchTerm),(t=>{e.destroyed||(s.cursor=0===t.length?"copy":i)}),h),K.awaitingViewClickStop),this._activeStop=t}_prepViewClick(){const{view:e}=this.viewModel,t=i(e,"click",this._handleViewClick.bind(this)),s=i(e.surface,"click",(()=>{clearTimeout(this._autoStopRemovalTimeoutId),s.pause()}));return{remove(){s.remove(),t.remove()},pause(){s.pause(),t.pause()},resume(){s.resume(),t.resume()}}}_prepPointerDownUpClick(){const e=i(document,"pointerdown",(e=>{this._pointerPressedSearchSuggestionStop=q(e)?this._activeStop:null})),t=i(document,"pointerup",(e=>{this._pointerDownUpHandle.pause();const t=q(e),s=this._activeStop;t||s!==this._pointerPressedSearchSuggestionStop||this._removeStop(s),this.scheduleRender(),this._pointerPressedSearchSuggestionStop=t?s:null}));return{remove(){t.remove(),e.remove()},pause(){t.pause(),e.pause()},resume(){e.resume()}}}_handleViewClick(e){const t=this._stopsToSearches.get(this._activeStop);t&&!t.searchTerm&&(t.search(e.mapPoint).then((e=>{const s=e.results[0].results[0],{feature:i,name:o}=s;this._activeStop.geometry=i.geometry,this._activeStop.name=o,t.searchTerm=o})),this.scheduleRender()),this._viewClickHandle.pause(),clearTimeout(this._autoStopRemovalTimeoutId)}_addNewPlaceholder(){if(this._pointerDownUpHandle.pause(),this._newPlaceholderStop)return;const e=new y({symbol:new S});this.viewModel.layer.stops.add(e),this._newPlaceholderStop=e}_handleReverseStops(){this._reverseStops()}_reverseStops(){this.viewModel.layer.stops.reverse();for(const e of this.viewModel.layer.stops)e.sequence=null;this._getDirections()}_handleRemoveStop(e){const t=e.currentTarget["data-stop-index"],s=this.viewModel.layer.stops.getItemAt(t);this._removeStop(s),(a(s.geometry)||n(this.viewModel.layer.routeInfo))&&this._getDirections()}_removeStop(e){this.viewModel.layer.stops.length<=2||(this._disposeSearch(e),this.viewModel.layer.stops.remove(e))}_handleDepartureOptionChange(e){const t=e.currentTarget,s=t.item(t.selectedIndex);s.value===D.NOW?(this._departureTime=D.NOW,this.viewModel.departureTime=D.NOW,this._handles.remove("departure-time-controls"),this._getDirections()):s.value===D.DEPART_BY?(this._departureTime=D.DEPART_BY,this._handles.add(d((()=>[this._datePicker.value,this._timePicker.value]),(()=>{this._updateDepartureTime(),this._getDirections()}),h),"departure-time-controls")):(this._departureTime=D.UNSPECIFIED,this.viewModel.departureTime=null,this._getDirections())}_updateDepartureTime(){const e=this._datePicker.value,t=this._timePicker.value;e&&t&&(this.viewModel.departureTime=new Date(e.getFullYear(),e.getMonth(),e.getDate(),t.getHours(),t.getMinutes()))}_renderTimeControls(){return U("div",{class:I.departureTimeControls,key:"esri-directions__time-controls",role:"group"},this._datePicker.render(),this._timePicker.render())}_renderSectionSplitter(){return U("div",{class:I.sectionSplitter})}_renderSaveContainer(){const{saveButton:e,saveAsButton:t,printButton:s,layerDetails:i}=this.visibleElements;return e||t||s||i?U("div",{class:I.saveSection,key:I.saveSection},this._renderSaveButtons(),this._renderRouteLayerDetailsLink()):null}_renderSaveButtons(){const{saveButton:e,saveAsButton:t,printButton:s}=this.visibleElements;return e||t||s?U("div",{class:I.saveButtons,key:I.saveButtons},this._renderSaveButton(),this._renderSaveAsButton(),this._renderPrintButton()):null}_renderSaveButton(){if(!this.visibleElements.saveButton)return null;const e=this.viewModel.layer.portalItem?.itemControl,t=a(this.viewModel.layer.routeInfo)&&("admin"===e||"update"===e);return U("calcite-button",{appearance:"outline",class:I.saveButton,color:"neutral",disabled:!t,"icon-start":"save",key:I.saveButton,onclick:()=>{this._handleSaveButtonClick()},text:this.messagesCommon.save,width:"full"},this.messagesCommon.save)}_renderSaveAsButton(){if(!this.visibleElements.saveAsButton)return null;const e=n(this.viewModel.layer.routeInfo);return U("div",{class:I.saveAsButtonPopover,key:I.saveAsButtonPopover},U("calcite-button",{afterCreate:e=>{this._saveAsButtonNode=e},appearance:"outline",class:I.saveAsButton,color:"neutral",disabled:e,"icon-start":"duplicate",key:I.saveAsButton,onclick:()=>this._handleSaveAsButtonClick(),text:this.messagesCommon.saveAs,width:"full"},this.messagesCommon.saveAs))}_renderSavePopover(){return U("calcite-popover",{label:this._saveLayer.label,open:this._saveLayer.opened,"overlay-positioning":"fixed",referenceElement:l(this._saveAsButtonNode)},this._saveLayer.render())}_handleSaveAsButtonClick(){this._saveLayer.opened?this._saveLayer.close():this._saveLayer.open(this.viewModel.layer)}_renderPrintButton(){return this.visibleElements.printButton?U("calcite-button",{appearance:"outline",class:I.printButton,color:"neutral","icon-start":"print",key:I.printButton,text:this.messagesCommon.print}):null}_renderRouteLayerDetailsLink(){if(!this.visibleElements.layerDetails)return null;const{portalItem:e}=this.viewModel.layer;if(!e)return null;const{id:t,portal:{url:s}}=e,i=`${s}/home/item.html?id=${t}`;return U("calcite-link",{class:I.layerDetailsLink,href:i,key:I.layerDetailsLink,target:"_blank"},this.messages.viewLayerDetails)}_handleSaveButtonClick(){this.viewModel.layer.save()}_renderDirectionsContainer(){return U("div",{class:this.classes(I.directionsSection,I.section),key:"esri-directions__container"},this._renderDirectionsContainerContent())}_renderLoader(){return U("div",{class:I.loader,key:"loader"})}_renderWarningCard(){return U("div",{class:I.warningCard,role:"alert"},U("div",{class:I.warningHeader},U("span",{class:I.warningIcon,"aria-hidden":"true"}),U(A,{class:I.warningHeading,level:this.headingLevel},this.messagesCommon.warning)),U("div",{class:I.warningMessage},this._getErrorMessage()))}_renderDirectionsContainerContent(){const{viewModel:{layer:e,state:t}}=this,s="routing"===t;return"error"===t?this._renderWarningCard():s?this._renderLoader():a(e.directionLines)?U("div",{"aria-disabled":this._saveLayer.opened.toString(),class:this.classes(I.summary,this._saveLayer.opened&&I.buttonDisabled),key:"esri-directions__summary",role:"group"},this._renderCosts(),this._renderRouteActions(),this._renderManeuverSections()):U("div",{key:"esri-directions__placeholder",class:I.emptyContent},this._renderPlaceholder(),U(A,{class:I.message,level:this.headingLevel},this.messages.directionsPlaceholder))}_renderPlaceholder(){return U("svg",{class:I.emptyIllustration,xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 256 256"},U("path",{fill:"currentcolor",d:"M192 36c-15.477 0-24 6.034-24 16.99v45.822l24 24 24-24v-45.82C216 42.033 207.477 36 192 36zm20 61.155l-20 20-20-20V52.99c0-8.62 6.73-12.99 20-12.99s20 4.37 20 12.99zM192 52a12 12 0 1 0 12 12 12.013 12.013 0 0 0-12-12zm0 20a8 8 0 1 1 8-8 8.008 8.008 0 0 1-8 8zM92 140.99C92 130.035 83.477 124 68 124s-24 6.034-24 16.99v45.822l24 24 24-24zm-4 44.165l-20 20-20-20V140.99c0-8.62 6.73-12.99 20-12.99s20 4.37 20 12.99zM68 140a12 12 0 1 0 12 12 12.013 12.013 0 0 0-12-12zm0 20a8 8 0 1 1 8-8 8.008 8.008 0 0 1-8 8zm84-44h16v4h-16zm-24 80h4v12h-12v-4h8zm0-28h4v16h-4zm0-52h12v4h-8v8h-4zm0 24h4v16h-4zm-36 64h16v4H92z"}))}_renderMessage(e){return U(A,{level:this.headingLevel},e)}_renderRouteActions(){return U("div",{class:I.routeActions},U("button",{"aria-label":this.messages.clearRoute,class:this.classes(I.clearRouteButton,I.button,I.buttonTertiary),tabIndex:0,onclick:this._handleClearRouteClick,bind:this,type:"button"},this.messages.clearRoute))}_getSections(){const{directionPoints:e,directionLines:t,stops:s}=this.viewModel.layer;if(n(e)||n(t))return null;const i=[];let o=null;for(const r of e){const{objectId:e,stopId:l}=r;if(a(l)){const e=s.find((e=>e.objectId===l)),t=0===i.length;(n(o)||o.stop!==e)&&(o={stop:e,directions:[],open:t},i.push(o));continue}if(n(o))continue;const c=t.find((t=>t.directionPointId===e));n(c)||o.directions.push({directionPoint:r,directionLine:c})}return i}_renderManeuverSections(){return n(this._sections)?null:U("div",{class:I.maneuvers,role:"group"},this._sections.map(((e,t)=>{const{open:s}=e;let i;e.directions.length>0&&s&&(i=U("ol",{class:I.maneuverList},e.directions.map((e=>this._renderManeuver(e)))));const o=l(this._sections).length>2,r=t===l(this._sections).length-1,n={[I.collapsibleSection]:o},a={[I.openIcon]:!s,[I.closeIcon]:s};let c;if(o&&!r){const t=s?this.messagesCommon.close:this.messagesCommon.open;c=U("header",{class:this.classes(I.maneuverSectionHeader,I.maneuverSectionToggle),key:I.maneuverSectionHeader},U("div",{"aria-expanded":s.toString(),"aria-label":t,bind:this,class:I.maneuverSectionHeaderButton,"data-maneuver-section":e,onkeydown:this._handleSectionToggle,onclick:this._handleSectionToggle,role:"button",tabIndex:0,title:t},U(A,{class:I.maneuverSectionTitle,level:this.headingLevel},e.stop.name),U("span",{"aria-hidden":"true",class:this.classes(a)})))}else c=U("header",{class:I.maneuverSectionHeader,key:I.maneuverSectionHeader},U(A,{class:I.maneuverSectionTitle,level:this.headingLevel},e.stop.name));return U("section",{class:this.classes(I.maneuverSection,n),key:t},c,i)})))}_handleSectionToggle(e){const t=e.currentTarget["data-maneuver-section"];t.open=!t.open}_renderCosts(){const e=this._getCostSummary(),{directionPoints:t}=this.viewModel.layer;if(n(t)||n(e))return null;const s=t.getItemAt(t.length-1).arrivalTime,{primary:i,secondary:o}=e,{eta:r,etaTemplate:l,primaryCosts:c,secondaryCosts:d,zoomToRoute:h}=this.messages,u=F("short-time"),p=a(s)?`<strong>${$(s,u)}</strong>`:null,v=a(s)?`${W(s)}`:null,m=z(l,{time:p,gmt:v});return U("div",{"aria-label":h,bind:this,class:I.directionCosts,onkeydown:this._handleSummaryInteraction,onclick:this._handleSummaryInteraction,role:"button",tabIndex:0,title:h},U("div",{class:I.costsDetails,role:"group"},U("div",{class:I.primaryCosts,title:c},i),U("div",{class:I.verticalSplitter}),U("div",{class:I.secondaryCosts,title:d},o)),U("div",{innerHTML:m,title:r}))}_handleSummaryInteraction(){this._activeManeuver=null,this._focusedManeuver=null,this.viewModel.clearHighlights(),this.zoomToRoute()}_getErrorMessage(){const{messages:e,viewModel:{lastError:t}}=this;if(a(t))switch(t.name){case"directions-view-model:unable-to-route":return e.errors.unableToRoute;case"directions-view-model:service-metadata-unavailable":return e.errors.unableToLoadServiceMetadata}return e.errors.unknownError}_normalizeSearchSources(e){this._overrideDefaultSources(e),this._applyLocatorSourceOverrides(e)}_overrideDefaultSources(e){e.viewModel.defaultSources.forEach((e=>{e.autoNavigate=!1}))}_applyLocatorSourceOverrides({allSources:e}){for(const t of e)"url"in t&&t.url&&(t.locationType??(t.locationType="street"),P(t.url)&&this.apiKey&&null==t.apiKey&&(t.apiKey=this.apiKey,t.url=R))}_acquireSearch(e){const{view:t}=this.viewModel;if(this._stopsToSearches.has(e)){const s=this._stopsToSearches.get(e);return s.view=t,this._overrideDefaultSources(s),s}const s=new w({view:t,resultGraphicEnabled:!1,popupEnabled:!1,...this.searchProperties});return this._normalizeSearchSources(s),this._handles.add([p((()=>s.allSources),"change",(()=>this._normalizeSearchSources(s))),s.on("select-result",(()=>{e.geometry=s.selectedResult.feature.geometry,e.name=s.selectedResult.name,this._getDirections()})),s.on("search-focus",(()=>this._handleStopInputFocus(s,e))),s.on("search-blur",(()=>this._handleStopInputBlur(s,e))),s.on("search-clear",(()=>{e.geometry=null,e.name=null,this._activeStop=e,this.viewModel.layer.removeResult()})),d((()=>s.searchTerm),(t=>{e.name=t}))],s),this._stopsToSearches.set(e,s),s}_disposeSearch(e){this._stopsToSearches.has(e)&&(this._stopsToSearches.get(e).destroy(),this._stopsToSearches.delete(e))}_renderManeuver(e){const t="",{directionsLengthUnits:s}=this.viewModel.routeParameters,{directionPoint:i,directionLine:o}=e,{distance:r,duration:n}=o,{messages:l,messagesUnits:d}=this,h=C(l,d,c(r,0),{fromUnits:"meters",toUnits:s}),u=T(c(n,0),"minutes"),p=h&&u?`${h} · ${u}`:`${h}${u}`,v=this._getFormattedManeuverText(i),{objectId:m,directionPointType:_}=i,g=L(_),y=`esri-directions__maneuver-${m}`,S=`esri-directions__cumulative-costs-${m}`,w=`esri-directions__intermediate-costs-${m}`,M={[I.maneuverActive]:this._activeManeuver===o};return U("li",{"aria-labelledby":`${y} ${S} ${w}`,bind:this,class:this.classes(I.maneuver,M),"data-maneuver":o,key:o,onclick:this._handleManeuverClick,onkeydown:this._handleManeuverClick,onfocus:this._handleManeuverFocus,onmouseover:this._handleManeuverMouseOver,onmouseout:this._handleManeuverMouseOut,onblur:this._handleManeuverBlur,tabIndex:0},a(g)&&U("img",{alt:"",class:I.maneuverIcon,src:g}),U("div",{class:I.maneuverCostsContainer},U("span",{id:y,innerHTML:c(v,"")}),U("div",{class:I.maneuverCosts},U("div",{class:I.horizontalSplitter}),U("div",{id:S,class:I.cumulativeCost,innerHTML:t,title:l.cumulativeCosts}),U("div",{id:w,class:I.intermediateCost,innerHTML:p,title:l.intermediateCosts}))))}_handleManeuverClick(e){const t=e.currentTarget["data-maneuver"];if(this._activeManeuver===t)return this._activeManeuver=null,void this.zoomToRoute();this._activeManeuver=t;const{geometry:s}=t;this.viewModel.centerAt(s),this.viewModel.highlight(t)}_handleManeuverMouseOver(e){if(this._activeManeuver||this._focusedManeuver)return;const t=e.currentTarget["data-maneuver"];this.viewModel.highlight(t)}_handleManeuverMouseOut(){this._activeManeuver||this._focusedManeuver||this.viewModel.clearHighlights()}_handleManeuverBlur(){this._activeManeuver||(this._focusedManeuver=null,this.viewModel.clearHighlights())}_handleManeuverFocus(e){if(this._activeManeuver)return;const t=e.currentTarget["data-maneuver"];this._focusedManeuver=t,this.viewModel.highlight(t)}_getFormattedManeuverText(e){const{displayText:t,name:s,intersectingName:i}=e;if(n(t))return"";let o=t;return a(s)&&o.includes(s)&&(o=o.replace(s,`<strong>${s}</strong>`)),a(i)&&o.includes(i)&&(o=o.replace(i,`<strong>${i}</strong>`)),o}_getCostSummary(){const{viewModel:{impedanceAttribute:e,layer:{routeInfo:t},routeParameters:s}}=this;if(n(e)||n(t))return null;let{totalDuration:i,totalDistance:o}=t;const{directionsLengthUnits:r}=s;o=a(o)?o:0,i=a(i)?i:0;const l=C(this.messages,this.messagesUnits,o,{fromUnits:"meters",toUnits:r}),c=T(i,"minutes"),[d,h]=k(e.units)?[c,l]:[l,c];return{primary:d,secondary:h}}async _getDirections(){if(!(this.viewModel.layer.stops.filter((e=>a(e.geometry))).length<2))try{await this.viewModel.getDirections()}catch{}}};e([v("viewModel.apiKey")],Q.prototype,"apiKey",void 0),e([v("viewModel.goToOverride")],Q.prototype,"goToOverride",void 0),e([_()],Q.prototype,"headingLevel",void 0),e([_()],Q.prototype,"iconClass",void 0),e([_({aliasOf:{source:"messages.widgetLabel",overridable:!0}})],Q.prototype,"label",void 0),e([v("viewModel.lastRoute")],Q.prototype,"lastRoute",void 0),e([v("viewModel.layer")],Q.prototype,"layer",void 0),e([v("viewModel.maxStops")],Q.prototype,"maxStops",void 0),e([_(),H("esri/widgets/Directions/t9n/Directions")],Q.prototype,"messages",void 0),e([_(),H("esri/t9n/common")],Q.prototype,"messagesCommon",void 0),e([_(),H("esri/core/t9n/Units")],Q.prototype,"messagesUnits",void 0),e([_()],Q.prototype,"routeServiceUrl",null),e([_()],Q.prototype,"routeSymbol",null),e([_()],Q.prototype,"searchProperties",void 0),e([_()],Q.prototype,"stopSymbols",null),e([v("viewModel.view")],Q.prototype,"view",void 0),e([_({type:b})],Q.prototype,"viewModel",void 0),e([_()],Q.prototype,"visibleElements",void 0),e([m("visibleElements")],Q.prototype,"castVisibleElements",null),e([v("viewModel.getDirections")],Q.prototype,"getDirections",null),e([v("viewModel.zoomToRoute")],Q.prototype,"zoomToRoute",null),e([E()],Q.prototype,"_handleStopIconClick",null),e([E()],Q.prototype,"_handleClearRouteClick",null),e([E()],Q.prototype,"_handleReverseStops",null),e([E()],Q.prototype,"_handleRemoveStop",null),e([E()],Q.prototype,"_handleSectionToggle",null),e([E()],Q.prototype,"_handleSummaryInteraction",null),e([E()],Q.prototype,"_handleManeuverClick",null),Q=e([g("esri.widgets.Directions")],Q);const X=Q;export{X as default};
|