如何用javascript api for arcgis调用有参数的GP服务
javascript代码:(个别变量没有说明,大家就就看看大概思路就好了,这是我的完整代码)
1 var linesCanlayer=null; 2 var gonCanlayer=null; 3 var legend; 4 var mapserviceurl="http://10.0.0.28/ArcGIS/rest/services/gon_linesCan/MapServer/jobs"; 5 var spaceFL=null; 6 7 8 //清除页面信息窗口、graphics图层 9 function clearselect() { 10 dojo.addOnLoad(function () { 11 if (map.graphics) { 12 map.graphics.clear(); 13 } 14 if (map.infoWindow) { 15 map.infoWindow.hide();} 16 if (linesCanlayer) { 17 map.removeLayer(linesCanlayer); 18 } 19 if (gonCanlayer) { 20 map.removeLayer(gonCanlayer); 21 } 22 }); 23 } 24 25 26 $(document).ready(function () { 27 28 // $("#wuCanGP").click(function () { 29 // gonlines(); 30 // }); 31 32 33 34 if (!this.IsPostBack) { 35 console.log("IsPostBack"); 36 } 37 $("#buttonWen").click(function () { 38 addMapServer(); 39 }); 40 41 $("#sqlBtn").click(function () { 42 var type=$("#AinsectType").val(); 43 var dataStart=$("#AdateStart").val(); 44 var dataEnd=$("#AdateEnd").val(); 45 $.ajax({ 46 url: "Handler/getData.ashx", //ShowDatas// 47 data: { inType: type, 48 handlerId: "3", startDates: dataStart, endDates:dataEnd 49 }, 50 dataType: "json", 51 success: function (result) { 52 if (result == null) { 53 console.log("一般处理程序中,数据传输错误"); 54 return; 55 } 56 else { 57 var idwfeatures = []; 58 spaceFL= new esri.layers.GraphicsLayer(); 59 var items = dojo.map(result.ds, function (feature) { 60 if( (feature.longitude=="") || (feature.latitude=="") ){}else{ 61 feature['YL']=feature.sumhv; //GP服务用的idw的字段是“YL”,之前没给它赋值 62 var wgs = new esri.SpatialReference({ "wkid": 4326 }); //球面 4326 平面 102113 63 //——获取用三层访问的数据,把它转换为球面 4326 的地图点,再用 var webMercator 确定转换为莫克托投影下的地图点 64 var latlng = new esri.geometry.Point(parseFloat(feature.longitude), parseFloat(feature.latitude), wgs); 65 var webMercator = esri.geometry.geographicToWebMercator(latlng); 66 var pt = new esri.geometry.Point(webMercator.x,webMercator.y, map.spatialReference); //问题第一部分主要出在这里 67 // var pt = new esri.geometry.Point(feature.longitude,feature.latitude, map.spatialReference); 68 var evtSymbol = new esri.symbol.SimpleMarkerSymbol().setColor("red").setSize(5); 69 var graphic = new esri.Graphic(pt, evtSymbol, feature); 70 spaceFL.add(graphic); 71 idwfeatures.push(graphic);} 72 }); 73 map.addLayer(spaceFL); 74 var idwfeatureSet = new esri.tasks.FeatureSet(); 75 idwfeatureSet.features = idwfeatures; 76 drawjob(idwfeatureSet); 77 } 78 }, 79 error: function () { alert("错误"); } 80 }); 81 82 83 }); 84 85 86 }); 87 function addMapServer() 88 { 89 var queryTask = new esri.tasks.QueryTask("http://10.0.0.28/ArcGIS/rest/services/insectPointSde/MapServer/0"); 90 var query = new esri.tasks.Query(); 91 query.outSpatialReference = { wkid: 102100 }; query.spatialRelationship = { wkid: 102100 }; //21480 92 query.returnGeometry = true; 93 query.outFields = ["*"]; 94 query.where = "1=1"; 95 queryTask.execute(query, addPoints); //将查询结果显示,和feature.selectFeatures的差别 96 } 97 98 function addPoints(featureSet) { 99 var idwfeatures = []; 100 spaceFL= new esri.layers.GraphicsLayer(); 101 var popupTemplate = esri.dijit.PopupTemplate({ 102 "title": "地图查询", 103 "fieldInfos": [ 104 { "fieldName": "Id", "label": "名称", visible: true }, 105 { "fieldName": "YL", "label": "昆虫总计数", visible: true } 106 ] 107 }); 108 var items = dojo.map(featureSet.features, function (feature) { 109 var evtSymbol = new esri.symbol.SimpleMarkerSymbol().setColor("blue").setSize(5); 110 var pt = new esri.geometry.Point(feature.geometry.x,feature.geometry.y, map.spatialReference); //问题第一部分主要出在这里 111 var graphic = new esri.Graphic(pt, evtSymbol, feature.attributes); 112 graphic.setInfoTemplate(popupTemplate); 113 idwfeatures.push(graphic); 114 spaceFL.add(graphic); 115 }); 116 map.addLayer(spaceFL); 117 var idwfeatureSet = new esri.tasks.FeatureSet(); 118 idwfeatureSet.features = idwfeatures; 119 drawjob(idwfeatureSet); 120 } 121 122 123 124 //#region drawPolygonPian生成湿度降水线 125 //生成湿度降水线 126 function drawjob(idwfeatureSet) { 127 clearselect(); 128 $("#gpinfo")[0].innerHTML="正在加载中……"; 129 $("#gpinfo")[0].style.visibility = "visible"; 130 //第一步构造GP 131 var gpUrl = 'http://10.0.0.28/ArcGIS/rest/services/gon_linesCan/GPServer/gon_linesCan'; 132 133 gp = new esri.tasks.Geoprocessor(gpUrl); 134 //第二步,构造参数 135 var fYLlayer= new esri.layers.ArcGISDynamicMapServiceLayer("http://10.0.0.28/ArcGIS/rest/services/insectPointSde/MapServer"); 136 var parms = {Input_point_features:idwfeatureSet}; 137 //这里函数是异步的,使用函数是submitJob,同步的使用的是execute。 138 //成功之后,调用jobResult,建议看一下这个参数。 139 gp.submitJob(parms, jobResultCan, statusCallback); 140 } 141 142 function statusCallback(jobInfo){ 143 if(jobInfo.jobStatus=="esriJobFailed"){ 144 $("#gpinfo")[0].innerHTML=jobInfo.jobStatus;} 145 console.log(jobInfo.jobStatus); 146 } 147 148 function jobResultCan(result) { 149 var jobId = result.jobId; 150 var status = result.jobStatus; 151 if (status === esri.tasks.JobInfo.STATUS_SUCCEEDED) { 152 var imageParams = new esri.layers.ImageParameters(); 153 // gp.getResultImageLayer(jobId, "Idw_gonclip", imageParams, displayResult); 154 // gp.getResultImageLayer(jobId, "Idw_lines_5_shp", imageParams, displayResultPian); 155 156 gp.getResultImageLayer(jobId, "Idw_gonclipc", imageParams, displayResultCan); 157 gp.getResultImageLayer(jobId, "Idw_lines_5c_shp", imageParams, displayResultgonCan); 158 } 159 } 160 161 162 function addResultsc(results) { 163 console.log(results); 164 var features = results.value.features; 165 for (var f = 0, fl = features.length; f < fl; f++) { 166 var feature = features[f]; 167 feature.setSymbol = new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([255, 255, 0]), 3); 168 //var polySymbolRed = new esri.symbol.SimpleMarkerSymbol(esri.symbol.SimpleMarkerSymbol.STYLE_SQUARE, 12, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([204, 102, 51]), 1), new dojo.Color([158, 184, 71, 1])); 169 //feature.setSymbol(simpleLineSymbol); 170 map.graphics.add(feature); 171 } 172 } 173 174 function displayResultCan(layer) { 175 console.log(layer); 176 $("#gpinfo")[0].style.visibility = "hidden"; 177 if (linesCanlayer != null) { 178 map.removeLayer(linesCanlayer); 179 } 180 181 linesCanlayer = layer; 182 map.addLayer(linesCanlayer); // 183 } 184 185 186 function displayResultgonCan(layer) { 187 console.log(layer); 188 if (gonCanlayer != null) { 189 map.removeLayer(gonCanlayer); 190 } 191 192 gonCanlayer = layer; 193 map.addLayer(gonCanlayer); 194 // map.addLayer([linesCanlayer,gonCanlayer]); 195 196 197 }