Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.5k views
in Technique[技术] by (71.8m points)

Cesium 怎么给点添加单击事件

求教,我使用Cesium.PointPrimitiveCollection 添加的点怎么给每一个点添加单击事件的?

let pointPrimitives = _this.viewer.scene.primitives.add(new Cesium.PointPrimitiveCollection())
      let data = [
        {x: 120.296589, y: 30.263504},
        {x: 120.296589, y: 30.261984},
        {x: 120.296589, y: 30.259051},
        {x: 120.296589, y: 30.257086},
        {x: 120.296589, y: 30.254216},
        {x: 120.296589, y: 30.250878},
        {x: 120.296589, y: 30.24988},
        {x: 120.296589, y: 30.248819},
        {x: 120.296589, y: 30.247883},
        {x: 120.296589, y: 30.245855},
        {x: 120.296589, y: 30.244311},
        {x: 120.296589, y: 30.241345},
        {x: 120.296589, y: 30.239943},
        {x: 120.296589, y: 30.238445},
        {x: 120.296589, y: 30.236745}
      ]
      data.map(item => {
        let position = Cesium.Cartesian3.fromDegrees(item.x, item.y, 0) // 这里的 50 是高度
        pointPrimitives.add({
          pixelSize: 4,
          color: Cesium.Color.RED,
          outlineColor: Cesium.Color.RED,
          outlineWidth: 0,
          position: position
        })
      })

image.png
先行感谢!!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

如果有同样问题的 可以使用这种方法:

`const handler = new this.cesium.ScreenSpaceEventHandler(viewer.scene.canvas)

  handler.setInputAction(function (click) {
    var pick = viewer.scene.pick(click.position)
    console.log(pick)
    if (pick && pick.id) {
      if (pick.id._id === 'billboard') {
        if (_this.modelViewerShow === true) {
          _this.getModel()
          _this.modelViewerShow = false
          _this.$('.adsk-viewing-viewer').show()
          _this.$('#GISviewer').hide()
        }
      } else {
        console.log(pick.id)
      }
    }
  }, _this.cesium.ScreenSpaceEventType.LEFT_CLICK)`

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...