new mars3d.layer.GraphicLayer({在单击聚合点的时候,拿到具体的聚合数据信息

183 篇文章 2 订阅
165 篇文章 0 订阅
function addGraphicLayer() {
  graphicLayer = new mars3d.layer.GraphicLayer({
    clustering: {
      enabled: true,
      pixelRange: 20,
      clampToGround: false,
      addHeight: 1000
    },
    popup: "all",
    center: { lat: 31.639275, lng: 117.388877, alt: 52574.8, heading: 339.3, pitch: -65 },
    flyTo: true
  })
  map.addLayer(graphicLayer)

  // 单击事件
  graphicLayer.on(mars3d.EventType.click, function (event) {
    console.log("你单击了", event)
  })

  mars3d.Util.fetchJson({
    url: "//data.mars3d.cn/file/geojson/hfty-point.json"
  }).then((res) => {
    for (let i = 0; i < res.features.length; i++) {
      const item = res.features[i]

      const label = new mars3d.graphic.BillboardPrimitive({
        position: item.geometry.coordinates,
        style: {
          image: "img/marker/mark-blue.png",
        }
      })
      graphicLayer.addGraphic(label)
    }
  })
}

1.不是聚合的图标点在单击的时候可以查到找到那个attr,但是点击聚合就找不到了。

2.期望在单击聚合点的时候,拿到聚合数据的详细信息。BillboardEntity 使用这个是可以获取的到聚合的数组n个图标点的信息的。但是BillboardPrimitive的attr携带赋值了参数,但是在点击聚合的时候好像没有这个参数。

解决方案:

  // 单击事件
  graphicLayer.on(mars3d.EventType.click, function (event) {
    console.log("你单击了", event)

    if (map.camera.positionCartographic.height > 90000) {
      const graphic = event.graphic
      // graphic.closePopup()
      if (graphic?.cluster) {
        // 单击了聚合的点
        console.log("单击了聚合的点", graphic.getGraphics())
      } else {
        // 单击了具体的点对象
        const position = graphic.positionShow
        map.flyToPoint(position, {
          radius: 5000, // 距离目标点的距离
          duration: 4,
          complete: function (e) {
            // 飞行完成回调方法
            // graphic.openPopup()
          }
        })
      }
    }
  })

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值