[英]How to save geojson data from OSRM to a text file
我正在使用传单常规计算机和mapbox来获取路线。 一切正常,我可以console.log退出路由,但是理想情况下,我想将geojson数据保存到文本文件中,这样我就可以进行测试而无需每次都调用API,并且也可以进行更改。 我在浏览器中使用javascript,只能在node.js中看到示例,这是唯一的方法吗?
有任何想法吗?
您可以使用FileSaver库将文件保存在客户端
// add the geojson to the map
const geoJson = L.geoJson(freeBus).addTo(map);
// use external library to save geojson
const saveTxt = (content, filename) => {
const file = filename + ".json";
saveAs(new File([JSON.stringify(content)], file, {
type: "text/plain;charset=utf-8"
}), file);
};
// invoke the function by passing geojson to be saved
// and .txt file name
saveTxt(geoJson.toGeoJSON(), "test");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.