import { GeolocationControl, Map, Placemark, YMaps, } from '@pbe/react-yandex-maps'; import { isEmpty } from 'lodash'; import { useEffect, useRef } from 'react'; import { Point } from '../model'; type YandexMapProps = { points: Point[]; selectedStation: number | null; handleMapStationClick: (id: number) => void; }; const mapCenter = [38.53575, 68.77905]; export const YandexMap = ({ points, selectedStation, handleMapStationClick, }: YandexMapProps) => { const mapRef = useRef(null); useEffect(() => { if (!mapRef.current) return; if (selectedStation !== null) { const selectedPoint = points.find( (point) => point.id === selectedStation, ); if (selectedPoint) { mapRef.current .setCenter(selectedPoint.coordinates, mapRef.current.getZoom(), { duration: 1000, }) .then(() => { mapRef.current.setZoom(13, { duration: 300 }); }); } } else { mapRef.current.setZoom(11, { duration: 300 }); } }, [selectedStation, points]); return ( { mapRef.current = ref; }} > {points.map((point) => { const isSelectedStation = selectedStation === point.id; return ( handleMapStationClick(point.id)} /> ); })} ); };