如何设置地标的大小?

时间:2018-10-22 22:37:11

标签: javascript yandex-maps

我用地标制作yandex地图。对于我使用的地标,请遵循以下预设:

  

'islands#blueHomeIcon'

我需要为地标图标设置大小:

  

268px x 268px

请帮助我。

我的尝试:

let map;
let latitude = 55.8005930;
let longitude = 49.2119510;
let zoom = 16;
let controls = ['fullscreenControl', 'rulerControl'];


ymaps.ready().then(() => {
  map = new ymaps.Map('map', {
    center: [latitude, longitude],
    zoom: zoom,
    controls: controls
  });

  setMarker([latitude, longitude]);
});

function setMarker(coords) {
  const marker = new ymaps.Placemark(coords, {}, {
    preset: 'islands#blueHomeIcon',
    iconImageSize: [268, 268]
  });

  map.geoObjects.add(marker);
}

JSFIDDLE

UPD:我需要使用标准地标图标(不是自定义图片)

1 个答案:

答案 0 :(得分:2)

要使用iconImageSize属性,您似乎必须使用布局default#image并提供图片。

myPlacemark = new ymaps.Placemark(myMap.getCenter(), {
        hintContent: 'A custom placemark icon',
        balloonContent: 'This is a pretty placemark'
    }, {
        /**
         * Options.
         * You must specify this type of layout.
         */
        iconLayout: 'default#image',
        // Custom image for the placemark icon.
        iconImageHref: 'images/myIcon.gif',
        // The size of the placemark.
        iconImageSize: [30, 42],
        /**
         * The offset of the upper left corner of the icon relative
         * to its "tail" (the anchor point).
         */
        iconImageOffset: [-5, -38]
    }),

https://tech.yandex.com/maps/jsbox/2.1/icon_customImage