vinni
vinni

Reputation: 653

mapbox gl calculate inside expression for circle-radius

I'd like to do a calculation inside an expression. Is this possbile? The code I have for now doesn't work. This example works fine:

'circle-radius': {
    'base': 1.5,
        'stops': [
            [0, 0],
            [20, 180]
        ]
}

But when I do a calculation inside, it doesnt work:

'circle-radius': {
    'base': 1.5,
    'stops': [
        [0, 0],
        [20, ['*', 2, 90]]
    ]
},

And what I'm really trying to do in the end is adding another variable from my data.

'circle-radius': {
    'base': 1.5,
    'stops': [
        [0, 0],
        [20, ['*', 2, ["get", "amount"]]]
    ]
},

Thanks!

Upvotes: 1

Views: 1737

Answers (1)

Steve Bennett
Steve Bennett

Reputation: 126767

You're mixing two different Mapbox-GL syntaxes together: the older "stops" method, and the newer expression syntax. Since you want to do a calculation, you need to entirely use the new expression syntax.

Something like this:

{
    "circle-radius": [
        "interpolate", ["linear"], ["zoom"],
        0, 0,
        20, ['*', 2, ['get', 'amount']]]
    ]
}

Upvotes: 3

Related Questions