You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

DeckGL中BitmapLayer的onHover事件未触发,求助解决方案

解决BitmapLayer onHover事件不触发的问题

你的代码里BitmapLayer的data设为null是导致onHover不触发的核心原因——DeckGL的拾取系统依赖图层的data生成可交互的拾取目标,即使是BitmapLayer这类基于图片的图层,也需要非空的data数组才能启用拾取功能。

修改方案如下:

  • 将BitmapLayer的data从null as any改为[{}](一个包含空对象的数组,仅用于激活拾取机制)
  • 保持TileLayer和BitmapLayer的pickable为true(你已设置,无需改动)

修改后的关键代码片段:

renderSubLayers: (props: any) => {
  console.log("Inside renderSubLayers for colorLayer")
  const { tile } = props;
  if (!tile || !props.data) return null;
  const { west, south, east, north } = tile.bbox;
  return new BitmapLayer(props, {
    id: `${props.id}-bitmap`,
    data: [{}], // 替换null以启用拾取
    bounds: [west, south, east, north],
    image: props.data,
    pickable: true,
    onHover: (info) => {
      console.log("Info:", info)
    },
  });
},

你也可以选择将onHover事件绑定到外层的TileLayer上,通过父图层的事件回调处理交互,但上述修改是最直接解决当前问题的方式。

内容的提问来源于stack exchange,提问作者Mandroid

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.12 04:42:12