// All material copyright ESRI, All Rights Reserved, unless otherwise specified.
// See http://js.arcgis.com/3.23/esri/copyright.txt for details.
//>>built
define("esri/tasks/ImageServiceProjectTask","dojo/_base/declare dojo/_base/lang dojo/has dojo/_base/Deferred dojo/_base/array ../kernel ../request ../deferredUtils ./Task ../urlUtils ../geometry/jsonUtils".split(" "),function(c,k,f,n,p,q,r,t,u,v,l){c=c(u,{constructor:function(a){this._handler=k.hitch(this,this._handler)},execute:function(a,b,d){var e=new n(t._dfdCanceller),g=this._url||this._getImageServiceUrl(a);if(g){var w=this._encode(k.mixin({},g.query,{f:"json"},a.toJson())),h=this._handler,
m=this._errorHandler,c=l.getJsonType(a.geometries[0]),f=a.outSR;e._pendingDfd=r({url:g.path+"/project",content:w,callbackParamName:"callback",load:function(a){h(a,c,f,b,d,e)},error:function(a){m(a,d,e)}})}else e.reject("Input arguments do not contain image service URL.");return e},_handler:function(a,b,d,e,g,c){try{var h=this._decodeGeometries(a,b,d);this._successHandler([h],"onComplete",e,c)}catch(m){this._errorHandler(m,g,c)}},_encodeGeometries:function(a){var b=[],d,e=a.length;for(d=0;d<e;d++)b.push(a[d].toJson());
return{geometryType:l.getJsonType(a[0]),geometries:b}},_decodeGeometries:function(a,b,d){var e=l.getGeometryType(b),c=[],f={spatialReference:d},h=k.mixin;p.forEach(a.geometries,function(a,b){c[b]=new e(h(a,f))});return c},onComplete:function(){},_getImageServiceUrl:function(a){var b;if(a&&a.geometries&&a.geometries.length&&a.outSR)if(a.geometries[0].spatialReference||a.geometries[0].spatialReference.url||a.outSR.url)if(a.geometries[0].spatialReference.url&&a.outSR.url&&a.geometries[0].spatialReference.url!==
a.outSR.url)this.onError(Error("Input and output spatial reference must be from one image service"));else b=a.geometries[0].spatialReference&&a.geometries[0].spatialReference.url?a.geometries[0].spatialReference.url:a.outSR.url;else this.onError(Error("Spatial reference doesn't contain Image Service URL"));b&&(b=v.urlToObject(b));return b}});f("extend-esri")&&k.setObject("tasks.ImageServiceProjectTask",c,q);return c});