我正在使用 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>
P粉0837850142023-09-17 11:35:06
以下是如何操作的。
<ObjectManager //其余代码相同 onObjectClick={(e) => { const id = e.get('objectId'); // 获取Id console.log(`Id is: ${id}`); }} />