lzc45 2015-04-16 01:00 采纳率: 0%
浏览 5154

用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>  
  • 写回答

5条回答 默认 最新

  • 哈哈713 2016-04-24 06:50
    关注

    楼主这个问题解决了吗

    评论

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料