/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["../../chunks/_rollupPluginBabelHelpers","../../chunks/tslib.es6","../../assets","../../Graphic","../../core/Accessor","../../core/Error","../../core/Evented","../../core/accessorSupport/decorators/property","../../core/arrayUtils","../../core/has","../../core/accessorSupport/ensureType","../../core/accessorSupport/decorators/subclass","../../symbols/PictureMarkerSymbol","./geolocationUtils","./GoTo"],(function(t,e,o,i,n,r,a,s,c,p,l,d,u,h,g){"use strict";const _=2500;let y=function(e){function n(){var t;return(t=e.apply(this,arguments)||this)._geolocationUsable=!0,t._iconPath=o.getAssetUrl("esri/images/support/sdk_gps_location.png"),t.geolocationOptions=null,t.goToLocationEnabled=!0,t.graphic=new i({symbol:new u({url:t._iconPath,width:21,height:21})}),t.scale=null,t.useHeadingEnabled=!0,t.view=null,t}t._inheritsLoose(n,e);var a=n.prototype;return a.initialize=function(){h.supported()||(this._geolocationUsable=!1)},a.destroy=function(){this._clear(),this.view=null},a._clear=function(){this.view&&this.view.graphics.remove(this.graphic)},a._getScaleWithinConstraints=function(t,e){if(!e)return t;if("2d"===e.type){const{effectiveMaxScale:o,effectiveMinScale:i}=e.constraints;return Math.min(i,Math.max(o,t))}return t},a._getScale=function(t){const{scale:e}=this,o="number"==typeof e?e:_;return this._getScaleWithinConstraints(o,t)},a._getHeading=function(t,e){const o=e&&e.spatialReference,i=o&&(o.isWebMercator||o.isGeographic),n=t.coords&&t.coords.heading;if(!(!i||"number"!=typeof n||isNaN(n)||n<0||n>360))return n},a._addHeading=function(t){const{heading:e,target:o,view:i}=t;i&&"number"==typeof e&&!isNaN(e)&&("3d"!==i.type?"2d"===i.type&&(o.rotation=360-e):o.heading=e)},a._animatePoint=function(t,e,o,i){const{view:n}=this;if(!this.goToLocationEnabled||!n)return Promise.resolve(e);const r=this.useHeadingEnabled?this._getHeading(e,n):void 0,a={target:t,scale:o};return this._addHeading({heading:r,target:a,view:n}),this.callGoTo({target:a,options:i}).then((()=>e))},a._setPosition=function(){var e=t._asyncToGenerator((function*(t,e){try{const o=yield h.positionToPoint({position:t,view:this.view},e),{graphic:i}=this,{timestamp:n}=t,{coords:r}=t,{accuracy:a,altitude:s,altitudeAccuracy:c,heading:p,latitude:l,longitude:d,speed:u}=r,g={timestamp:n,accuracy:a,altitude:s,altitudeAccuracy:c,heading:p,latitude:l,longitude:d,speed:u};i&&(i.geometry=o,i.attributes=g);const _=this._getScale(this.view);return this._animatePoint(o,t,_,e)}catch(o){throw new r("positioning:invalid-point","Cannot position invalid point",{error:o})}}));function o(t,o){return e.apply(this,arguments)}return o}(),n}(g.GoToMixin(a.EventedMixin(n)));e.__decorate([s.property()],y.prototype,"_geolocationUsable",void 0),e.__decorate([s.property()],y.prototype,"geolocationOptions",void 0),e.__decorate([s.property()],y.prototype,"goToLocationEnabled",void 0),e.__decorate([s.property()],y.prototype,"graphic",void 0),e.__decorate([s.property()],y.prototype,"scale",void 0),e.__decorate([s.property()],y.prototype,"useHeadingEnabled",void 0),e.__decorate([s.property()],y.prototype,"view",void 0),y=e.__decorate([d.subclass("esri.widgets.support.GeolocationPositioning")],y);return y}));
