Solved! Go to Solution.
define( [ "dojo/_base/declare", "esri/layers/ArcGISImageServiceLayer" ], function( declare, ArcGISImageServiceLayer ) { var MyImageServiceLayer = declare([ArcGISImageServiceLayer], { declaredClass: "esri.layers.ArcGISImageServiceLayer" }); return MyImageServiceLayer; }); var map, layer; require(["esri/map", "esri/layers/MyImageServiceLayer", "esri/dijit/Print", "dojo/domReady!"], function (Map, MyImageServiceLayer, Print) { esri.config.defaults.io.proxyUrl = "/proxy.ashx";//use your own proxy instead of this. map = new Map("map", { basemap: "gray", center: [-80.85, 35.22], zoom: 14 }); var print = new Print({ map: map, url: "http://sampleserver6.arcgisonline.com/arcgis/rest/services/Utilities/PrintingTools/GPServer/Export%20Web%20Map%20Task" }, "print"); print.startup(); layer = new MyImageServiceLayer("http://sampleserver6.arcgisonline.com/arcgis/rest/services/CharlotteLAS/ImageServer"); map.addLayer(layer); layer.on("load", function () { layer.renderingRule = { "rasterFunction": "RFTShadedReliefElevationColorRamp" }; layer.renderingRule.toJson = function () { return { "rasterFunction": "RFTShadedReliefElevationColorRamp" }; }; layer.setRenderingRule(layer.renderingRule); }); });
require(["esri/tasks/PrintTask","esri/tasks/PrintParameters","esri/tasks/PrintTemplate","mapui","mainmodel"],
function(PrintTask,PrintParameters,PrintTemplate,MapUI,MainModel){
var printConfig = Config.getConfig().print,
printTask = new PrintTask(printConfig.url),
params = new PrintParameters(),
viewModel = MainModel.getVM();
params.map = MapUI.getMap();
params.template = new PrintTemplate();
params.template.label = printConfig.template.label;
params.template.format = printConfig.template.format;
params.template.layout = printConfig.template.layout;
params.template.layoutOptions = printConfig.template.layoutOptions;
var languageIsEnglish = (query(".selectedLanguage")[0].id === "languageEnglish");
if(languageIsEnglish)
viewModel.printMap("Printing");
else
viewModel.printMap("Printing");
printTask.execute(params,function(response){
window.open(response.url);
if(languageIsEnglish)
viewModel.printMap("Print");
else
viewModel.printMap("Cetak");
},function(error){
if(languageIsEnglish)
viewModel.printMap("Print");
else
viewModel.printMap("Cetak");
});
});
print: {
url:"http://gis-stage.wri.org/arcgis/rest/services/Utilities/PrintingTools/GPServer/Export%20Web%20Map%20Task",
template: {
label:"Map",
format:"PNG32",
layout:"A4 Landscape",
layoutOptions: {
titleText: "Suitability Map",
authorText: "WRI & esri",
copyrightText: "WRI",
scalebarUnit: "Miles"
}
}
}
getImageUrl: function (extent, width, height, callback,options) {
var _self = this;
var bbox = [extent.xmin, extent.ymin, extent.xmax, extent.ymax],
params,
min,
max,
tempArray,
membership_arguments;
var rasterFunction = _self.getRenderingRule();
if (options) {
params = options;
params['renderingRule'] = JSON.stringify(rasterFunction);
params['bbox'] = bbox.join(",");
callback(_self.url + "/exportImage?",params);
}
else {
params = {
noData: 0,
noDataInterpretation: "esriNoDataMatchAny",
interpolation: "RSP_BilinearInterpolation",
renderingRule: JSON.stringify(rasterFunction),
format: "png8",
size: width + "," + height,
imageSR: 3857,
bboxSR: 3857,
f: "image",
pixelType: 'U8',
bbox: bbox.join(",")
};
callback(_self.url + "/exportImage?" + dojo.objectToQuery(params));
}
},
PrintTask includes renderingRule if that property exists in your layer. Please check yourCustomImageServiceLayer.renderingRule is there, and yourCustomImageServiceLayer.renderingRule.toJson() is a valid function.
"{"rasterFunction":"PalmOilSuitabilityNew","rasterFunctionArguments":{"ElevRaster":"$1","SlopeRaster":"$2","WaterRaster":"$3","ConsRaster":"$4","STypeRaster":"$5","SDepthRaster":"$6","PeatRaster":"$7","SAcidRaster":"$8","SDrainRaster":"$9","RainfallRaster":"$10","LCRaster":"$11","ElevInpR":[0,100,100,1000000],"ElevOutV":[1,0],"SlopeInpR":[0,30,30,1000000],"SlopeOutV":[1,0],"WaterInpR":[0,10,10,1000000],"WaterOutV":[0,1],"ConsInpR":[0,10,10,1000000],"ConsOutV":[0,1],"RainfallInpR":[0,150,150,700,700,1000000],"RainfallOutV":[1,1,0],"SDepthInpR":[0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7],"SDepthOutV":[1,0,0,0,1,1,1,1],"PeatInpR":[0,0,1,1,2,2,3,3,4,4,5,5,6,6],"PeatOutV":[1,0,0,0,0,0,0],"SAcidInpR":[0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7],"SAcidOutV":[1,1,1,1,1,1,1,1],"SDrainInpR":[0,0,1,1,2,2,3,3,4,4],"SDrainOutV":[1,0,1,1,1],"LCInpR":[0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8],"LCOutV":[1,1,1,1,0,0,0,0,0],"STypeInpR":[1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10],"STypeOutV":[1,1,1,0,1,1,1,1,1,0]}}"
{
"mapOptions": {
"showAttribution": true,
"extent": {
"xmin": -9002667.410873475,
"ymin": 4193183.580948897,
"xmax": -8996552.448610498,
"ymax": 4195815.881110537,
"spatialReference": {
"wkid": 102100
}
},
"spatialReference": {
"wkid": 102100
},
"scale": 18055.954822005082
},
"operationalLayers": [
{
"id": "layer0",
"title": "layer0",
"opacity": 1,
"minScale": 591657527.591555,
"maxScale": 9027.977411,
"url": "http://services.arcgisonline.com/ArcGIS/rest/services/Canvas/World_Light_Gray_Base/MapServer"
},
{
"id": "layer2",
"title": "layer2",
"opacity": 1,
"minScale": 0,
"maxScale": 0,
"url": "http://sampleserver6.arcgisonline.com/arcgis/rest/services/CharlotteLAS/ImageServer",
"bandIds": null,
"compressionQuality": null,
"interpolation": null,
"renderingRule": {
"rasterFunction": "RFTShadedReliefElevationColorRamp"
}
},
{
"id": "layer1",
"title": "layer1",
"opacity": 1,
"minScale": 591657527.591555,
"maxScale": 9027.977411,
"url": "http://services.arcgisonline.com/ArcGIS/rest/services/Canvas/World_Light_Gray_Reference/MapServer"
},
{
"id": "map_graphics",
"minScale": 0,
"maxScale": 0,
"featureCollection": {
"layers": []
}
}
],
"exportOptions": {
"outputSize": [
800,
1100
],
"dpi": 96
}
}
Can you post the web map json sent to print service?
require(["esri/request"], function(request) {
request.setRequestPreCallback(function(ioArgs) {
// if request is to the PrintingTools url
// Get my Image Service Layer from ioArgs.content.Web_Map_as_JSON
// Add in my rendering rule and rasterFunctionArguments
// replace webmap JSON with updated JSON and request now uses POST instead of GET
return ioArgs;
});
});