Yurko
Yurko

Reputation: 23

Style layer depending on multiple feature properties

is there way to paint features depending on its properties? For example, there is a Feature with int properties "level_a" and "level_b" and it is needed to fill Feature depending which property is greater. There is no way to compare them directly since filter supports only [">", feature(key), value] And features suppose to be in the same layer. Thank you.

Needed something like:

map.addLayer({
                'id': 'foo',
                'type': 'fill',
                'source': 'source',
                'filter': ['>', 'level_a', 'level_b'],   //cannot insert properties directly an value field
                'paint': {
                    'fill-color': '#blue',
                }
            });

Upvotes: 0

Views: 633

Answers (1)

Steve Bennett
Steve Bennett

Reputation: 126265

Yes, expressions support this and much more: https://docs.mapbox.com/mapbox-gl-js/style-spec/expressions/

Using the newer syntax, this would work fine:

'filter': ['>', ['get', 'level_a'], ['get', 'level_b']]

Upvotes: 2

Related Questions