gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 00:48:28 24 4
gpt4 key购买 nike

我想针对某些建筑物显示 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/ ]

关于javascript - 是否可以通过 poi_label 过滤建筑物层?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53147172/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com