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 badges1 Answer
Reset to default 0I 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
版权声明:本文标题:How does the "all" expression in Mapbox for Swift work? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744889803a2630702.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论