MapboxGL.SymbolLayer filter expression to check if id in array

1.2k Views Asked by At

I am trying to do the following with react-native-mapbox-gl

<MapboxGL.SymbolLayer 
  id="controlPointIcon" 
  filter={['all', ['in', 'id', this.state.nextPossible], ['==', 'type', 'alt']]} 
  style={mapStyle.iconControlPoint} 
/>

The filter is supposed the match only if the given GeoJSON feature has its property id included in the array this.state.nextPossible and if the property type matches 'alt'.

I am clearly doing something wrong, the error I am getting says:

Invalide predicate: "id" ... NSInvalidArgumentException 
reason [__NSCFNumber isEqualTOString:]: unrecognized selector sent to instance ...

Any idea how to solve this with mapbox filter expressions?

1

There are 1 best solutions below

0
On

See https://github.com/react-native-mapbox-gl/maps/issues/70#issuecomment-499775185 in is a legacy filter syntax and not supported. Please use match instead.

<MapboxGL.SymbolLayer 
  id="controlPointIcon" 
  filter={
      ['all', 
         ['match', 
            'id', this.state.nextPossible, true, 
            false
         ], 
         ['==', 'type', 'alt']
      ]} 
  style={mapStyle.iconControlPoint} 
/>