/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["exports","../../config","../../core/Error","../../core/has","../../core/Logger","../../geometry/Point","../../geometry/support/webMercatorUtils","../../portal/Portal","../../chunks/_rollupPluginBabelHelpers","../../request","../../core/arrayUtils","../../core/urlUtils","../../geometry","../../geometry/Extent","../../geometry/Geometry","../../geometry/Multipoint","../../geometry/Polygon","../../geometry/Polyline","../../rest/geometryService/units","../../rest/operations/generalize","../../rest/support/GeneralizeParameters","../../rest/operations/lengths","../../rest/support/LengthsParameters","../../rest/operations/offset","../../rest/support/OffsetParameters","../../rest/geometryService/project","../../rest/operations/relation","../../rest/support/RelationParameters","../../rest/operations/trimExtend","../../rest/support/TrimExtendParameters","../../rest/support/ProjectParameters"],(function(e,t,r,o,i,n,s,u,c,a,l,g,p,m,d,y,f,P,h,v,w,S,b,x,U,G,M,R,T,j,A){"use strict";const E=i.getLogger("esri.widgets.support.geolocationUtils"),L={maximumAge:0,timeout:15e3,enableHighAccuracy:!0};function z(){const e=o("esri-geolocation");return e||E.warn("geolocation-unsupported","Geolocation unsupported."),e}function C(){const e=window.isSecureContext;return e||E.warn("insecure-context","Geolocation requires a secure origin."),e}function W(){return z()&&C()}function _(e){const t=15e3;return e||(e=L),new Promise(((o,i)=>{setTimeout((()=>i(new r("geolocation:timeout","getting the current geolocation position timed out"))),t),navigator.geolocation.getCurrentPosition(o,i,e)}))}function k(e,t){const{position:r,view:o}=e;return O(H(q(r)),o,t)}function q(e){const t=e&&e.coords||{},r={accuracy:t.accuracy,altitude:t.altitude,altitudeAccuracy:t.altitudeAccuracy,heading:t.heading,latitude:t.latitude,longitude:t.longitude,speed:t.speed};return e?{coords:r,timestamp:e.timestamp}:e}function H(e){const t=e&&e.coords;return t?new n({longitude:t.longitude,latitude:t.latitude,z:t.altitude||null,spatialReference:{wkid:4326}}):null}function O(e,t,o){if(!t)return Promise.resolve(e);const i=t.spatialReference;return i.isWGS84?Promise.resolve(e):i.isWebMercator?Promise.resolve(s.geographicToWebMercator(e)):B(o).then((t=>{if(!t)throw new r("geometry-service:missing-url","Geometry service URL is missing");const n=new A({geometries:[e],outSpatialReference:i});return G.project(t,n,o).then((e=>e[0]))}))}function B(e){if(t.geometryServiceUrl)return Promise.resolve(t.geometryServiceUrl);const r=u.getDefault();return r.load(e).catch((()=>{})).then((()=>r.get("helperServices.geometry.url")))}e.getCurrentPosition=_,e.positionToPoint=k,e.supported=W,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
