QueryTask应用:
// 获取全部行政区块
async getDistrictData() {
let layerUrl.YTH_BASE_DISTRICT = 'http://172.18.80.186:6080/arcgis/rest/services/ps_yth/XTFQ_REGION/MapServer', // 行政区块
const queryTask = new this.$esri.QueryTask({
url: `${layerUrl.YTH_BASE_DISTRICT}/0`
})
const query = new this.$esri.Query({
outFields: ['*'],
returnGeometry: true,
where: '1=1'
})
await queryTask.execute(query).then(response => {
this.districtData = response.features
console.log('response: ', response.features)
})
},
其他使用this.districtData数据的相关代码:
//创建districtLayer图层
addLayers() {
this.districtLayer = new this.$esri.GraphicsLayer({
id: 'districtLayer',
graphics: [],
visible: true
})
this.mapAndView.map.add(this.districtLayer)
},
// 查询某个行政区块
addDistrictLayer(districtCode) {
if (this.districtLayer) {
this.districtLayer.removeAll()
}
this.districtData.forEach(item => {
if (districtCode === item.attributes.ADDVCD) {
const polygon = new this.$esri.Polygon({
rings: item.geometry.rings[0],
spatialReference: this.mapAndView.spatialReference
})
const graphic = new this.$esri.Graphic({
geometry: polygon,
symbol: {
type: 'simple-fill',
style: 'solid',
color: [255, 57, 80, 0.08],
outline: {
color: '#ff3950',
width: 3
}
},
attributes: item.attributes
})
this.districtLayer.addMany([graphic])
this.mapAndView.goTo(graphic.geometry.extent.expand(0.8))
}
})
}