我已經找到了解決辦法:
// 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)
});
});