有没有办法从mapbox API获取建筑信息(几何,高度等)?
我从这个例子开始: https://www.mapbox.com/mapbox-gl-js/example/3d-buildings/ 它在地图视图上添加了3D图层。我只需要获取用于生成3D构建的信息,以便在我的应用程序中使用。
所以我尝试使用这个API: https://www.mapbox.com/api-documentation/#retrieve-features-from-vector-tiles
例如,如果我这样称呼:
我得到了各种各样的信息,但与建筑没什么关系。
根据这个: https://www.mapbox.com/blog/mapbox-studio-building-heights/
信息应该在某处
答案 0 :(得分:2)
我找到了解决方案:
// Dafault public token, replace with yours if you have one
mapboxgl.accessToken = 'pk.eyJ1IjoibHZpZ2dpYW5pIiwiYSI6ImNpeHZvbGVqMzAwMGoyd3J5YXllbnpuOHQifQ.RAyB0ZTsnLggAZYp_TPmHQ';
var map = new mapboxgl.Map({
container: div,
style: 'mapbox://styles/mapbox/outdoors-v9',
interactive: false
});
map.fitBounds(
someBounds, // arbitrary bounds
{
linear: true
});
map.on("load", function(){
features = map.queryRenderedFeatures(
{ layers: ["building"], filter: ['==', 'extrude', 'true']}); // This is where I get building information
features.forEach(function(feature){
console.log(feature.geometry); // feature.geometry getter returns building shape points (basement)
console.log(feature.properties.height); // this is the building height
console.log(feature.properties.min_height); // this is the building part elevation from groung (e.g. a bridge)
});
});