Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can expressions be used within an interpolator? #1211

Open
jaybo opened this issue Feb 21, 2024 · 0 comments
Open

Can expressions be used within an interpolator? #1211

jaybo opened this issue Feb 21, 2024 · 0 comments

Comments

@jaybo
Copy link

jaybo commented Feb 21, 2024

mapbox-gl-js version: 3.1.2
mapbox-gl-draw version: 1.4.3

Steps to Trigger Behavior

Here's an example of an expression I would expect should work, but seems to not. No errors are shown, but the icon size doesn't change when selected.

// try and increase the size of the selected point by 2X
iconPrivateSizeInterpolator: mapboxgl.Expression =
[
    "let",
    "selectBoost",
    ["case", ["==", "active", "true"], 2, 1],

    [
        "interpolate",
        ["linear"],
        ["zoom"],
        0,
        0,
        4.5,
        ["*", ["var", "selectBoost"], 0.4],
        15,
        ["*", ["var", "selectBoost"], 0.7],
    ],
];

which is referenced like:

layout: {
    "icon-image": ["get", "user_icon"],
    ...
    "icon-size": this.iconPrivateSizeInterpolator,
},

What's totally curious, is that I have another interpolator based on a user property that works. But what I don't get is why I don't need to preface the variable name with user_ in functioning example below. Draw is sooo mysterious.

// WORKS boost size of text based on properties.starsAverage 
iconTextSizeInterpolator: mapboxgl.Expression =
// starsAverage is 0 to 5
[
    "let",
    "starBoost",
    ["*", ["coalesce", ["get", "starsAverage"], 0], 0.5], // 0 to 2.5

    [
        "interpolate",
        ["linear"],
        ["zoom"],
        0,
        0,
        11.5,
        0,
        12,
        ["+", ["var", "starBoost"], 11],
    ],
];

referenced as:

layout: {
    "icon-image": ["get", "icon"],
    ...
    "text-size": this.iconTextSizeInterpolator,
},

Expected Behavior

Icon gets twice as large when selected

Actual Behavior

No change in icon size

@jaybo jaybo changed the title Can expressions be used within an interpolators? Can expressions be used within an interpolator? Feb 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant