Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Text label with zoom stops behaves incorrectly on Android #6303

Closed
clydebarrow opened this issue Sep 10, 2016 · 5 comments
Closed

Text label with zoom stops behaves incorrectly on Android #6303

clydebarrow opened this issue Sep 10, 2016 · 5 comments

Comments

@clydebarrow
Copy link
Contributor

Platform: Android:
Mapbox SDK version 4.2.0-beta.2:

Steps to trigger behavior

  1. I have a style that changes labels for a point based on zoom level:

            "text-field": {
                "base": 1,
                "stops": [
                    [
                        0,
                        "{code}"
                    ],
                    [
                        10,
                        "{name}"
                    ],
                    [
                        22,
                        "{name}"
                    ]
                ]
            },
    

    Previewing this map in Studio, or using the sharing URL gives the expected behaviour, i.e. the label displays the {code} property at low zoom levels, and the {name} property at high zoom levels:
    screen shot 2016-09-10 at 8 48 39 pm
    . When using this map in an Android app only the higher zoom label ({name} in the above example) is displayed, irrespective of the zoom level.
    screenshot_2016-09-10-20-43-26

Actual behavior

@clydebarrow
Copy link
Contributor Author

After some experimentation I found that adding an extra stop to the function makes it work on Android. Changing the above example to:

                "text-field": {
                    "base": 1,
                    "stops": [
                        [
                            0,
                            "{code}"
                        ],
                        [
                            9,
                            "{code}"
                        ],
                        [
                            10,
                            "{name}"
                        ],
                        [
                            22,
                            "{name}"
                        ]
                    ]
                }

results in {code} being shown up to zoom level 10.

@jfirebaugh
Copy link
Contributor

Possibly same root cause as #5823.

@clydebarrow
Copy link
Contributor Author

This begs the question as to what is the expected behaviour. With numeric functions it's possible to interpolate, but where the values are discrete there needs to be some other algorithm. Is this specified anywhere? If not I propose the following for functions with discrete values:

Select the value from the nearest zoom stop with a value less than or equal to the current zoom;
If no such stop exists, select the value from the nearest zoom stop with a value greater than the current zoom.
If no such stop exists the function is invalid.

This shouldn't break anything existing, but will make my original example and that from #5823 work as expected.

@clydebarrow
Copy link
Contributor Author

Ok, reading the mapbox-gl-native code, it appears the current algorithm chooses the higher zoom stop if it exists, i.e. the reverse of my proposal. That's a reasonable implementation (if documented) but it does not behave in the same manner as the Studio preview. One or the other needs to change. I tried looking at the mapbox-gl-js code to see what it does, but I don't speak Javascript so I couldn't figure it out.

@jfirebaugh
Copy link
Contributor

Fixed in #6328.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants