!function(e){"object"==typeof module&&"object"==typeof module.exports?e(require,exports):"function"==typeof define&&define.amd&&define(["require","exports","tslib","../../deps/bluebird_fork","../../activities/core/converters","./ArcGisApiVersion","esri/geometry/Extent","esri/request"],e)}(function(e,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var t=e("tslib"),r=t.__importDefault(e("../../deps/bluebird_fork")),a=e("../../activities/core/converters"),o=e("./ArcGisApiVersion"),s=t.__importDefault(e("esri/geometry/Extent")),e=t.__importDefault(e("esri/request"));function i(e){return"object"==typeof e.signal}function u(e){return null!=e&&"function"==typeof e.cancel}n.isAbortable=i,n.isCancellable=u,n.schedulePromiseCancellation=function(e,n){!i(e.cancellationToken)&&u(n)&&e.cancellationToken.finally(function(){return n.cancel()})},n.inline=function(e,n,t){return void 0===t&&(t=void 0),(e=r.default.resolve(e)).isFulfilled()?n(e.value()):e.isRejected()&&t?t(e.reason()):e.then(n,t)},n.addToPath=function(n,t){return n.replace(/([\#\?].*)?$/,function(e){return n.substr(0,n.length-e.length).match(/\/+$/)?t+e:"/"+t+e})},n.polygonFromExtent=function(e,n){var t;if(null!=e)return"number"==typeof(t=e).xmin&&("number"==typeof t.xmax&&("number"==typeof t.ymin&&"number"==typeof t.ymax))?new n({rings:[[[e.xmin,e.ymin],[e.xmax,e.ymin],[e.xmax,e.ymax],[e.xmin,e.ymax]]],spatialReference:e.spatialReference}):e};var m=e.default;function c(e){return null!=e&&(!Array.isArray(e)&&!!Array.isArray(e.features))}n.fetch=function(e,n,t,r){return o.isArcGisApiVersion3x&&(n.__ts=(new Date).valueOf()),function(e,n,t,r){if(n.f="json",o.isArcGisApiVersion3x){var i={url:e,content:a.jsonToQueryObject(n),handleAs:"json",timeout:t};return m(i)}return t={method:"get",query:a.jsonToQueryObject(n),responseType:"json",timeout:t,cacheBust:!1},r&&(t.signal=r),m(e,t).then(function(e){return e.data})}(e,n,t,r)},n.post=function(e,n,t,r){if(n.f="json",o.isArcGisApiVersion3x){var i={url:e,content:a.jsonToQueryObject(n),handleAs:"json",timeout:t};return m(i,{usePost:!0})}return t={method:"post",query:a.jsonToQueryObject(n),responseType:"json",timeout:t,cacheBust:!1},r&&(t.signal=r),m(e,t).then(function(e){return e.data})},n.isFeatureSet=c,n.featuresToArray=function(e){return null==e?[]:e instanceof Array?e:c(e)?e.features:void 0!==e.attributes&&null!==e.attributes||void 0!==e.geometry&&null!==e.geometry?[e]:[]},n.extentOf=function(e){for(var n=void 0,t=0,r=e||[];t<r.length;t++){var i,a=r[t];a&&("point"===a.type?(i=a,void 0===n?n=function(e){var n=new s.default;n.xmin=e.x,n.ymin=e.y,n.xmax=e.x,n.ymax=e.y,n.spatialReference=e.spatialReference,"number"==typeof e.z&&(n.zmin=e.z,n.zmax=e.z);return n}(i):(n.xmin=Math.min(n.xmin,i.x),n.ymin=Math.min(n.ymin,i.y),n.xmax=Math.max(n.xmax,i.x),n.ymax=Math.max(n.ymax,i.y),n.spatialReference=a.spatialReference||n.spatialReference,"number"==typeof i.z&&(n.zmin=Math.min(n.zmin,i.z),n.zmax=Math.max(n.zmax,i.z)))):null!=(i=o.isArcGisApiVersion3x?a.getExtent():a.extent)&&(void 0!==n?(n.xmin=Math.min(n.xmin,i.xmin),n.ymin=Math.min(n.ymin,i.ymin),n.xmax=Math.max(n.xmax,i.xmax),n.ymax=Math.max(n.ymax,i.ymax),n.spatialReference=a.spatialReference||n.spatialReference,"number"==typeof i.zmin&&(n.zmin=Math.min(n.zmin,i.zmin)),"number"==typeof i.zmax&&(n.zmax=Math.max(n.zmax,i.zmax))):n=i=!o.isArcGisApiVersion3x?i.clone():i))}return n},n.toEsriUnit=function(e){switch(e&&e.toLowerCase()){case"feet":return"9002";case"kilometers":return"9036";case"meters":return"9001";case"miles":return"9093";case"nautical-miles":return"109012";case"yards":return"109001";default:return e}}});