I'm quite new to OpenLayers. Right now I'm using it with OSM for a project and I'm facing what seems an issue to me: when I set an Overlay while zoomed in to max resolution, then, when I zoom out, the marker looks like it have moved to a different location. If I zoom in again everything is correct.

I this a bug in OpenLayers?

I'm using projection EPSG:3857 all the time and the marker positioning is set to "bottom-center".

Here is an image of the issue: map From left to right: - 1. what I set - 2. what I see when zooming out - 3. What should be

Any Idea?

1 Answer 1


First, you should use a ol.layer.Vector instead of an ol.Overlay to display markers, especially if you have many.

Second, take a look at this Icon example in OpenLayers. The marker always points to the correct location. That is: because its center is not the location.

Look at the style definition:

  var iconStyle = new ol.style.Style({
    image: new ol.style.Icon(/** @type {olx.style.IconOptions} */ ({
      anchor: [0.5, 46],
      anchorXUnits: 'fraction',
      anchorYUnits: 'pixels',
      src: 'https://openlayers.org/en/v4.1.1/examples/data/icon.png'

The anchor property defines where the image should points, by default it is the center of the image. See the ol.style.Icon API doc.

For your case, it would seem that the center of the image points to the location, where you would have wanted to bottom tip to do that. Try the ol.layer.Vector with icon style definition, instead.

  • There should be a bug in OpenLayers. It has a similar behaviour using Vectors. If Y offset for the icon seems fine, but not X offset. It seems that setting anchorXUnits to "pixels" causes the very same problems. Settings anchorXUnits to fraction seems to work fine but there is a tiny offset. I'll try to open a bug in their website
    – Carles
    May 4, 2017 at 17:07
  • Only 3 years later, but how do you set a bunch of images on the map? Just run through a loop or is there a setAll() type of call? Thanks.
    – JustAspMe
    Feb 21, 2020 at 18:26
  • @JustAspMe I suggest you open a new thread about your question in which you describe more what you're trying to accomplish and what you've tried to do so far. Feb 25, 2020 at 12:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.