是否可以通过 poi_label 过滤建筑物图层?

Is it possible to filter buildings layer by the poi_label?

我想展示 3d 建筑(填充-挤压) 某些建筑。

是否可以根据建筑物的名称(来自 poi_label)过滤建筑物列表?

例如:

map.addLayer({
  'id': 'mybuildinglayer',
  'type': 'fill-extrusion',
  'source': {
     type: 'vector',
     url: 'mapbox://mapbox.mapbox-streets-v7'
  },
  'source-layer': 'building',
  'filter': [
      "==",
      "name",
      "McDonalds"
   ],
   'paint': {
      'fill-extrusion-color': '#FFFFFF',
      'fill-extrusion-height': 50,
      'fill-extrusion-base': 0,
   }
});

您需要按名称过滤要素,并找到包含这些要素的建筑物(使用 turf.js):

// All features rendered:
var fs = map.queryRenderedFeatures();

// Filtering features by source and by name:
var names = ['McDonald\'s Langstrasse'];
var ps = fs.filter(f => 
  f.sourceLayer === 'poi_label' && 
  names.indexOf(f.properties.name) !== -1
);

// Filter the buildings by source and by the entry of feature inside the building:
var bs = fs.filter(f =>
  f.sourceLayer === 'building' &&
  ps.filter(p =>          
    turf.pointsWithinPolygon(turf.points([p.geometry.coordinates]), f.geometry)
        .features.length > 0
  ).length > 0
);

[https://jsfiddle.net/nq28kc4j/]