首先
1.安装
npm install geobuf
npm install pbf
2.引用
import geobuf from 'geobuf';
import pbf from 'pbf';
3.使用方法
//res为要转换的数据
var vt = new pbf(res);
var geojson = geobuf.decode(vt);
4.要点
该方法要求数据类型为arraybuffer
所以在调用接口时设置数据返回类型
//接口为get时的写法
export function getCountryRoads(params){
return request ({
url:'接口地址',
method:'get',
responseType: 'arraybuffer'
})
}
//接口为post时的写法
axios.post('url', 参数, {
responseType: 'arraybuffer',
})
.then((res) => {
let data = res.data;
var vt = new pbf(data);
var geojson = geobuf.decode(vt);
})