gribnoysup / react-yandex-maps

Yandex Maps API bindings for React
MIT License
327 stars 116 forks source link

Клик на `Point` в `ObjectManager` #196

Closed tilvan closed 4 years ago

tilvan commented 4 years ago

@gribnoysup Я могу навесить событие клика на сам Point? Иными словами, мне надо по клику на метку получить её properties

Я добавляю на карту ObjectManager с FeatureCollection

mmarkelov commented 4 years ago

@tilvan как-то так:

<YMaps>
  <Map
    defaultState={{
      center: [55.751574, 37.573856],
      zoom: 10,
    }}
  >
    <ObjectManager
      options={{
        clusterize: true,
        gridSize: 32,
      }}
      objects={{
        openBalloonOnClick: true,
        preset: 'islands#greenDotIcon',
      }}
      clusters={{
        preset: 'islands#redClusterIcons',
      }}
      filter={object => object.id % 2 === 0}
      defaultFeatures={features}
      modules={[
        'objectManager.addon.objectsBalloon',
        'objectManager.addon.objectsHint',
      ]}
      // Слушаем клики по объектам ObjectManager
      instanceRef={ref => ref.objects.events.add('click', (e) => {
        // Используем айдишник для того, чтобы далее получить инфу по метке
        const objectId = e.get('objectId');
        console.log(ref.objects.getById(objectId))
     })}
    />
  </Map>
</YMaps>

Полезные доки:

tilvan commented 4 years ago

@mmarkelov Благодарю!