如何减少openlayers 3中Icon的大小,我正在使用bing贴图

问题描述 投票:6回答:1

这是我的代码:

var iconFeature = new ol.Feature({
   geometry: new ol.geom.Point(ol.proj.transform([-95.3698,29.7604], 'EPSG:4326' , 'EPSG:3857')),
   name: 'Null Island',
});

var iconStyle = new ol.style.Style({
  image: new ol.style.Icon({
    opacity: 0.75,
    src: 'flag.png',
    height:10,
    width:10,
  })
});
iconFeature.setStyle(iconStyle);

我也试过使用锚,但是我无法减小尺寸,请帮忙

openlayers-3
1个回答
16
投票

ol.style.Icon采用scale参数,您可以使用它来缩放图标。

var iconStyle = new ol.style.Style({
  image: new ol.style.Icon({
    opacity: 0.75,
    src: 'flag.png',
    // the real size of your icon
    size: [10, 10],
    // the scale factor
    scale: 0.5
  })
});
© www.soinside.com 2019 - 2024. All rights reserved.