12345 |
- /*
- All material copyright ESRI, All Rights Reserved, unless otherwise specified.
- See https://js.arcgis.com/4.25/esri/copyright.txt for details.
- */
- import{_ as t}from"../../chunks/tslib.es6.js";import"../../intl.js";import e from"../../PopupTemplate.js";import o from"../../core/Error.js";import a from"../../core/Handles.js";import{property as i}from"../../core/accessorSupport/decorators/property.js";import"../../core/arrayUtils.js";import"../../core/accessorSupport/ensureType.js";import{subclass as r}from"../../core/accessorSupport/decorators/subclass.js";import{removeSelectedFeature as l}from"../Popup/actions.js";import s from"../support/GeolocationPositioning.js";import{getCurrentPosition as c}from"../support/geolocationUtils.js";import{onLocaleChange as p}from"../../intl/locale.js";import{fetchMessageBundle as n}from"../../intl/messages.js";async function d(){const t=await n("esri/widgets/Locate/t9n/Locate");return new e({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:[l.clone()],content:[{type:"fields"}]})}let h=class extends s{constructor(t){super(t),this._locateController=null,this._handles=new a,this.popupEnabled=!0,this.locate=this.locate.bind(this)}initialize(){this._handles.add([p((()=>{const{graphic:t,view:e}=this,o=e?.graphics?.includes(t);o&&this._updatePopupTemplate(t)}))])}destroy(){this.cancelLocate(),this._handles.destroy(),this._handles=null}get state(){return this._geolocationUsable?this.get("view.ready")?this._locateController?"locating":"ready":"disabled":"feature-unsupported"}async locate(){if(this.cancelLocate(),"disabled"===this.state)throw new o("locate:disabled-state","Cannot locate when disabled.");if("feature-unsupported"===this.state)throw new o("locate:feature-unsupported-state","Cannot locate in unsecure domain.");const t=new AbortController;this._locateController=t;try{let e=await c(this.geolocationOptions);return e=await this._setPosition(e,{signal:t.signal}),this._locateController!==t?null:(this.graphic&&(this.graphic=this.graphic.clone(),await this._updatePopupTemplate(this.graphic),this.view.graphics.push(this.graphic)),this.emit("locate",{position:e}),this._locateController=null,e)}catch(e){throw this._locateController=null,this.emit("locate-error",{error:e}),e}}cancelLocate(){this._clear(),this._locateController&&this._locateController.abort(),this._locateController=null}async _updatePopupTemplate(t){if(!this.popupEnabled)return;const e=await d(),o=t!==this.graphic;this.destroyed||o||(t.popupTemplate=e)}};t([i()],h.prototype,"_locateController",void 0),t([i()],h.prototype,"popupEnabled",void 0),t([i({readOnly:!0})],h.prototype,"state",null),t([i()],h.prototype,"locate",null),t([i()],h.prototype,"cancelLocate",null),h=t([r("esri.widgets.Locate.LocateViewModel")],h);const u=h;export{u as default};
|