[英]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.