gpt4 book ai didi

javascript - 从 mapbox api 获取建筑信息

转载 作者:行者123 更新时间:2023-11-30 15:23:35 26 4
gpt4 key购买 nike

有没有办法从 mapbox API 获取建筑信息(几何、高度等)?

我从这个例子开始: https://www.mapbox.com/mapbox-gl-js/example/3d-buildings/它在 map View 上添加了一个 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=

我得到了各种信息,但与建筑物无关。

据此: 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)
});
});

关于javascript - 从 mapbox api 获取建筑信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43325687/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com