Cesium加載城市白膜數(shù)據(jù)
數(shù)據(jù)獲取
首先,城市建筑數(shù)據(jù)可以去網(wǎng)上扒一些,拿到的都是shp格式的文件。
數(shù)據(jù)轉(zhuǎn)化
shp文件可以很方便的轉(zhuǎn)為Geojson文件,然后再通過Cesium導入也可以實現(xiàn)效果。效果如下所示:
圖中就是用Geojson數(shù)據(jù)添加到地圖中,大約有117000條數(shù)據(jù),加載的效果還可以。但是數(shù)據(jù)量大加載時間會比較長而且會卡頓。
shp數(shù)據(jù)文件可以通過CesiumLab來轉(zhuǎn)換為3dtiles,然后再通過Cesium加載到地球中。文章來源:http://www.zghlxwxcb.cn/news/detail-502368.html
加載3DTiles
下面封裝了一個添加3DTiles的方法add3DTiles()
,可以直接拿去使用。文章來源地址http://www.zghlxwxcb.cn/news/detail-502368.html
// 添加城市白膜3DTiles
add3DTiles(params) {
const {
url,
complete, // 加載完成的回調(diào)函數(shù)
flyTo = false,
show = true
} = params
console.log(url + '——數(shù)據(jù)開始加載');
console.time('3dtiles');
const tileset = viewer.scene.primitives.add(new Cesium.Cesium3DTileset({
url,
show,
shadows: Cesium.ShadowMode.DISABLED,
luminanceAtZenith: 1,
}))
// 監(jiān)聽數(shù)據(jù)加載完成
tileset.allTilesLoaded.addEventListener(() => {
console.log('數(shù)據(jù)加載完成');
console.timeEnd('3dtiles');
if(typeof complete == 'function') {
complete()
} else {
console.error('complete參數(shù)值格式有誤,應為function類型')
}
// 加載完成后飛往該處
if(flyTo) {
viewer.flyTo(tileset);
}
});
return tileset
}
到了這里,關于Cesium加載城市白膜數(shù)據(jù)3DTiles的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!