@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
3 lines (2 loc) • 3.86 kB
JavaScript
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */
import{__decorate as e}from"tslib";import o from"../Graphic.js";import{deprecateWidget as t}from"../core/deprecate.js";import i from"../core/Logger.js";import{property as s,subclass as r}from"../core/accessorSupport/decorators.js";import l from"./Widget.js";import n from"./Locate/LocateViewModel.js";import{loadCalciteComponents as a}from"./support/componentsUtils.js";import{globalCss as c}from"./support/globalCss.js";import{messageBundle as p,vmEvent as d,tsx as g}from"./support/widget.js";const m={base:"esri-locate"};let u=class extends l{constructor(e,o){super(e,o),this.messages=null,this.messagesCommon=null,this.viewModel=new n({suppressDeprecationWarning:!0}),this._locate=()=>{const{viewModel:e}=this;"locating"===e.state?e.cancelLocate():e.locate().catch(()=>{})},t(i.getLogger(this),"Locate","arcgis-locate",{version:"4.32"})}loadDependencies(){return a({button:()=>import("@esri/calcite-components/dist/components/calcite-button"),loader:()=>import("@esri/calcite-components/dist/components/calcite-loader"),tooltip:()=>import("@esri/calcite-components/dist/components/calcite-tooltip")})}get geolocationOptions(){return this.viewModel.geolocationOptions}set geolocationOptions(e){this.viewModel.geolocationOptions=e}get goToLocationEnabled(){return this.viewModel.goToLocationEnabled}set goToLocationEnabled(e){this.viewModel.goToLocationEnabled=e}get goToOverride(){return this.viewModel.goToOverride}set goToOverride(e){this.viewModel.goToOverride=e}get graphic(){return this.viewModel.graphic}set graphic(e){this.viewModel.graphic=e}get icon(){return"gps-off"}set icon(e){this._overrideIfSome("icon",e)}get label(){return this.messages?.widgetLabel??""}set label(e){this._overrideIfSome("label",e)}get popupEnabled(){return this.viewModel.popupEnabled}set popupEnabled(e){this.viewModel.popupEnabled=e}get scale(){return this.viewModel.scale}set scale(e){this.viewModel.scale=e}get view(){return this.viewModel.view}set view(e){this.viewModel.view=e}cancelLocate(){this.viewModel.cancelLocate()}locate(){return this.viewModel.locate()}render(){const{viewModel:e,icon:o}=this,{state:t}=e,i="locating"===t,s=i?this.messagesCommon.cancel:this.messages.title,r="feature-unsupported"===t,l=this._localizeError(this.viewModel?.error);return g("div",{class:this.classes(m.base,c.widget)},!r&&g("calcite-button",{class:c.widgetButton,disabled:"disabled"===t,iconStart:i?void 0:o,kind:"neutral",label:s,onclick:this._locate,title:s},i?g("calcite-loader",{inline:!0,label:""}):null),l?g("calcite-tooltip",{open:!0,overlayPositioning:"fixed",placement:this._getPlacement(),referenceElement:this.container,topLayerDisabled:this.topLayerDisabled},l):null)}_getPlacement(){const{container:e,view:o}=this,t=e&&o?o.ui.getPosition(e):null;if(!t||"manual"===t)return"auto";const[i,s]=t.split("-");return`${"right"===s?"left":"right"}-${"bottom"===i?"end":"start"}`}_localizeError(e){return e instanceof GeolocationPositionError?e.code===GeolocationPositionError.PERMISSION_DENIED?this.messages?.permissionError:e.code===GeolocationPositionError.TIMEOUT?this.messages?.timeoutError:this.messages?.positionUnavailable:e instanceof Error?e.message:void 0}};e([s()],u.prototype,"geolocationOptions",null),e([s()],u.prototype,"goToLocationEnabled",null),e([s()],u.prototype,"goToOverride",null),e([s({type:o})],u.prototype,"graphic",null),e([s()],u.prototype,"icon",null),e([s()],u.prototype,"label",null),e([s(),p("esri/widgets/Locate/t9n/Locate")],u.prototype,"messages",void 0),e([s(),p("esri/t9n/common")],u.prototype,"messagesCommon",void 0),e([s()],u.prototype,"popupEnabled",null),e([s()],u.prototype,"scale",null),e([s()],u.prototype,"view",null),e([s({type:n}),d(["locate","locate-error"])],u.prototype,"viewModel",void 0),u=e([r("esri.widgets.Locate")],u);const h=u;export{h as default};