gribnoysup / react-yandex-maps

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

this.toGlobalPixelBounds is not a function #247

Closed nazarukroman closed 4 years ago

nazarukroman commented 4 years ago

Здравствуйте, использую метод getCenterAndZoom из util.bounds, но получаю такую ошибку this.toGlobalPixelBounds is not a function.

Может кто-нибудь подсказать в чем проблема?

Пример: https://codesandbox.io/s/react-yandex-map-wefcf

mmarkelov commented 4 years ago

@nazarukroman думаю что проблема с контекстом вызова функции(this) MapContentComponent:

const getCenterAndZoom = ymaps.util.bounds.getCenterAndZoom

// В данном случае this будет указывать на React компонент
const centerAndZoom = getCenterAndZoom(
    [[59.893177, 30.300489], [60.014985, 30.464908]],
    [320, 240]
  );

Есть два варианта чтобы Ваш код заработал:

const centerAndZoom = getCenterAndZoom( [[59.893177, 30.300489], [60.014985, 30.464908]], [320, 240] );

nazarukroman commented 4 years ago

Ох, точно, я совсем забыл про это :( Спасибо большое за ответ!