UNPKG

@arcgis/map-components

Version:
2 lines 6.72 kB
/* COPYRIGHT Esri - https://js.arcgis.com/5.1/LICENSE.txt */ import j from"./WIL4XDDC.js";import{a as P}from"./CFHNK7GX.js";import i from"./HFRXDFTO.js";import"./PC4PAQXQ.js";import g from"./KA7BM2DQ.js";import{a as C}from"./HZFVK34O.js";import{a as u}from"./54VXNFQ4.js";import e from"./LKOVDQTE.js";import c from"./OAWV35F7.js";import{h as M}from"./AKBXFBDL.js";import"./LMBRORN7.js";import a from"./5E6WEUZS.js";import{d as _}from"./PBSJQPB2.js";import{M as v,N as b,O as w,P as d,R as y,U as E,a as f,b as p,x as h}from"./WUJCCZQC.js";import"./3TTFCHAA.js";export default $arcgis.t(([{watch:$},{property:c,subclass:G},D,{onLocaleChange:z},B,I,,,,T,{d:O},{a:S,b:L}])=>{var k=f`.arcgis-button{--calcite-icon-color: var(--calcite-color-text-3);--calcite-button-background-color: var(--calcite-color-foreground-1);color:var(--calcite-color-text-3);line-height:var(--calcite-font-line-height-relative-tight);calcite-button{--calcite-offset-invert-focus: 1}display:flex;flex-flow:column;cursor:pointer;background-color:var(--calcite-color-foreground-1);font-size:var(--calcite-font-size);:hover{--calcite-icon-color: var(--calcite-color-text-1);--calcite-button-background-color: var(--calcite-color-transparent-hover)}}:host{width:fit-content;height:fit-content}`,A=Object.defineProperty,R=Object.getOwnPropertyDescriptor,s=(e,t,i,a)=>{for(var o=a>1?void 0:a?R(t,i):t,l=e.length-1,n;l>=0;l--)(n=e[l])&&(o=(a?n(t,i,o):n(o))||o);return a&&o&&A(t,i,o),o},U=new I({icon:"trash",id:"remove-selected-feature",title:"{messages.remove}"})._internalSetClassName("esri-icon-trash");function j(e){return new B({title:e.currentLocation,fieldInfos:[{fieldName:"timestamp",label:e.timestamp,format:{dateFormat:"short-date-short-time"}},{fieldName:"latitude",label:e.latitude,format:{places:4,digitSeparator:!0}},{fieldName:"longitude",label:e.longitude,format:{places:4,digitSeparator:!0}},{fieldName:"accuracy",label:e.accuracy,format:{places:0,digitSeparator:!0}},{fieldName:"altitude",label:e.altitude,format:{places:0,digitSeparator:!0}},{fieldName:"altitudeAccuracy",label:e.altitudeAccuracy,format:{places:0,digitSeparator:!0}},{fieldName:"heading",label:e.heading,format:{places:0,digitSeparator:!0}},{fieldName:"speed",label:e.speed,format:{places:0,digitSeparator:!0}}],actions:[U.clone()],content:[{type:"fields"}]})}var r=class extends L{constructor(e){super(e),this._getCurrentPosition=S,this.popupEnabled=!0,this.locate=this.locate.bind(this)}initialize(){this.addHandles([z(()=>{let{graphic:e,view:t}=this;e&&t?.graphics?.includes(e)&&this._updatePopupTemplate(e)})])}destroy(){this.cancelLocate()}get state(){return this._geolocationUsable?this.view?.ready?this._locateController?"locating":this.error!=null?"error":"ready":"disabled":"feature-unsupported"}async locate(){if(this.cancelLocate(),this.state==="disabled")throw new D("locate:disabled-state","Cannot locate when disabled.");if(this.state==="feature-unsupported")throw new D("locate:feature-unsupported-state","Cannot locate in unsecure domain.");let e=new AbortController;this._locateController=e,this.error=void 0;try{let t=await this._getCurrentPosition(this.geolocationOptions);if(await this.updatePosition(t,e),this._locateController!==e)return null;let{graphic:i}=this;return i&&this._updatePopupTemplate(i),this._addGraphic(),this.currentPosition=t,this._locateController=void 0,t}catch(t){if(O(t))return null;throw e===this._locateController&&(this._locateController=void 0),this.error=t,t}}cancelLocate(){this._clearGraphic(),this._locateController&&this._locateController.abort(),this._locateController=void 0}_updatePopupTemplate(e){if(!this.popupEnabled)return;let t=j(this.messages),i=e!==this.graphic;this.destroyed||i||(e.popupTemplate=t)}};s([c()],r.prototype,"_locateController",2);s([c()],r.prototype,"currentPosition",2);s([c()],r.prototype,"error",2);s([c()],r.prototype,"messages",2);s([c()],r.prototype,"popupEnabled",2);s([c({readOnly:!0})],r.prototype,"state",1);r=s([G("map-components.locate.LocateViewModel")],r);var N="gps-off",V=T(r),m=class extends w{constructor(){super(),this.locateButtonElement=v(),this.messages=C(),this.viewModel=V(this),this.hideErrorTooltip=()=>{this.isErrorTooltipOpen=!1},this.isErrorTooltipOpen=!1,this.view=this.viewModel.view,this.autoDestroyDisabled=!1,this.geolocationOptions=this.viewModel.geolocationOptions,this.goToLocationDisabled=this.viewModel.goToLocationEnabled,this.goToOverride=this.viewModel.goToOverride,this.graphic=this.viewModel.graphic,this.icon=N,this.popupDisabled=this.viewModel.popupEnabled,this.scale=this.viewModel.scale,this.state=this.viewModel.state,this.visualScale="m",this.arcgisError=h(),this.arcgisPropertyChange=M()("state"),this.arcgisReady=h(),this.arcgisSuccess=h(),this.listenOn(document,"click",this.hideErrorTooltip)}static{this.properties={isErrorTooltipOpen:16,view:0,autoDestroyDisabled:5,geolocationOptions:0,goToLocationDisabled:7,goToOverride:0,graphic:0,icon:1,label:1,messageOverrides:0,popupDisabled:5,referenceElement:1,scale:9,state:32,visualScale:1}}static{this.styles=k}async cancelLocate(){this.viewModel.cancelLocate()}async destroy(){await this.manager.destroy()}async locate(){return await this.viewModel.locate()}loaded(){this.viewModel.messages={...this.messages,...this.messageOverrides},this.manager.onLifecycle(()=>[$(()=>this.viewModel.error,t=>{this.isErrorTooltipOpen=!!t,this.arcgisError.emit({error:t})}),$(()=>this.viewModel.currentPosition,t=>{this.arcgisSuccess.emit({position:t})})])}_localizeError(t){if(t instanceof GeolocationPositionError)return t.code===GeolocationPositionError.PERMISSION_DENIED?this.messages?.permissionError:t.code===GeolocationPositionError.TIMEOUT?this.messages?.timeoutError:this.messages?.positionUnavailable;if(t instanceof Error)return t.message}_locate(){let{viewModel:t}=this;t.state==="locating"?t.cancelLocate():t.locate().catch(()=>{})}render(){let{viewModel:t,icon:i}=this,{state:a}=t,o=a==="locating",l=o?this.messages.cancel:this.messages.title,n=a==="feature-unsupported",x=P===void 0?N:void 0,g=this._localizeError(this.viewModel?.error);return p`<div class=${d(_("root",u.arcgisButton))}>${!n&&p`<calcite-button class=${d(u.widgetButton)} .disabled=${a==="disabled"} .loading=${o} .iconStart=${o?void 0:i??x} kind=neutral .label=${l} @click=${this._locate} .scale=${this.visualScale} title=${l??y} ${b(this.locateButtonElement)}></calcite-button>`||""}${g?p`<calcite-tooltip .open=${this.isErrorTooltipOpen} overlay-positioning=fixed .referenceElement=${this.locateButtonElement.value}>${g}</calcite-tooltip>`:null}</div>`}};E("arcgis-locate",m);return m},"core/reactiveUtils","core/accessorSupport/decorators","core/Error","intl","PopupTemplate","support/actions/ActionButton",a,c,e,g,i,j)