Skip to content

[Bug] Markers jump in 1 pixel after map zooming#1014

Description

@khmm12

Greetings 馃憢

The problem

I found weird markers behaviour. After map zooming they jump in 1px.

gif

2022-02-18 17 48 18

Reason

It happens because screen coordinates are rounded after map movement (see).

Reproducible on:

  • Macbook Pro 2015 15
  • macOS, Google Chrome 98
  • mapbox-gl v1 / maplibre-gl-js v1 / maplibre-gl-js v2

But it should be noticeable everywhere due to subpixel rendering.

Solution

Round screen coordinates during movement taking into account Window.devicePixelRatio. Theoretically it should solve stuttering during zooming (which happens on HiDPI screens only?).

const pixelRatio = (typeof window !== 'undefined' && window.devicePixelRatio) || 1;

export function roundPixel(pixel: number): number {
  return Math.round(pixel * pixelRatio) / pixelRatio;
}
 DOM.setTransform(this._element, `${anchorTranslate[this._anchor]} translate(${roundPixel(this._pos.x)}px, ${roundPixel(this._pos.y)}px) ${pitch} ${rotation}`);

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions