Skip to content

Instantly share code, notes, and snippets.

@smartdeal
Created June 29, 2018 16:12
Show Gist options
  • Save smartdeal/ad38f36f41fc34555b83662f86a8b583 to your computer and use it in GitHub Desktop.
Save smartdeal/ad38f36f41fc34555b83662f86a8b583 to your computer and use it in GitHub Desktop.
[Lazy load and init Yandex Map] #YandexMap
/* Yandex Map
========================================================*/
var map_container = document.getElementById("map");
if (map_container) {
$(document).ready(function () {
get_map(map_container, map_contact);
});
}
function get_map(map_container, map_array){
if ( map_container !== null ) {
if (typeof ymaps === 'undefined')
$.loadScript('https://api-maps.yandex.ru/2.1/?lang=ru_RU', function(){
ymaps.ready(init);
var myMap,
myPlacemark,
curLat,
curLong,
curDesc;
function init(){
curLat = map_array['lat'];
curLong = map_array['long'];
myMap = new ymaps.Map(map_container, {
// center: [61.582319, 98.112851],
center: [curLat, curLong],
zoom: 17
});
// curDesc = map_array['desc'];
myPlacemark = new ymaps.Placemark([curLat, curLong], {}, {
// balloonContent: curDesc
iconLayout: 'default#image',
iconImageHref: theme_url+'/img/map-pin.png',
iconImageSize: [42, 58],
iconImageOffset: [-30, -70]
});
myMap.geoObjects.add(myPlacemark);
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment