A
A
Alexis_D2022-01-14 10:55:59
Yandex maps
Alexis_D, 2022-01-14 10:55:59

How to keep the label centered when moving the map?

I use the react-yandex-map library to work with Yandex maps. I can’t fix the label in the center when dragging the map (you need to do it like a Yandex taxi, they always have a label when dragging in the center), I looked at the official dock, I didn’t find anything there.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2022-01-14
@Alexis_D

const [ coord, setCoord ] = useState(...);

function onActionTickComplete(e) {
  const projection = e.get('target').options.get('projection');
  const { globalPixelCenter, zoom } = e.get('tick');
  setCoord(projection.fromGlobalPixels(globalPixelCenter, zoom));
}

<Map
  onActionTickComplete={onActionTickComplete}
  ...
>
  <Placemark geometry={coord} />
</Map>

https://codesandbox.io/s/sweet-khayyam-zqwy8?file=...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question