K
K
karpo5182021-11-04 22:23:05
JavaScript
karpo518, 2021-11-04 22:23:05

How to delete/redraw a Yandex.Map created using the map constructor?

To add a Yandex map to the page, I use js to generate and embed the script tag received in the map constructor into the div container. This trick was required because:

1. I did not find a way to create a map built in the constructor on the page through the Maps Javascript API.
2. The map assembled in the constructor should have a height, while I would like it to take the height from the height of the parent container.

Now I use the resize event so that when the display orientation on the smartphone changes, the map retains the size of the parent container. On this event, I first delete the contents of the container, and then re-add the script tag generated by the map designer to it. Obviously, this is the wrong way to redraw the map, because errors are pouring into the console related to the unexpected removal of the html layout of the map.

Error examples:

Script element was removed from document.
Uncaught TypeError: Cannot read property 'options' of undefined


The second error is generated in the background and litters the entire console. The map works as expected, but I would still like to fix the errors that my crutch produces.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
karpo518, 2021-11-04
@karpo518

Solved the problem of adaptability of the map block using the Iframe code instead of Javascript. Specified the width and height of 100% for the iframe tag. Now the block adjusts to the size of the parent. One less crutch on the site)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question