Stranger in the Q
Stranger in the Q

Reputation: 3898

mapbox: disable one feature rendering

i want to disable rendering of only one extruded building in my case, i looking for something like this

map.on('load', function () {
    map.addLayer({
        'id': '3d-buildings',
        'source': 'mapbox',
        'source-layer': 'building',
        "filter": ["!=", "id", "12345"],
        'type': 'fill-extrusion',
        'paint': {
            'fill-extrusion-color': '#bbb',
            'fill-extrusion-height': 10,
            'fill-extrusion-base': 0,
            'fill-extrusion-opacity': 1
        }
    });

})

following expression is incorrect:

"filter": ["!=", "id", "12345"]

mapbox-gl-0.44.1

Upvotes: 2

Views: 1405

Answers (1)

stdob--
stdob--

Reputation: 29167

The filter retrieves the property value from the properties of the current feature. Make sure that the building id is in the properties:

{
  "type": "Feature",
  "properties": {
    "id": "12345",
    "base_height": 30,
    "height": 40
  },
  "geometry": {...}
  }
}

Upd: Gets the feature's id, if it has one: ["id"]. And, of course, you need to take into account the possible type of identifier:

"filter": ["!=", ["id"], 12345]

For example click on the building to hide it: [ https://jsfiddle.net/yedg641a/ ]

Upvotes: 2

Related Questions