cesium 点击单一tile轮廓高亮

 单击or悬浮事件

const handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas)
      const _this = this
      handler.setInputAction(function (movement) {
        // debugger
        var pickedObject = viewer.scene.pick(movement.position)
        _this._logPosition(movement.position, viewer)
        console.log('当前视角:position:' + viewer.camera.position + ',heading:' + viewer.camera.heading + ',pitch:' + viewer.camera.pitch + ',roll:' + viewer.camera.roll)
        const orientation = { heading:viewer.camera.heading, pitch:viewer.camera.pitch, roll:viewer.camera.roll }
        const destination = viewer.camera.position
        const position_new = {
          orientation:orientation,
          destination:destination
        }
        _this.$emit('newposition', position_new)
        if (Cesium.defined(pickedObject)) {
          const entity = pickedObject.id ? pickedObject.id : pickedObject
          let eventName = ''
          if (Cesium.defined(entity)) {
            if (entity instanceof Cesium.Cesium3DTileFeature) {
              eventName = 'on-3dtile-click'
              console.log(entity)
              _this.$emit('on-3dtile-click', entity)
            } else {
              if (entity instanceof Cesium.Entity || entity instanceof Cesium.Billboard) {
                eventName = 'on-vector-click'
                _this.$emit('on-vector-click', entity)
              } else {
                eventName = 'on-primitive-click'
              }
            }
            _this.$emit(eventName, entity)
          }
        }
      }, Cesium.ScreenSpaceEventType.LEFT_CLICK)

      // 悬浮事件
      handler.setInputAction(function (movement) {
        var pickedObject = viewer.scene.pick(movement.endPosition)
        if (Cesium.defined(pickedObject)) {
          const entity = pickedObject.id ? pickedObject.id : pickedObject
          let eventName = ''
          if (Cesium.defined(entity)) {
            if (entity instanceof Cesium.Cesium3DTileFeature) {
              eventName = 'on-3dtile-mousemove'
            } else {
              if (entity instanceof Cesium.Entity || entity instanceof Cesium.Billboard) {
                eventName = 'on-vector-mousemove'
              } else {
                eventName = 'on-primitive-mousemove'
              }
            }
            _this.$emit(eventName, entity)
          }
        }
      }, Cesium.ScreenSpaceEventType.MOUSE_MOVE)

父组件调用子组件

<viewer @on-viewer-completed="viewerCompletedHandler"
            @on-vector-click="viewVectorClick"
            @on-3dtile-click="onTileClick"></viewer>

单击方法

onTileClick(feature){
  this.clickEvent(feature)
}

调用高亮方法

clickEvent(pickedFeature) {
      debugger
      if (this.houetteStage) {
        viewer.scene.postProcessStages.remove(this.houetteStage)
        this.houetteStage = null
      }
        // 如果支持剪影,则鼠标上方的剪影功能为蓝色,鼠标单击的剪影功能为绿色
        // 如果不支持轮廓,请将特征颜色更改为鼠标悬停时为黄色,单击鼠标时为绿色
      if (Cesium.PostProcessStageLibrary.isSilhouetteSupported(viewer.scene)) {
        // 支持轮廓 悬浮时
        // var silhouetteBlue = Cesium.PostProcessStageLibrary.createEdgeDetectionStage()
        // silhouetteBlue.uniforms.color = Cesium.Color.BLUE// 蓝色
        // silhouetteBlue.uniforms.length = 0.01
        // silhouetteBlue.selected = []
        // 单击时
        var silhouetteGreen = Cesium.PostProcessStageLibrary.createEdgeDetectionStage()
        silhouetteGreen.uniforms.color = new Cesium.Color(255 / 255, 114 / 255, 0, 1)
        silhouetteGreen.uniforms.length = 0.02
        silhouetteGreen.selected = [pickedFeature]
        this.houetteStage = Cesium.PostProcessStageLibrary.createSilhouetteStage([
          // silhouetteBlue,
          silhouetteGreen
        ])
        debugger
        viewer.scene.postProcessStages.add(this.houetteStage)
      }
    }

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

我就是你的语法糖️

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值