2017-04-10 67 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) 
    }); 
});