E
E
exedis2018-02-20 18:28:35
JavaScript
exedis, 2018-02-20 18:28:35

How to put your icon on Yandex maps?

Hello, I can’t figure out how to put my icons on the labels. I clustered the labels, made icons on the clusters themselves, but it doesn’t work on the labels.

<script>  
   ymaps.ready(function () {
    var myMap = new ymaps.Map('map', {
            center: [55.751574, 37.573856],
            zoom: 12
        }, {
            searchControlProvider: 'yandex#search'
        }),
        clusterer = new ymaps.Clusterer({
            clusterIcons: [
                {
                    href: '/assets/img/logo.png',
                    size: [20, 45],
                    offset: [-3, -42]
                },
                {
                    href: '/assets/img/logo.png',
                    size: [20, 45],
                    offset: [-3, -42]
                }],
            clusterNumbers: [10],
            clusterIconContentLayout: null
        }),
        getPointData = function (index) {
            return {
                    iconLayout: 'default#image',
                    iconImageHref: '/assets/img/logo.png', 
                    iconImageSize: [70, 70],
                    iconImageOffset: [-35, -35]
            };
        },
        points = [
             [55.691846,37.568841],[55.812949,37.650162],[55.907869,37.582933],[55.749491,37.591421],[55.801415,37.531774],[55.878076,37.559649]
         ],
        geoObjects = [];

    for (var i = 0, len = points.length; i < len; i++) {
         geoObjects[i] = new ymaps.Placemark(points[i], getPointData(points[i]));
    }
    clusterer.add(geoObjects);
    myMap.geoObjects.add(clusterer);
    myMap.setBounds(clusterer.getBounds(), {
        checkZoomRange: true
    });
    myMap.behaviors.disable('scrollZoom');
});
  </script>

How to put your own icon on the label?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
exedis, 2018-02-23
@exedis

Everything should have been written like this

for (var i = 0, len = points.length; i < len; i++) {
         geoObjects[i] = new ymaps.Placemark(points[i], { 
              balloonContentBody: '',
            },{
            	iconLayout: 'default#image',
            	iconImageHref: '/assets/img/logo.png', 
            	iconImageSize: [20, 45],
            	iconImageOffset: [-3, -42], 

            });
   
    }

Y
Yana Mitrofanova, 2018-02-20
@Raina97

https://yandex.ru/blog/mapsapi/46712
https://yandex.ru/blog/mapsapi/36471

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question