I
I
Igor2018-11-16 12:22:40
Yandex maps
Igor, 2018-11-16 12:22:40

Why does the yandex.map "Map is not a constructor" error occur when drawing a map?

There is an error yandex.map when drawing a map. And the first time it works fine, I refresh the page - and the error "Map is not a constructor" occurs.
Yandex maps are connected.

<script src="https://api-maps.yandex.ru/2.1/?lang=ru_RU&amp;apikey=ACVJ7VsBAAAAfSS6cgIAVLnRi1q0iH043DIGgZ25iZHlDRIAAAAAAAAAAAAPNPh4wuod8SF2ylX9eUu1ZgNmVg==" type="text/javascript"></script>

when loading the page, it executes the script for drawing the map for the object:
var myMap = new ymaps.Map('map', {
            center: [56.83002698350858, 60.61000808465601],
            zoom: 16
        }, {
          searchControlProvider: 'yandex#search'
        }),

        // Создаём макет содержимого.
        MyIconContentLayout = ymaps.templateLayoutFactory.createClass(
          '<div style="color: #FFFFFF; font-weight: bold;">$[properties.iconContent]</div>'
        ),

        myPlacemark = new ymaps.Placemark(myMap.getCenter(), {
          hintContent: 'г. Екатеринбург, ул. Карла Маркса, 8, офис 306',
          balloonContent: 'г. Екатеринбург, ул. Карла Маркса, 8, офис 306'
        }, {
          // Опции.
          // Необходимо указать данный тип макета.
          iconLayout: 'default#image',
          // Своё изображение иконки метки.
          //iconImageHref: 'images/myIcon.gif',
          // Размеры метки.
          iconImageSize: [30, 42],
          // Смещение левого верхнего угла иконки относительно
          // её "ножки" (точки привязки).
          iconImageOffset: [-5, -38]
        });

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
freeExec, 2018-11-16
@pingvin156

Because your "drawing script" works out before api-maps.yandex.ru is loaded

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question