none
Layer filter string operator RRS feed

  • Question

  • I would like to filter features of the layer which id property is included in the array.

    so I have var ids = [24, 53, 98];

    and I want to filter features only with id == 24 or id == 53 or id == 98

    is it possible? something like:

    layer.setOptions({
        filter: ['includes', ['get', 'id'], ids]
    });

    Monday, August 12, 2019 9:19 AM

All replies

  • This can be achieved using a 'match' expression. This expression allows an array of values to be passed in for comparison. Here is a sample filter for your id values.

    filter: [
        'match',    //The type of expression.
    
        ['get', 'id'],  //What property to compare.
        [24, 53, 98],        //What values to compare.
    
        true,   //Result if there is a match.
    
        false   //Result if not a match.
    ]
    I'll add this example to the docs as I'm sure others will want to do something like this.


    Monday, August 12, 2019 7:54 PM