mapbox / mapbox/mapbox-gl-js

Icon is flipped horizontally when icon-anchor is *-left or *-right and icon loaded via addImage()

Open
#13,045 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug :lady_beetle:
Dominant language
TypeScript
Stars
12.4k
Forks
2.4k
PR merge metrics
No merged PRs in 30d

Description

I load an image using `addImage` and `loadImage`. When using `icon-anchor: center` it displays normally:

![image](https://github.com/mapbox/mapbox-gl-js/assets/678344/0d899fc1-807e-4f9b-8326-e25283c6edb2)

However when I use `icon-anchor: left` (or `right`, `bottom-left` etc) it:

- flips the image along the vertical axis
- positions the image to the left of its anchor
- horizontally compresses the image

![image](https://github.com/mapbox/mapbox-gl-js/assets/678344/e5d20e3e-bf67-4da4-9178-737fac8bfd21)

In these examples, the location of the feature is the bottom left corner of the cream-colored rectangle (ignoring the rounded corner).

This does not occur when using an image from a pre-generated sprite sheet (eg, `parking-11`):

![image](https://github.com/mapbox/mapbox-gl-js/assets/678344/7ed6f50e-efb2-44d6-a7d2-1881cc1a03be)

My layer definition here is:

```
{
"id": "cad-logo",
"type": "symbol",
"source": "cad",
"minzoom": 13,
"filter": [
"==",
[
"get",
"layer"
],
"_LOGO"
],
"layout": {
"icon-image": "landnow-logo",
"icon-anchor": "left",
"icon-size": 0.2
}
}
```

There is no mention of flipping behaviour in the documentation, and the fact that it doesn't happen with a pre-generated stylesheet suggests that this is a bug, not intended.

Using v3.0.1. Also present in v2.13.0.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The reported entry points are addImage(), loadImage(), and the symbol layer's icon-anchor and icon-image properties; no source file or test is named. Start by reproducing the issue with a dynamically loaded image and compare it with the pre-generated sprite case. Done means left, right, and corner anchors preserve orientation, dimensions, and placement consistently.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
computer-graphics, frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.