0

I am getting the the OSM Buildings (mapbox://mapbox.mapbox-streets-v8) via mapbox style. I want to hide some building within a BBox. Getting the corresponding features:

var features = this.map.queryRenderedFeatures(
  [ new mapboxgl.Point(468, 213) as PointLike,
    new mapboxgl.Point(43, 95) as PointLike ],
  { layers: ['building'] });

Trying to filter them:

    function buildFilter(arr) {
      var filter = ['in', '$id'];
      if (arr.length === 0) {
        return filter;
      }
      for(var i = 0; i < arr.length; i += 1) {
        filter.push(arr[i]);
      }
      return filter;
    }

    this.map.setFilter("building", buildFilter(ids));
  }

But there seems to be no unique ids? As a result a lot of buildings are being hidden, if I filter with this method. The mapbox documentation notes:

OpenStreetMap IDs are not stored as object properties but as object IDs within the vector tile. This means they are not available for styling via Mapbox Studio, but can still be interacted with via Mapbox GL JS and other vector tile libraries.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.