花一整天的时间在这上面。
我刚刚发现组件中的onClick
属性DeckGL
捕获了空白区域或分层区域中的每次点击。来自空的 DeckGL 画布的事件对象如下所示:
{
"x": 877,
"y": 556,
"coordinate": [
106.85059802642887,
-6.138317762993974
],
"lngLat": [
106.85059802642887,
-6.138317762993974
],
"layer": null, //If the click come from layer, the layer should not null
"color": null,
"object": null,
"index": -1
}
弄清楚如果点击来自 DeckGL 顶部的图层,图层将包含与对象相关的道具。
因此,在您的情况下,您可以检查图层是否为空
<DeckGL
//...Other props
onClick={(event) => {
//Click comes from empty area
if(event.layer === null) {
// Set popup
}else{
// Clear Popup
}
}}
/>