// 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/dijit/geoenrichment/ReportPlayer/dataProviders/commands/supportClasses/MapToImageUtil","dojo/Deferred dojo/when dojo/dom-construct dojo/dom-style dojo/promise/all esri/tasks/PrintTask esri/tasks/PrintParameters esri/tasks/PrintTemplate esri/dijit/geoenrichment/utils/UrlUtil esri/dijit/geoenrichment/utils/ImageInfoUtil esri/dijit/geoenrichment/utils/ImageUtil".split(" "),function(m,f,g,b,n,q,r,t,u,v,w){var h={mapToURL:function(a,e,d){d=function(a){a=a||"https://utility.arcgisonline.com/arcgis/rest/services/Utilities/PrintingTools/GPServer/Export Web Map Task";
u.registerCORS(a);return a}(d.printMapTaskUrl);d=new q(d);var c=new r;c.map=a;a=new t;a.exportOptions={width:3.125*b.get(e,"width"),height:3.125*b.get(e,"height"),dpi:300};a.format="png32";a.showAttribution=!1;c.template=a;return f(d.execute(c),function(a){var c=new m;setTimeout(function(){c.resolve(a.url)},100);return c.promise})},urlToSrc:function(a,e){return e.saveImagesAsBase64?v.getRemoteImageDataUrl(a,{sizeLimit:1500}):a}},p={replaceMapWithImage:function(a){for(var e=[];a.children.length;)e.push(a.firstChild),
a.removeChild(a.firstChild);var d=b.get(a,"position"),c=g.create("img",{"class":"esriGEAbsoluteStretched"},a);b.set(c,{width:b.get(a,"width")+"px",height:b.get(a,"height")+"px"});b.set(a,"position","relative");return{mapImage:c,undo:function(){g.destroy(c);b.set(a,"position",d);e.forEach(function(c){g.place(c,a)})}}}};return{replaceMapWithImage:function(a,e){var d=[],c={errors:[],undo:function(){d.map(function(a){a()})}},b=a.collectMaps({allAreas:e.allAreas}),k=[];return n(b.map(function(a){return f(h.mapToURL(a.map,
a.node,e),function(c){var b=p.replaceMapWithImage(a.node);d.push(b.undo);k.push(a);var l=new m;b.mapImage.onload=l.resolve;b.mapImage.onerror=function(a){console.log(a);g.destroy(b.mapImage);l.resolve()};f(h.urlToSrc(c,e),function(a){b.mapImage.src=a});return l.promise})})).always(function(){k.length!==b.length&&(b.forEach(function(a){-1===k.indexOf(a)&&(a=p.replaceMapWithImage(a.node),d.push(a.undo))}),c.errors.push(Error("Some maps can't be exported")));return c})},collectMapsAsImages:function(a,
b){var d=a.collectMaps({allAreas:!0});return n(d.map(function(a){return f(h.mapToURL(a.map,a.node,b),function(a){return h.urlToSrc(a,b)}).otherwise(function(){return null}).then(function(b){return{url:b,itemId:a.itemId,areaIndex:a.areaIndex,position:a.position}})}))}}});