How to add click event handler for objectManager in React yandex maps?
P粉450079266
P粉450079266 2023-09-16 20:11:32
0
1
655

I'm using the react-yandex-maps (https://github.com/R1ZEN/react-yandex-maps) library, and I need to handle click events for a single landmark, but I don't know how to do it. How do I add an onClick event on the render object on the map?

<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粉450079266
P粉450079266

reply all(1)
P粉083785014

Here’s how to do it.

<ObjectManager
  //其余代码相同
   onObjectClick={(e) => {
        const id = e.get('objectId'); // 获取Id 
        console.log(`Id is: ${id}`);
      }}

/>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template