Closed bemulima closed 4 years ago
Also I tried get ymap object and by him call setCenter method then set duration. But the result is not successful:
let onMapClick = (event) => {
console.log('getYmaps()', getYmaps());
setYaCoords(event.get("coords"));
//getYmaps().setCenter(getCoords(), getYmaps().getZoom(), {'duration': 1000});
},
YandexMap = () => {
return (<YMaps>
<Map
state={{ center: getCoords(), zoom: getZoom()}}
width={'100%'}
height={'350px'}
onClick={onMapClick.bind(this)}
// instanceRef={ref => {if(getYmaps() === null) setYmaps(ref)}}
>
<Placemark geometry={getCoords() } />
</Map>
</YMaps>);
};
So, I found solution. In begin add base ymaps and placemark objects to state and after change don't connect redux. Just in onClick event set new coords and duration
const onMapClick = (event) => {
setYaCoords(event.get("coords")); // update coords in state
getYmaps().setCenter(getCoords(), getYmaps().getZoom(), {'duration': 500});
getPlacemark().geometry.setCoordinates(getCoords());
},
YandexMap = () => {
return (<YMaps>
<Map
state={{ center: getCoords(), zoom: getZoom()}}
width={'100%'}
height={'350px'}
onClick={onMapClick.bind(this)}
instanceRef={ref => {if(getYmaps() === null) setYmaps(ref)}} // set base ymaps object to state
>
<Placemark
geometry={getCoords() }
instanceRef={ref => {if(getPlacemark() === null) setPlacemark(ref)}} // set base placemark object to state
/>
</Map>
</YMaps>);
};
export default YandexMap;
Hey guys! Every body can tell me how to set duration after change coords? I tried set duration by options but not working.