2

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

'岛屿#blueHomeIcon'

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

268 像素 x 268 像素

请帮我。

我的尝试:

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:我需要使用标准地标图标(不是自定义图像)

4

1 回答 1

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

于 2018-10-22T22:48:53.130 回答