mapbox style specification 具体例子

 

参考官网:

https://docs.mapbox.com/mapbox-gl-js/style-spec/expressions/

The value for any layout property, paint property, or filter may be specified as an expression. 
An expression defines a formula for computing the value of the property using the operators described below. 
The set of expression operators provided by Mapbox GL includes:
Mathematical operators for performing arithmetic and other operations on numeric values
Logical operators for manipulating boolean values and making conditional decisions
String operators for manipulating strings
Data operators, providing access to the properties of source features
Camera operators, providing access to the parameters defining the current map view

Expressions are represented as JSON arrays. The first element of an expression array is a string naming the expression operator, e.g. "*" or "case". Elements that follow (if any) are the arguments to the expression. Each argument is either a literal value (a string, number, boolean, or null), or another expression array.

[expression_name, argument_0, argument_1, ...]

下面汇总具体的例子:


['match', ['get', property], inputValue, outputValue if match, outputValue if not a match]
filterDay = ['match', ['get', 'Day'], ['Sat', 'Sun'], false, true];
// 应用多个过滤器
map.setFilter('collisions', ['all', filterHour, filterDay]);

"filter": ['==', ['type',['get', 'key']],'value']
map.setFilter('collisions', ['==', ['number', ['get', 'Hour']], hour]);
filter: ['==', ['number', ['get', 'Hour']], 12]


'circle-color': [
        'interpolate',
        ['linear'],
        ['number', ['get', 'Casualty']],
        0, '#2DC4B2',
        1, '#3BB3C3',
        2, '#669EC4',
        3, '#8B88B6',
        4, '#A2719B',
        5, '#AA5E79'
      ]
// 以下两个语句效果一致 
map.setFilter('jq',['==',['get','jqhour'],'somethingstring']);

map.setFilter('jq',['in','jqhour','smstring']);
'circle-radius': [
'interpolate',
['linear'],
['get', 'mag'],
6,
20,
8,
40
]

 

 

 

 

 

 

 

 

 

 

 

 

 

 

你可能感兴趣的:(mapbox,过滤器,filter)