用ArcGIS JavaScript api怎样将GP服务的执行结果(栅格数据)添加到页面上

我的GP 服务是对遥感影像进行水体信息提取,gp服功能能够实现,可是在将结果添加到页面时却不能实现, gp.getResultImageLayer(jobInfo.jobId, "water", imageParams, function (gpLayer) {
gpLayer.setOpacity(0.5);
map.addLayer(gpLayer);
});这句代码总是不能实现求个为前辈帮帮忙,谢谢!

 <!DOCTYPE html>  
<html>  
  <head>  
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">  
    <meta http-equiv="X-UA-Compatible" content="IE=7, IE=9">  
    <meta name="viewport" content="width=device-width,user-scalable=no">  
    <!--The viewport meta tag is used to improve the presentation and behavior of the samples on iOS devices-->  
    <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">  
    <title>影像处理系统</title>  

    <link rel="stylesheet" type="text/css" href="http://localhost:8080/arcgis_js_api/library/3.3/jsapi/js/dojo/dijit/themes/tundra/tundra.css"/> 
    <link rel="stylesheet" type="text/css" href="http://localhost:8080/arcgis_js_api/library/3.3/jsapi/js/esri/css/esri.css" /> 
    <link rel="stylesheet" href="http://localhost:8080/arcgis_js_api/library/3.3/js/dojo/dijit/themes/claro/claro.css"> 
    <style>  
      html, body {   
        height: 100%; width: 100%; margin: 0; padding: 0;  
      }  
    </style>  
    <script>var dojoConfig = {   
        parseOnLoad: true   // 解析加载  
    };</script>  
    <script  src="http://localhost:8080/arcgis_js_api/library/3.3/jsapi/init.js"></script>

    <script>  

    dojo.require("dijit.layout.BorderContainer");
    dojo.require("dijit.layout.ContentPane");
    dojo.require("esri.map");
    dojo.require("esri.toolbars.draw");
    dojo.require("esri.tasks.gp");

    var map, toolbar, gp;
 function init() {
         map = new esri.Map("map");
         basemap = new esri.layers.ArcGISDynamicMapServiceLayer("http://localhost:6080/arcgis/rest/services/LZC/MyMapService/MapServer");
         map.addLayer(basemap);
      dojo.connect(map, 'onLoad', createToolbar);
    }

//选取水体提取范围
     function drawPolygon1() {
        alert("请选择提取范围!");
        flge=1;
      toolbar.activate(esri.toolbars.Draw.POLYGON);
    }
//选取植被提取范围
    function drawPolygon2() {
        alert("请选择提取范围!");
        flge=2;
         toolbar.activate(esri.toolbars.Draw.POLYGON);
    }
//绘制裁剪范围    
  function createToolbar(themap) {  
        dojo.connect(dijit.byId('map'), 'resize', map, map.resize);
        toolbar = new esri.toolbars.Draw(map);  // esri.toolbars.Draw(map, options) 
        dojo.connect(toolbar, "onDrawEnd", drawEnd);   // 绘制完成触发  
      }   
//定义裁剪范围symbol
    function drawEnd(geometry) {
       toolbar.deactivate();
       var symbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_DASHDOT, new dojo.Color([255, 0, 0]), 2), new dojo.Color([255, 255, 0, 0.25]));
       var graphic = new esri.Graphic(geometry, symbol);
       map.graphics.add(graphic);
      tojob(graphic);
    }

//传递参数以及调用服务
    function tojob(graphic) {
         //第一步构造GP
        var gpUrl ="http://localhost:6080/arcgis/rest/services/GPP/water/GPServer/water";
        gp = new esri.tasks.Geoprocessor(gpUrl);
         //第二步,构造参数
     //我们通过上面,了解到GPFeatureRecordSetLayer对应FeatureSet
    var features = [];
    features.push(graphic);
    var featureset = new esri.tasks.FeatureSet();
    featureset.features = features;
    var parms = {
        polygon  : featureset

    };
    //这里函数是异步的,使用函数是submitJob,同步的使用的是execute。
    //成功之后,调用jobResult,建议看一下这个参数。
    gp.submitJob(parms, jobResult);
}

function jobResult(result){
    var jobId = result.jobId;
    var status = result.jobStatus;
    if (status === esri.tasks.JobInfo.STATUS_SUCCEEDED) {
        //成功之后,将其中的结果取出来,当然这也是参数名字。
        //在模型中,想要取出中间结果,需要设置为模型参数
        alert("调用成功");
        gp.getResultData(jobId, "water", completeCallback1);
        }
    }

//添加最后提取结果
    function completeCallback1(jobInfo){
        imageParams = new esri.layers.ImageParameters();
        imageParams.format = "tif";
        imageParams.imageSpatialReference = new esri.SpatialReference({wkid: 4326});
        imageParams.layerOption = esri.layers.ImageParameters.LAYER_OPTION_SHOW;
        alert("准备添加结果!");
        gp.getResultImageLayer(jobInfo.jobId, "water", imageParams, function(gpLayer){
            gpLayer.setOpacity(0.5);
            map.addLayer(gpLayer);
        });
        alert("添加成功!");
    }

dojo.addOnLoad(init);

</script>  
</head>  
  <body class="tundra">  

<div id="mainWindow" data-dojo-type="dijit.layout.BorderContainer" data-dojo-props="design:'headline'" style="width:100%; height:100%;">  
    <div id="header" data-dojo-type="dijit.layout.ContentPane" data-dojo-props="region:'right'" style="width:20%; height:100%;">  
      <span>功能<br/></span>  
      <hr>
      <input id="Button1" type="button" value="提取水体信息" onclick="drawPolygon1()" /><br><br>
      <input id="Button2" type="button" value="提取植被信息" onclick="drawPolygon2()" />
      <hr/>
      <div id="bookmark" > </div> 
      <hr/>
        图例:
    <div id="legendDiv"  style=" height:500px; overflow:auto; border:1px solid #000000;"></div></div> 

 <div id="map" data-dojo-type="dijit.layout.ContentPane" data-dojo-props="region:'left'" style="width:77.8%; height:100%;">  
 <div id="scaleBarDiv" > </div></div>  

</div>  
  </body>  
</html>  

楼主这个问题解决了吗

楼主,你好,问题解决了吗? 我也遇到这个问题。

我也遇到过,我是返回的内容超出了发布时的限定了。只要重新发布下,然后把“parameters”里面的“maximum number of records return by the server” 返回的长度改大点就好了。ords图片说明

我也遇到这个问题,说图片格式不支持怎么回事

挖个坟。
发布服务的时候,选择异步调用,勾中 “View results with a map service”,在调用时就能加载到地图中了。