/*
 COPYRIGHT 2009 ESRI

 TRADE SECRETS: ESRI PROPRIETARY AND CONFIDENTIAL
 Unpublished material - all rights reserved under the
 Copyright Laws of the United States and applicable international
 laws, treaties, and conventions.

 For additional information, contact:
 Environmental Systems Research Institute, Inc.
 Attn: Contracts and Legal Services Department
 380 New York Street
 Redlands, California, 92373
 USA

 email: contracts@esri.com
 */

window[esri._dojoScopeName||"dojo"]._xdResourceLoaded(function(_1,_2,_3){return {depends:[["provide","esri.tasks.PrintTask"],["require","esri.tasks._task"],["require","esri.tasks.gp"]],defineResource:function(_4,_5,_6){if(!_4._hasResource["esri.tasks.PrintTask"]){_4._hasResource["esri.tasks.PrintTask"]=true;_4.provide("esri.tasks.PrintTask");_4.require("esri.tasks._task");_4.require("esri.tasks.gp");_4.declare("esri.tasks.PrintTask",esri.tasks._Task,{constructor:function(_7){this.url=_7;this._handler=_4.hitch(this,this._handler);},_handler:function(_8,io,_9,_a,_b){try{var _c=_8[0].value;this._successHandler([_c],"onComplete",_9,_b);}catch(err){this._errorHandler(err,_a,_b);}},execute:function(_d,_e,_f){var _10=this._handler,_11=this._errorHandler;var _12=new esri.tasks.Geoprocessor(this._url.path);var _13=_d.template?_d.template:new esri.tasks.PrintTemplate();var _14=_13.exportOptions;var _15;if(_14){var _16=_14.width;var _17=_14.height;var dpi=_14.dpi;_15={outputSize:[_16,_17],dpi:dpi};}if(_13.preserveScale===false){this._preserveScale=false;}else{this._preserveScale=true;}var _18=_13.layoutOptions;var _19,_1a=[];if(_18){this.legendAll=false;if(!_18.legendLayers){this.legendAll=true;}else{_4.forEach(_18.legendLayers,function(_1b,idx){_1a.push({id:_1b});});}var _1c,_1d;if(_18.scalebarUnit==="Miles"||_18.scalebarUnit==="Kilometers"){_1c="Kilometers";_1d="Miles";}else{if(_18.scalebarUnit==="Meters"||_18.scalebarUnit==="Feet"){_1c="Meters";_1d="Feet";}}var _1e={Miles:"mi",Kilometers:"km",Yards:"yd",Feet:"ft",Meters:"m"};_19={titleText:_18.titleText,authorText:_18.authorText,copyrightText:_18.copyrightText,scaleBarOptions:{metricUnit:_1c,metricLabel:_1e[_1c],nonMetricUnit:_1d,nonMetricLabel:_1e[_1d]},legendOptions:{operationalLayers:_1a}};}var map=_d.map;var _1f=this._getPrintDefinition(map);_4.mixin(_1f,{exportOptions:_15,layoutOptions:_19});if(this.allLayerslegend){_4.mixin(_1f.layoutOptions,{legendOptions:{operationalLayers:this.allLayerslegend}});}var _20=_4.toJson(_1f);var _21=_13.format;var _22=_13.layout;var _23={Web_Map_as_JSON:_20,Format:_21,Layout_Template:_22};var dfd=new _4.Deferred(esri._dfdCanceller);var _24=function(r,i){_10(r,i,_e,_f,dfd);};var _25=function(r){_11(r,_f,dfd);};dfd._pendingDfd=_12.execute(_23,_24,_25);return dfd;},onComplete:function(){},_multipointLayer:function(){this.layerDefinition={name:"multipointLayer",geometryType:"esriGeometryMultipoint",drawingInfo:{renderer:null},fields:[{name:"fake",type:"esriFieldTypeInteger"}]};this.featureSet={geometryType:"esriGeometryMultipoint",features:[]};},_polygonLayer:function(){this.layerDefinition={name:"polygonLayer",geometryType:"esriGeometryPolygon",drawingInfo:{renderer:null},fields:[{name:"fake",type:"esriFieldTypeInteger"}]};this.featureSet={geometryType:"esriGeometryPolygon",features:[]};},_pointLayer:function(){this.layerDefinition={name:"pointLayer",geometryType:"esriGeometryPoint",drawingInfo:{renderer:null},fields:[{name:"fake",type:"esriFieldTypeInteger"}]};this.featureSet={geometryType:"esriGeometryPoint",features:[]};},_polylineLayer:function(){this.layerDefinition={name:"polylineLayer",geometryType:"esriGeometryPolyline",drawingInfo:{renderer:null},fields:[{name:"fake",type:"esriFieldTypeInteger"}]};this.featureSet={geometryType:"esriGeometryPolyline",features:[]};},_createFeatureCollection:function(_26){var _27=new this._polygonLayer();var _28=new this._polylineLayer();var _29=new this._pointLayer();var _2a=new this._multipointLayer();var _2b,_2c=0,_2d=0,_2e=0,_2f=0;_4.forEach(_26.graphics,function(g,idx){if(g.geometry.type==="polygon"){_2e++;_2b=g.toJson();if(!_2b.attributes){_2b.attributes={fake:_2e};}_27.featureSet.features.push(_2b);if(_26.renderer){_27.layerDefinition.drawingInfo.renderer=_26.renderer.toJson();}if(_26.fields){_27.layerDefinition.fields=_26.fields;}}else{if(g.geometry.type==="polyline"){_2d++;_2b=g.toJson();if(!_2b.attributes){_2b.attributes={fake:_2d};}_28.featureSet.features.push(_2b);if(_26.renderer){_27.layerDefinition.drawingInfo.renderer=_26.renderer.toJson();}if(_26.fields){_27.layerDefinition.fields=_26.fields;}}else{if(g.geometry.type==="point"){_2c++;_2b=g.toJson();if(!_2b.attributes){_2b.attributes={fake:_2c};}_29.featureSet.features.push(_2b);if(_26.renderer){_27.layerDefinition.drawingInfo.renderer=_26.renderer.toJson();}if(_26.fields){_27.layerDefinition.fields=_26.fields;}}else{if(g.geometry.type==="multipoint"){_2f++;_2b=g.toJson();if(!_2b.attributes){_2b.attributes={fake:_2f};}_2a.featureSet.features.push(_2b);if(_26.renderer){_27.layerDefinition.drawingInfo.renderer=_26.renderer.toJson();}if(_26.fields){_27.layerDefinition.fields=_26.fields;}}}}}},this);var _30=[];if(_29.featureSet.features.length>0){_30.push(_29);}if(_28.featureSet.features.length>0){_30.push(_28);}if(_27.featureSet.features.length>0){_30.push(_27);}if(_2a.featureSet.features.length>0){_30.push(_2a);}var _31={layers:_30};var _32={id:_26.id,opacity:_26.opacity,featureCollection:_31};return _32;},_getPrintDefinition:function(map){var _33=this._createOperationalLayers(map);var _34={operationalLayers:_33};var _35={mapOptions:{extent:map.extent.toJson(),spatialReference:map.spatialReference.toJson()}};if(this._preserveScale){_4.mixin(_35.mapOptions,{scale:esri.geometry.getScale(map)});}if(map.timeExtent){_4.mixin(_35.mapOptions,{time:[map.timeExtent.startTime.getTime(),map.timeExtent.endTime.getTime()]});}var _36={};_4.mixin(_36,_35,_34);return _36;},_createOperationalLayers:function(map){var i,_37,_38,_39,_3a=[];if(this.legendAll){this.allLayerslegend=[];}else{this.allLayerslegend=null;}for(i=0;i<map.layerIds.length;i++){_37=map.getLayer(map.layerIds[i]);if(!_37.loaded||!_37.visible){continue;}if(_37.credential){_37.url+="?token="+_37.credential.token;}_38=_37.declaredClass;switch(_38){case "esri.layers.ArcGISDynamicMapServiceLayer":var _3b=[];if(_37._params.dynamicLayers){var _3c=_4.fromJson(_37._params.dynamicLayers);_4.forEach(_3c,function(_3d,idx){_3b.push({id:_3d.id,layerDefinition:_3d});});}else{_4.forEach(_37.layerInfos,function(_3e,idx){var _3f={id:_3e.id,layerDefinition:{definitionExpression:null,layerTimeOptions:null}};if(_37.layerDefinitions&&_37.layerDefinitions[_3e.id]){_3f.layerDefinition.definitionExpression=_37.layerDefinitions[_3e.id];}if(_37.layerTimeOptions&&_37.layerTimeOptions[_3e.id]){_3f.layerDefinition.layerTimeOptions=_37.layerTimeOptions[_3e.id];}_3b.push(_3f);});}_39={id:_37.id,url:_37.url,title:_37.id,opacity:_37.opacity,visibleLayers:_37.visibleLayers,layers:_3b};_3a.push(_39);if(this.allLayerslegend){this.allLayerslegend.push({id:_37.id,subLayerIds:_37.visibleLayers});}break;case "esri.layers.ArcGISImageServiceLayer":_39={id:_37.id,url:_37.url,title:_37.id,opacity:_37.opacity,bandIds:_37.bandIds,compressionQuality:_37.compressionQuality,format:_37.format,interpolation:_37.interpolation};if(_37.mosaicRule){_4.mixin(_39,{mosaicRule:_37.mosaicRule.toJson()});}if(_37.renderingRule){_4.mixin(_39,{renderingRule:_37.renderingRule.toJson()});}_3a.push(_39);if(this.allLayerslegend){this.allLayerslegend.push({id:_37.id});}break;case "esri.layers.WMSLayer":var _40=_37.imageFormat.split("/")[1];if(_40.toLowerCase()==="png"){_40="png32";}_39={id:_37.id,url:_37.url,title:_37.title,opacity:_37.opacity,type:"wms",version:_37.version,format:_40,transparentBackground:_37.imageTransparency,visibleLayers:_37.visibleLayers};_3a.push(_39);if(this.allLayerslegend){this.allLayerslegend.push({id:_37.id,subLayerIds:_37.visibleLayers});}break;case "esri.virtualearth.VETiledLayer":_39={id:_37.id,visibility:_37.visible,type:"BingMaps"+_37.mapStyle,culture:_37.culture,opacity:_37.opacity};_3a.push(_39);break;case "esri.layers.OpenStreetMapLayer":_39={id:_37.id,title:_37.id,type:"OpenStreetMap",opacity:_37.opacity,url:_37.tileServers[0]};_3a.push(_39);break;case "esri.layers.WMTSLayer":_39={id:_37.id,url:_37.url,title:_37.id,opacity:_37.opacity,type:"wmts",layer:_37.layerInfos[0].identifier,style:_37.layerInfos[0].style,format:_37.layerInfos[0].format,tileMatrixSet:_37.layerInfos[0].tileMatrixSet};_3a.push(_39);break;case "esri.layers.KMLLayer":_39={id:_37.id,title:_37.id,type:"KML",url:_37.url,opacity:_37.opacity};_3a.push(_39);if(this.allLayerslegend){this.allLayerslegend.push({id:_37.id});}break;case "esri.layers.MapImageLayer":var _41=_37.getImages();_4.forEach(_41,function(_42,idx){_39={id:_37.id+"_image"+idx,type:"image",title:_37.id,opacity:_37.opacity,extent:_42.extent.toJson(),url:_42.href};_3a.push(_39);});break;default:if(_37 instanceof esri.layers.TiledMapServiceLayer||_37 instanceof esri.layers.DynamicMapServiceLayer){_39={id:_37.id,url:_37.url,title:_37.id,opacity:_37.opacity};_3a.push(_39);}}}for(i=0;i<map.graphicsLayerIds.length;i++){_37=map.getLayer(map.graphicsLayerIds[i]);if(!_37.loaded||!_37.visible){continue;}_38=_37.declaredClass;switch(_38){case "esri.layers.FeatureLayer":if(_37.url){_39={id:_37.id,url:_37.url,title:_37.id,opacity:_37.opacity,minScale:_37.minScale,maxScale:_37.maxScale,layerDefinition:{drawingInfo:{renderer:_37.renderer.toJson()}}};if(_37.getDefinitionExpression()){_4.mixin(_39.layerDefinition,{definitionExpression:_37.getDefinitionExpression()});}if(_37.mode!==2){if(_37.getSelectedFeatures().length>0){var _43=_4.map(_37.getSelectedFeatures(),function(_44){return _44.attributes[_37.objectIdField];});_4.mixin(_39,{selectionObjectIds:_43,selectionSymbol:_37.getSelectionSymbol().toJson()});}}else{var _45=_4.map(_37.getSelectedFeatures(),function(_46){return _46.attributes[_37.objectIdField];});_4.mixin(_39.layerDefinition,{objectIds:_45});var _47=new esri.renderer.SimpleRenderer(_37.getSelectionSymbol());_4.mixin(_39.layerDefinition.drawingInfo,{renderer:_47.toJson()});}}else{_39=this._createFeatureCollection(_37);}_3a.push(_39);if(this.allLayerslegend){this.allLayerslegend.push({id:_37.id});}break;case "esri.layers.GraphicsLayer":_39=this._createFeatureCollection(_37);_3a.push(_39);if(this.allLayerslegend){this.allLayerslegend.push({id:_37.id});}break;default:}}if(map.graphics&&map.graphics.graphics.length>0){_39=this._createFeatureCollection(map.graphics);_3a.push(_39);}return _3a;}});_4.declare("esri.tasks.PrintParameters",null,{map:null,template:null});_4.declare("esri.tasks.PrintTemplate",null,{label:null,exportOptions:{width:800,height:1100,dpi:96},layoutOptions:null,format:"PNG32",layout:"MAP_ONLY",preserveScale:true});}}};});