我正在使用 react-yandex-maps(https://github.com/R1ZEN/react-yandex-maps)库,并且我需要处理单个地标的点击事件,但是我不知道如何做。我该如何在地图上的渲染对象上添加 onClick 事件?
<YMaps>
    <Map className="w-full h-full"
        state={{ center: center, zoom: 12 }}
        onBoundsChange={handleBoundsChange}
    >
        <ObjectManager
            options={{
                clusterize: true,
            }}
            objects={{
                preset: "islands#greenDotIcon",
            }}
            clusters={{
                preset: "islands#redClusterIcons",
            }}
            defaultFeatures={data.result.data.map((el: APZ) => ({
                type: "Feature",
                id: el.id,
                geometry: {
                    type: "Point",
                    coordinates: [el.lat, el.long],
                },
            }
            ))}
        />
    </Map>
</YMaps>
            Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
以下是如何操作的。
<ObjectManager //其余代码相同 onObjectClick={(e) => { const id = e.get('objectId'); // 获取Id console.log(`Id is: ${id}`); }} />