arcgis JavaScript调用GP服务自动生成等值面

  首先创建模型



共享为服务之后开始调用,本例子需要的两个参数均从webservice获取:雨量YL数据和裁剪范围

源代码如下:仅供参考

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <!--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>GP Task Population Zonal Stats</title>


    <link rel="stylesheet" href="http://js.arcgis.com/3.14/dijit/themes/claro/claro.css">
    <link rel="stylesheet" href="http://js.arcgis.com/3.14/esri/css/esri.css">
    <style>
        html, body, #map {
            height: 100%;
            width: 100%;
            margin: 0;
            padding: 0;
        }


        body {
            background-color: #FFF;
            overflow: hidden;
            font-family: "Trebuchet MS";
        }


       
    </style>
    <script src="http://js.arcgis.com/3.14/"></script>


    <!--
    <script src="jsapi_vsdoc10_v33.js" type="text/javascript"></script>
    -->
    <script>




        dojo.require("esri.map");
        dojo.require("esri.graphic");
        dojo.require("esri/graphicsUtils");
        dojo.require("esri/tasks/Geoprocessor");
        dojo.require("esri/tasks/FeatureSet");
        dojo.require("esri/tasks/JobInfo");
        dojo.require("esri.tasks.query");
        dojo.require("esri.layers.FeatureLayer");






        var map, gp, dynamic, query, query1, featureSet, featureSet1, myfeatureSet;




        function init() {
            //底图 rest
            var mapurl = "http://localhost:6080/arcgis/rest/services/sichuanshengbianjie/MapServer/";
            map = new esri.Map("map");
            dynamic = new esri.layers.ArcGISDynamicMapServiceLayer(mapurl);
            map.addLayer(dynamic);


            //注册map的点击事件,
            dojo.connect(map, "onClick", findHotspot);


        }


        //加载dom
        dojo.ready(init);




        function findHotspot() {


            // gp服务地址
            var gpServiceUrl = "http://localhost:6080/arcgis/rest/services/contour/GPServer/ContourServiceSO2";
            //创建gp服务
            var gp = new esri.tasks.Geoprocessor(gpServiceUrl);
            gp.outSpatialReference = map.spatialReference;
            //获取rainpoint YL数据
            featureLayer = new esri.layers.FeatureLayer("http://localhost:6080/arcgis/rest/services/rainpoint/MapServer/0");
            require([
  "esri/tasks/query"
            ], function (Query) {
                query = new Query();
                query1 = new Query();
            });
         
            query.returnGeometry = true;
            query.outFields = ["YL"];
            query.where = "1>0";
            query.OutputSpatialReference = "4214";


            featureLayer.queryFeatures(query, function (fs) {
                featureSet = fs;


                //获取边界
                featureLayer1 = new esri.layers.FeatureLayer("http://localhost:6080/arcgis/rest/services/sichuanshengbianjie/MapServer/0");
                query1.returnGeometry = true;
                query1.where = "1>0";
                query1.OutputSpatialReference = "4214";
                featureLayer1.queryFeatures(query1, function (fs1) {
                    featureSet1 = fs1;




                    //设置GP服务输入参数
                    var params = {
                        "输入点要素": featureSet,
                        "四川省边界": featureSet1
                    };
                    //cleanup any results from previous runs
                    // cleanup();
                    //执行gp服务,调用回调函数,显示执行结果
                    gp.submitJob(params, addResults);        // gpJobComplete, gpJobStatus, gpJobFailed


                });




            });




        }




        //construct the result map service url using the id from jobinfo we'll add a new layer to the map
        //gp完成后的回调函数,获取处理结果


        function addResults(jobinfo) {


            //construct the result map service url using the id from jobinfo we'll add a new layer to the map
            var mapurlll = "http://localhost:6080/arcgis/rest/services/contour/MapServer/jobs" + "/" + jobinfo.jobId;
            hotspotLayer = new esri.layers.ArcGISDynamicMapServiceLayer(mapurlll


                );


            //add the hotspot layer to the map
            map.addLayer(hotspotLayer);


        }






    </script>
</head>
<body class="claro">
    <div id="map"></div>
    <div data-dojo-type="dijit.layout.BorderContainer" data-dojo-props="design,'headline',gutters:false">
        <div id="map" data-dojo-type="dijit.layout.ContentPane" data-dojo-props="region:'center'">
        </div>


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



点击地图生成,结果如图


  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值