10

This is my code:

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);

I have tried using anchor also, but I could not decrease the size, please help

Andrew
  • 4,953
  • 15
  • 40
  • 58
user1960217
  • 131
  • 2
  • 3
  • 15

1 Answers1

24

ol.style.Icon takes a scale parameter that you can use to scale your icon.

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
  })
});
tsauerwein
  • 5,841
  • 3
  • 36
  • 49
  • N.B. This is a singular value, not x/y individual scaling. Really needs x/y scaling to be useful for some tasks. –  May 20 '15 at 12:39
  • looks like there still isn't a way to scale instead of crop using imgSize. https://github.com/openlayers/openlayers/issues/2720 – Michael Nov 11 '18 at 18:39