graphicsLayer: any = null // 新建预览图层
//高亮展示
highLightFeature(item){
if (!this.graphicsLayer) {
this.graphicsLayer = new config.esriConstructors.GraphicsLayer({
id: 'graphics-layer'
})
view.map.layers.add(this.graphicsLayer)
} else {
this.graphicsLayer.visible = true
this.graphicsLayer.graphics.removeAll()
}
if (item.features.length > 0) {
const features = item.features[0].geometry
const type = this.getGeometryType(features)
switch (type) {
case 'Polygon':
const fillSymbol = {
type: 'simple-fill',
color: [227, 139, 79, 0.8],
outline: {
color: [255, 0, 0],
width: 2
}
}
const graphicPolygon = this.createGeometry(
features,
'Polygon',
fillSymbol,
view
)
view.extent = graphicPolygon.geometry.extent
this.graphicsLayer.graphics.add(graphicPolygon)
view.extent = changeExtent(features.extent.clone())
break
case 'Point':
const markerSymbol = {
type: 'simple-marker',
color: [255, 51, 51],
outline: {
color: [255, 255, 255],
width: 1
}
}
const graphic = this.createGeometry(
features,
'Point',
markerSymbol,
view
)
view.center = graphic.geometry
this.graphicsLayer.graphics.add(graphic)
break
case 'Polyline':
const lineSymbol = {
type: 'simple-line',
color: [255, 0, 0],
width: 2
}
const graphicLine = this.createGeometry(
features,
'Polyline',
lineSymbol,
view
)
view.extent = graphicLine.geometry.extent
this.graphicsLayer.graphics.add(graphicLine)
break
default:
break
}
} else {
this.$message.warning('无数据定位')
}
}
//判断类型
getGeometryType(features: any) {
let type = ''
if (features.x) {
type = 'Point'
}
if (features.paths) {
type = 'Polyline'
}
if (features.rings) {
type = 'Polygon'
}
return type
}
//创建视图
createGeometry(item: any, type: string, symbol: any, view: any) {
let graphic = null
try {
switch (type) {
case 'Polygon':
const polygon = new config.esriConstructors.Polygon({
rings: item.rings,
spatialReference: view.spatialReference
})
graphic = new config.esriConstructors.Graphic({
geometry: polygon,
symbol
})
break
case 'Polyline':
const polyline = new config.esriConstructors.Polyline({
type: 'polyline',
paths: item.paths,
spatialReference: view.spatialReference
})
graphic = new config.esriConstructors.Graphic({
geometry: polyline,
symbol
})
break
case 'Point':
const point = new config.esriConstructors.Point({
x: item.x,
y: item.y,
spatialReference: view.spatialReference
})
graphic = new config.esriConstructors.Graphic({
geometry: point,
symbol
})
break
default:
break
}
return graphic
} catch (error) {
console.log(error)
return graphic
}
}
gis判断地块类型绘制点线面
于 2022-05-11 15:26:48 首次发布