0
0
0348raven2017-03-13 19:00:59
Yandex maps
0348raven, 2017-03-13 19:00:59

How to do clustering on Yandex maps when requesting coordinates with getJSON?

I'm trying to cluster

ymaps.ready(function () {
        var map = {};

        $('.js-map--trigger').click(function () {

            var container = $(this).closest('.item').next('li').find('.js-map');

            $('.js-map').css('height', '');
            $(container).css('height', '150');

            if ('destroy' in map) {
                map.destroy();
            }

            map = new ymaps.Map(container[0], {
                center: [55.753915313211486,37.62053621957395],
                zoom: 8,
                type: 'yandex#map',
                flying: true
            });

            var coordsFromDataAttr = $(this).data('id');

            $.getJSON('/items/' + coordsFromDataAttr + '/items', function (data) {
                $.each(data, function (key, val) {
                    map.geoObjects.add(new ymaps.Placemark([val.latitude, val.longitude],{
                        hintContent: val.address,
                        balloonContent: '<div><p>' + val.address +'</p><a href="' + val.href + '" class="">Посмотреть</a></div>',
                    },
                    {
                        iconImageHref: 'icon.svg',
                        iconImageSize: [20, 20],
                        iconImageOffset: [-10, -20]
                    }))
                })
            });

            map.controls.add('smallZoomControl', { top: 75, left: 5 });

        });
    })

I understand that it is necessary to take out the addition of objects outside the function getJSON()and somehow cluster them with their own style, and so that when you click on the cluster, these labels will be approached.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
forgotten, 2017-03-13
@forgotten

https://tech.yandex.ru/maps/jsbox/2.1/object_manager

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question