// All material copyright ESRI, All Rights Reserved, unless otherwise specified.
// See http://@sbaseurl@/jsapi/jsapi/esri/copyright.txt and http://www.arcgis.com/apps/webappbuilder/copyright.txt for details.

//>>built
define("dojo/_base/declare dojo/_base/lang dojo/Deferred jimu/BaseWidget dojo/on esri/symbols/PictureMarkerSymbol esri/symbols/SimpleFillSymbol esri/symbols/SimpleLineSymbol esri/graphic esri/Color esri/geometry/Circle".split(" "),function(l,f,m,n,p,q,g,h,r,k,t){var e=null;var d=l([n],{constructor:function(a,b,c){this.id="widget-myLocation-compass-"+(new Date).getTime();this.map=b;this.folderUrl=a;this.config=c;this._debug=0;this.inherited(arguments)},show:function(a,b){if(this.map.spatialReference.isWebMercator()||
4326===this.map.spatialReference)!0===this.config.useCompass&&this._showDirection(b),!0===this.config.useAccCircle&&this._showAccCircle(a,b)},_showDirection:function(a){if(a.useTracking){this._destroyDirectionHandler();var b;"ondeviceorientationabsolute"in window?b="deviceorientationabsolute":"ondeviceorientation"in window?b="deviceorientation":DeviceOrientationEvent&&(b="deviceorientation");this._directionHandler=p(window,b,f.hitch(this,this._watchMobileLocation,a))}},_watchMobileLocation:function(a,
b){if(b){if(b.webkitCompassHeading||b.alpha)var c=b.webkitCompassHeading||Math.abs(b.alpha-360);b=window.orientation||0;"undefined"!==typeof c&&a.highlightGraphic.setSymbol(new q({url:this.folderUrl+"/images/compass.png",width:36,height:36,angle:-c-b}))}},_showAccCircle:function(a,b){this._destroyAccCircle();if((b=b.highlightGraphic)&&b._graphicsLayer){var c=b.geometry;a=a.position.coords.accuracy/this.map.getResolution();a=new t({center:c,radius:a});a=new r(a,new g(g.STYLE_SOLID,new h(h.STYLE_SOLID,
new k([94,164,255,.2]),1),new k([16,119,255,.2])));b._graphicsLayer.add(a);this._accCircle=a;this._accCircleGraphicsLayer=b._graphicsLayer}},clean:function(){this._destroyDirectionHandler();this._destroyAccCircle()},destroy:function(){this.clean();this.inherited(arguments)},_destroyDirectionHandler:function(){this._directionHandler&&(this._directionHandler.remove&&this._directionHandler.remove(),this._directionHandler=null)},_destroyAccCircle:function(){this._accCircleGraphicsLayer&&this._accCircleGraphicsLayer.remove&&
this._accCircle&&(this._accCircleGraphicsLayer.remove(this._accCircle),this._accCircle=null)}});d.getInstance=function(a,b,c){null===e&&(e=new d(a,b,c));return e};d.needCompass=function(a){return!0!==a.locateButton.highlightLocation||!0!==a.locateButton.useTracking||!0!==a.useCompass&&!0!==a.useAccCircle?!1:!0};d.checkPermission=function(){var a=new m;DeviceOrientationEvent&&DeviceOrientationEvent.requestPermission?DeviceOrientationEvent.requestPermission().then(f.hitch(this,function(b){"granted"==
b?a.resolve(!0):a.resolve(!1)})).catch(function(b){a.resolve(!1)}):a.resolve(!1);return a};return d});