有没有办法从 Mapbox API 获取建筑信息(几何形状、高度等)?
我从这个例子开始:https://www.mapbox.com/mapbox-gl-js/example/3d-buildings/ 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/api-documentation/#retrieve-features-from-vector-tiles
例如,如果我这样称呼:
我得到了各种信息,但没有任何与建筑物有关的信息。
根据这个:https://www.mapbox.com/blog/mapbox-studio-building-heights/ https://www.mapbox.com/blog/mapbox-studio-building-heights/
该信息应该在某处
我找到了解决方案:
// 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)
});
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)