admin管理员组

文章数量:1405134

I'm having a very difficult time understanding Mapbox expressions in Swift. For example, I write the following:

let falseExpression: MapboxMaps.Expression = Exp(.literal) { false }
let combinedFilter: MapboxMaps.Expression = Expression(operator: .all, arguments: [
    Expression.Argument.expression(workIdFilter),
    Expression.Argument.expression(falseExpression)
])

Then I apply "combinedFilter" to the filter property of a layer. I would expect this to always evaluate to false, since 'falseExpression' is literally false, and ".all" means that all the expressions have to be true. And that means it should hide every feature on the layer. But, it doesn't do anything. All the features remain visible.

If I apply 'falseExpression' directly to the layer instead of combinedFilter, it does hide the features. Or if I omit 'workIdFilter' from the combinedFilter, it also evaluates to false and hides all of the features. ('workIdFilter' evaluates to true in this case).

I'm either misunderstanding what (.all) means or I'm writing this wrong.

I'm having a very difficult time understanding Mapbox expressions in Swift. For example, I write the following:

let falseExpression: MapboxMaps.Expression = Exp(.literal) { false }
let combinedFilter: MapboxMaps.Expression = Expression(operator: .all, arguments: [
    Expression.Argument.expression(workIdFilter),
    Expression.Argument.expression(falseExpression)
])

Then I apply "combinedFilter" to the filter property of a layer. I would expect this to always evaluate to false, since 'falseExpression' is literally false, and ".all" means that all the expressions have to be true. And that means it should hide every feature on the layer. But, it doesn't do anything. All the features remain visible.

If I apply 'falseExpression' directly to the layer instead of combinedFilter, it does hide the features. Or if I omit 'workIdFilter' from the combinedFilter, it also evaluates to false and hides all of the features. ('workIdFilter' evaluates to true in this case).

I'm either misunderstanding what (.all) means or I'm writing this wrong.

Share Improve this question edited Mar 8 at 17:55 Flarosa asked Mar 8 at 17:48 FlarosaFlarosa 1,8812 gold badges23 silver badges40 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

I found the answer:

In my example I referenced 'workIdFilter' but didn't show its definition because it didn't matter, or shouldn't have mattered. Here it is:

let workIdFilter: MapboxMaps.Expression = Exp(.not) {
    Exp(.inExpression) {
        Exp(.get) { "WorkId" }
        Array(hiddenWorkIds)
    }
}

What I'm trying to do here is hide features where the property "WorkId" is contained in the array "hiddenWorkIds".

And here's the problem - when "hiddenWorkIds" is an empty array, it doesn't work right. I can't tell exactly what is happening but I'm guessing there's some error internally that is causing the whole expression to fail and therefore not hide anything.

The workaround is pretty simple -- I just put some dummy value into the array to make sure it is never empty.

This seems like a bug to me. Surely .inExpression should accept an empty list and behave as expected?

本文标签: How does the quotallquot expression in Mapbox for Swift workStack Overflow