1. 程式人生 > 其它 >arcgis for js 前端GP服務呼叫

arcgis for js 前端GP服務呼叫

1.先發布好GP服務,例子可參考:https://www.cnblogs.com/hjyjack9563-bk/p/16077788.html,釋出好服務後可以看到瀏覽器如下類似的GP服務

 

2.前端要建立的

Geoprocessor物件

FeatureSet物件作為graphic的集合

注意:傳參的引數名要跟服務裡的引數名相對應

 

 

 完整程式碼

//GP建立
var gp = new Geoprocessor(url)
      var featureset = new FeatureSet()
// featureset.features = [graphic] featureset.features
= me.initlyr.graphics.items var featureset1 = new FeatureSet() featureset1.features = me.rltfw var para = { 'KQZL': featureset, 'Z_值欄位': 'PJZ', '掩膜範圍': featureset1, '表示式': "Year = 2019 AND Month = 1 AND TYPE = 'PM2.5'", '重分類區間值': '' // 'cflvals': '0 50 1;50 100 2;100 150 3;150 200 4;200 300 5;300 500 6'
} //GP呼叫 gp.submitJob(para).then(jobinfo => { console.log('gg', jobinfo) // 'output'----對應著服務的引數名 gp.getResultData(jobinfo.jobId, 'output').then(res => { console.log('ggg', res) for (var j in res.value.features) { var item = res.value.features[j]
var poly = { type: 'polygon', hasZ: false, hasM: false, rings: item.geometry.rings, spatialReference: view.spatialReference } var tempindex = Number(item.attributes['gridcode']) // var tempindex = Number(item.attributes['grid_code']) - 1 var fillsym = { type: 'simple-fill', // autocasts as new SimpleFillSymbol() color: me.tempColor[tempindex], outline: { // autocasts as new SimpleLineSymbol() color: [255, 255, 0], width: 0 } } var attr = item.attributes attr.type = 'rlt' var gra = new Graphic({ geometry: poly, symbol: fillsym, attributes: attr }) me.rltlyr.add(gra) } view.map.reorder(view.map.findLayerById('界線')) me.loading = false }) })