2017-04-10 234 views
1

有沒有辦法從mapbox API獲取建築信息(幾何體,高度等)?從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://api.mapbox.com/v4/mapbox.mapbox-streets-v7/tilequery/-74.0066,40.7135.json?radius=50&limit=50&access_token=

我得到了各種各樣的informartion,但沒有涉及到建築物。

根據此: https://www.mapbox.com/blog/mapbox-studio-building-heights/

的信息應該是有什麼地方

回答

0

我已經找到了解決辦法:

// 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) 
    }); 
});