@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
3 lines (2 loc) • 3.45 kB
JavaScript
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.19/LICENSE.txt */
import{__decorate as t}from"tslib";import{onLocaleChange as e,fetchMessageBundle as o}from"../../intl.js";import r from"../../PopupTemplate.js";import{deprecateUnnecessaryViewModel as a}from"../../core/deprecate.js";import i from"../../core/Error.js";import l from"../../core/Logger.js";import{isAbortError as s}from"../../core/promiseUtils.js";import{property as c,subclass as n}from"../../core/accessorSupport/decorators.js";import{removeSelectedFeature as p}from"../Popup/actions.js";import d from"../support/GeolocationPositioning.js";import{getCurrentPosition as u}from"../support/geolocationUtils.js";async function h(){const t=await o("esri/widgets/Locate/t9n/Locate");return new r({title:t.currentLocation,fieldInfos:[{fieldName:"timestamp",label:t.timestamp,format:{dateFormat:"short-date-short-time"}},{fieldName:"latitude",label:t.latitude,format:{places:4,digitSeparator:!0}},{fieldName:"longitude",label:t.longitude,format:{places:4,digitSeparator:!0}},{fieldName:"accuracy",label:t.accuracy,format:{places:0,digitSeparator:!0}},{fieldName:"altitude",label:t.altitude,format:{places:0,digitSeparator:!0}},{fieldName:"altitudeAccuracy",label:t.altitudeAccuracy,format:{places:0,digitSeparator:!0}},{fieldName:"heading",label:t.heading,format:{places:0,digitSeparator:!0}},{fieldName:"speed",label:t.speed,format:{places:0,digitSeparator:!0}}],actions:[p.clone()],content:[{type:"fields"}]})}let m=class extends d{constructor(t){super(t),this._locateController=null,this.error=void 0,this.popupEnabled=!0,this.locate=this.locate.bind(this),t?.suppressDeprecationWarning||a(l.getLogger(this),"Locate","arcgis-locate",{version:"4.34"})}normalizeCtorArgs(t){const{suppressDeprecationWarning:e,...o}=t??{};return o}initialize(){this.addHandles([e(()=>{const{graphic:t,view:e}=this;if(!t)return;const o=e?.graphics?.includes(t);o&&this._updatePopupTemplate(t)})])}destroy(){this.cancelLocate()}get state(){return this._geolocationUsable?this.view?.ready?this._locateController?"locating":null!=this.error?"error":"ready":"disabled":"feature-unsupported"}async locate(){if(this.cancelLocate(),"disabled"===this.state)throw new i("locate:disabled-state","Cannot locate when disabled.");if("feature-unsupported"===this.state)throw new i("locate:feature-unsupported-state","Cannot locate in unsecure domain.");const t=new AbortController;this._locateController=t,this.error=void 0;try{const e=await u(this.geolocationOptions);if(await this.updatePosition(e,t),this._locateController!==t)return null;const{graphic:o}=this;return o&&await this._updatePopupTemplate(o),this._addGraphic(),this.emit("locate",{position:e}),this._locateController=null,e}catch(e){if(s(e))return null;throw t===this._locateController&&(this._locateController=null),this.error=e,this.emit("locate-error",{error:e}),e}}cancelLocate(){this._clearGraphic(),this._locateController&&this._locateController.abort(),this._locateController=null}async _updatePopupTemplate(t){if(!this.popupEnabled)return;const e=await h(),o=t!==this.graphic;this.destroyed||o||(t.popupTemplate=e)}};t([c()],m.prototype,"_locateController",void 0),t([c()],m.prototype,"error",void 0),t([c()],m.prototype,"popupEnabled",void 0),t([c({readOnly:!0})],m.prototype,"state",null),t([c()],m.prototype,"locate",null),t([c()],m.prototype,"cancelLocate",null),m=t([n("esri.widgets.Locate.LocateViewModel")],m);const f=m;export{f as default};