cesium解析txt,dxf,shpfile的zip,geojson文件
geojson的文件,读取后直接就是geojson格式,cesium有相对应的示例可以直接加载,所以没有过多要说的.
dxf文件是借助一个js库读取的,返回的也是geojson格式.同样用来直接加载即可
shpfile解析同dxf文件的解析步骤
txt文件由于参数过于特殊,而且并没有找到一些相对应的工具库,所以自己去解析的,对于格式有很大的局限性,目前支持一种格式,稍微我会把格式分享出来,仅供参考
话不多说,上代码 ✅
const axios = require('axios');
let fileType = params.fileUrl
.split('.')
.pop()
.toLowerCase();
let FormParams = {
url: `/getFile${
params.fileUrl}`,
method: 'get',
headers: {
needToken: true
}
};
if (fileType == 'zip') FormParams.responseType = 'arraybuffer';
axios(FormParams).then(res => {
switch (fileType) {
case 'dxf':
let blob = new Blob([res.data], {
type: 'application/octet-stream'
});
let files = new window.File([blob], 'admin.dfx', {
type: 'application/octet-stream'
});
this.setDXF(files);
break;
case 'geojson':
if (res.status == 200) {
// console.log(res.data);
let sourceData = Cesium.GeoJsonDataSource.load(res.data);
this.viewer.dataSources.add(sourceData);
this.viewer.flyTo(sourceData);
}
break;
case 'txt':
this.setTxt('', res.data);
break;
case 'zip':
let ziPblob = new Blob([res.data], {
});
let zipFile =

本文介绍如何使用Cesium加载多种格式的地理空间数据文件,包括TXT、DXF、SHPFILE及ZIP压缩包内的文件。针对不同格式,文章提供了具体的解析方法和示例代码,如借助第三方库将DXF转换为GeoJSON格式,并直接加载到Cesium中。

4498

被折叠的 条评论
为什么被折叠?



