node.js制作road数据

tech2023-02-01  112

把geojson数据转变为需要的road数据,以作路径流动效果 并且新加了时间戳 var fs = require(“fs”); fs.readFile(‘data/lianjiangroadgcj02.geojson’, { encoding: “utf-8” }, (err, data) => { var jsonobj=JSON.parse(data); var arr =jsonobj.features; var brr =[]; var crr =[]; for(var i=0;i<arr.length;i++){ brr[i] = arr[i].geometry; crr[i] = brr[i].coordinates; } var lianjiangroad =[]; var lianjiang ={}; for( var j=0;j<crr.length;j++){ var lianjiang ={}; // var pathdata=JSON.stringify(crr[j][0]); lianjiang[“path”] =crr[j][0]; // console.log(crr[j][0]); var k =crr[j][0].length; // console.log(k); var time=[]; for(var p =0;p<k;p++){ time[p] = Math.floor(Math.random() * 900 + 100); } time.sort(function (a,b) { return a-b; }); // console.log(time); lianjiang[“timestamps”]=time; lianjiangroad.push(lianjiang); } var dataJson = JSON.stringify(lianjiangroad); fs.writeFileSync(’./data/lianjiang.json’,dataJson); });

最新回复(0)