A
A
Alexey Nikolaev2015-07-19 22:07:40
JavaScript
Alexey Nikolaev, 2015-07-19 22:07:40

How to make Yandex.Map change its size smoothly and dynamically?

Good time!
There is a block with a fixed height - map-area . The map is loaded into it, and, accordingly, it automatically takes the height of the parent block (moreover, the height is automatically written in the style attribute of the created map). I also have a button that smoothly changes the height of the map-area block . If you don't touch the map ( or set it explicitly to 100% height ), it will not react to changing the size of the container, moreover, stubs with the inscription "Yandex.maps do not have data about these coordinates" will appear around the edges. The card is broken.
Found the following workable:

$map.animate({'height':'600px'}, 'fast', 'linear', function() {
  map.container.fitToViewport(); // объект класса ymaps.Map
})

So the map remains functional after the animation, the position of the center is corrected. But this happens abruptly, but I would like to achieve a smooth unfolding, with a smooth shift in the center of the map, etc.
Is there any way to do this?..
Thank you.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
F
forgotten, 2015-07-19
@Heian

Well, obviously, manually change the height of the map in a cycle and call fitToViewport.

C
chudomozg, 2019-08-30
@chudomozg

those. Does the word 'fast' imply anything? =)
From the Documentation:
.animate( properties [, duration ] [, easing ] [, complete ] )
the duration parameter (delay) can be set in numbers (milliseconds if memory serves) and in words (fast, slow).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question