gis判断地块类型绘制点线面

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
  }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值