konratnox
3/31/2017 - 12:19 PM

Создание яндекс карты с метками

Создание яндекс карты с метками

$(document).ready(function() {
    ymaps.ready(init);
    ymaps.ready(addPoints);
    var myMap;
    var points = [];

    function init(){


        myMap = new ymaps.Map('mapBlock', {
            center: [59.925392693408305,30.337163693359344],
            zoom: 9,
            behaviors: ['default', 'scrollZoom']
        }, {
            searchControlProvider: 'yandex#search'
        }),
            objectManager = new ymaps.ObjectManager({
                clusterize: true,
                gridSize: 32
            });
        myMap.behaviors.disable('scrollZoom');
        objectManager.objects.options.set('preset', 'islands#greenDotIcon');
        objectManager.clusters.options.set('preset', 'islands#greenClusterIcons');
        myMap.geoObjects.add(objectManager);
    }

    function addPoints() {
        points = [];

        $('.office-table__office').each(function(index, el) {
            var coord = $(el).attr('data-coordinates');
            var coordFirst = parseFloat(coord.split(',')[0]);
            var coordSecond = parseFloat(coord.split(',')[1]);
            var name = $(el).attr('data-storename');
            var cont = $(el).find('.office-table__addr').html() + '<br>' + $(el).attr('data-hours') + '<br>' + $(el).find('.office-table__tel').html();
            points.push(new ymaps.Placemark([coordFirst, coordSecond],
                {
                    balloonContentHeader: name,
                    balloonContentBody: cont,
                },
                {
                    iconColor: '#C09B48'
                }
                )
            );
        });

        $.each(points, function (index, value) {
            myMap.geoObjects.add(value);
        });

    }
});