点击监听

构件点击使用 `component:selected` 事件。事件返回当前选中的模型 URL 和构件 ID;应在模型加载前或加载完成后注册,并在页面卸载时取消订阅。

打开 API 调试

点击监听

构件点击使用 component:selected 事件。事件返回当前选中的模型 URL 和构件 ID;应在模型加载前或加载完成后注册,并在页面卸载时取消订阅。

const offComponent = viewer.on('component:selected', ({ url, id }) => {
  console.log('selected component:', { url, id });
});

标签点击使用稳定的标签 API:

const offLabelClick = viewer.engine?.onLabelClick((payload) => {
  console.log('label id:', payload.id);
  console.log('label data:', payload.label.data);
});
// 页面或组件卸载时
offComponent();
offLabelClick?.();

2D 与 GIS Viewer 同样支持 onLabelClick()。