Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

使用 Scene 全局监听点击事件,无法获取上图元素的 feature 数据 #2674

Open
adiu-1024 opened this issue Feb 26, 2025 · 4 comments
Assignees

Comments

@adiu-1024
Copy link

scene.on('click', event => {
console.log('feature', event)
})

在当点击地图元素的时候,比如地图上面图层中的某个面,我希望拿到面里边的 properties 数据来进行业务处理

Copy link
Contributor

hi @adiu-1024, welcome!

Copy link
Contributor

Hi @adiu-1024, Please star this repo if you find it useful! Thanks ⭐!
你好~ @adiu-1024 🌟 如果这个仓库对你有帮助,可以给我们点个star支持一下~你的支持对我们来说是最大的鼓励,感谢你的支持与点赞 🌟

Copy link

在使用 Scene 全局监听点击事件时,如果无法获取到地图元素的 feature 数据,可能是因为事件对象中没有包含所需的 properties 数据。以下是一些可能的解决方案:

  1. 确保图层支持事件:确保你所使用的图层支持点击事件,并且在初始化图层时没有禁用事件功能。

  2. 检查事件对象:在点击事件的回调函数中,检查 event 对象的结构,确认是否包含 featureproperties 数据。可以通过 console.log(event) 来查看事件对象的完整结构。

  3. 使用图层事件:如果全局事件无法获取到 feature 数据,可以尝试直接在图层上监听点击事件。例如:

    layer.on('click', event => {
      console.log('feature properties', event.feature.properties);
    });
  4. 更新 L7 版本:确保你使用的是最新版本的 L7,可能在新版本中已经修复了相关问题。

如果以上方法仍然无法解决问题,请提供更多的代码细节或上下文信息,以便更好地帮助你解决问题。

如果你需要进一步的帮助,请随时告诉我!

🪧 Tips For further assistance, please describe your question in the comments and @petercat-assistant to start a conversation with me.

@adiu-1024
Copy link
Author

使用的版本是"@antv/l7": "^2.22.4" ,通过全局事件处理性能更好,是Bug吗?还是说设计就是这样,就是不支持

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants