调用GP插值服务主要分为两步
一.arcgis 制作 GP服务
1.arcmap版本需要和server版本一样, 不然gp服务无法使用
2.发布服务的时候选择“查看结果图层”,不然不能渲染到地图上(同理,模型构建器中需要把最后的结果设为参数,不然也无法渲染)
3.如果一直报错,但不知道哪有问题,打开arcgis manager ,点进调用的 gp 服务,里面有个 ”submitJob ***“ 的按钮,get或者post 的都可以,可以进入测试界面
二.js调用
import qs from 'qs' //引入qs用于格式化json格式
// qs插件的介绍
// https://blog.csdn.net/m0_45272038/article/details/120181018
setInterpolation(data) {
this.queryParams.pollutantName = data
this.getPointList().then((temp) => {
const tempValue = 'overMultiple'
// 先移除图层
if (this.dynamicLayer) {
map.removeLayer(this.dynamicLayer)
this.dynamicLayer = null
}
this.GISServer.GPServer = 'http://39.101.202.131:6080/arcgis/rest/services/TRJC/TRJCInterpolation/GPServer/TRJCFinal'
this.GISServer.mapServer = 'http://39.101.202.131:6080/arcgis/rest/services/TRJC/TRJCInterpolation/MapServer'
if (tempValue && this.pollutantlist.length > 0 && data !== '') {
this.lengendShow = true
this.loading = true
// 临时插值数据
const tempJson = {
'displayFieldName': '',
'geometryType': 'esriGeometryPoint',
'spatialReference': {
'wkid': 4326,
'latestWkid': 4326
},
'fields': [
{
'name': 'FID',
'type': 'esriFieldTypeOID',
'alias': 'FID'
},
{
'name': 'name',
'type': 'esriFieldTypeString',
'alias': 'name',
'length': 254
},
{
'name': 'lon',
'type': 'esriFieldTypeDouble',
'alias': 'lon'
},
{
'name': 'lat',
'type': 'esriFieldTypeDouble',
'alias': 'lat'
},
{
'name': 'name11',
'type': 'esriFieldTypeString',
'alias': 'name11',
'length': 254
},
{
'name': 'teep',
'type': 'esriFieldTypeDouble',
'alias': 'teep'
},
{
'name': 'va',
'type': 'esriFieldTypeString',
'alias': 'va',
'length': 254
},
{
'name': 'value1',
'type': 'esriFieldTypeDouble',
'alias': 'value1'
},
{
'name': 'value2',
'type': 'esriFieldTypeDouble',
'alias': 'value2'
},
{
'name': 'value3',
'type': 'esriFieldTypeDouble',
'alias': 'value3'
},
{
'name': 'value4',
'type': 'esriFieldTypeDouble',
'alias': 'value4'
},
{
'name': 'value5',
'type': 'esriFieldTypeDouble',
'alias': 'value5'
},
{
'name': 'value6',
'type': 'esriFieldTypeDouble',
'alias': 'value6'
}
],
'features': [],
'exceededTransferLimit': false
}
for (var i = 0; i < this.pollutantlist.length; i++) {
if (this.pollutantlist[i].longitude && this.pollutantlist[i].latitude) {
var feature = { 'geometry': { 'x': this.pollutantlist[i].longitude, 'y': this.pollutantlist[i].latitude, 'spatialReference': { 'wkid': 4326 }}, 'attributes': { 'value3': this.pollutantlist[i][tempValue], 'name': this.pollutantlist[i].regionName, 'lat': this.pollutantlist[i].latitude, 'lon': this.pollutantlist[i].longitude }}
tempJson.features.push(feature)
}
}
// 请求接口开始插值
axios.post(this.GISServer.GPServer + '/submitJob?f=json',
qs.stringify({ test: JSON.stringify(tempJson), Z: 'value3' })
, {
headers: {
// 关键
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
}
}).then(res => {
if (res.data.jobId) {
this.getResult(res.data.jobId)
} else {
alert('提示', '计算失败!')
}
}).catch(err => { //
console.log('请求失败:' + err.status + ',' + err.statusText)
})
}
})
},
// 请求接口获取绘制好的插值图
getResult(params) {
axios.post(this.GISServer.GPServer + '/jobs/' + params + '?f=json').then(res => {
if (res.data.jobStatus === 'esriJobSucceeded') {
this.showResult(params)
} else {
this.getResult(params)
}
})
},
// 绘制插值图
showResult(params) {
var mapurl = this.GISServer.mapServer + '/jobs/' + params
this.dynamicLayer = esri.dynamicMapLayer({ url: mapurl, opacity: 0.4, useCors: false, zIndex: 9999 })
this.dynamicLayer.addTo(map)
},
备注:
1.动态的参数需要在模型构建器中设置为模型参数,并在发布服务时将该参数设置为“用户自定义”;
2.参数具体格式可以参考模型中 Submit Job 中的参数格式
3.最好事先在 Submit Job 界面能够实现之后再进行前端代码开发