我已经做了一个地图使用传单绘图插件,让用户下载他们画的项目。这些绘制的项以GeoJSON的形式导出,使用这里中的以下代码
document.getElementById('export').onclick = function(e) {
// Extract GeoJson from featureGroup
var data = featureGroup.toGeoJSON();
// Stringify the GeoJson
var convertedData = 'text/json;charset=utf-8,' +
encodeURIComponent(JSON.stringify(data));
// Create export
document.getElementById('export').setAttribute('href', 'data:' +
convertedData);
document.getElementById('export').setAttribute('download','data.geojson');
}这是完美的,但如果在导出之前将GeoJSON转换为.kml,则会更加理想。我知道toKml插件,但我正在努力使它工作(我仍然是非常新的这一切)。我要在哪里补充:
var kml = tokml(geojsonObject);发布于 2018-05-04 16:35:03
您可以使用tokml(data)将您的tokml(data)对象转换为KML,并使用数据URL中的结果字符串,并使用适当的MIME类型和文件名:
var data = featureGroup.toGeoJSON();
var kml = tokml(data);
var convertedData = 'application/xml;charset=utf-8,' + encodeURIComponent(kml);
// if you want to use the official MIME type for KML
// var convertedData = 'application/vnd.google-earth.kml+xml;charset=utf-8,' +
// encodeURIComponent(kml);
document.getElementById('export').setAttribute('href', 'data:' + convertedData);
document.getElementById('export').setAttribute('download', 'data.kml');https://stackoverflow.com/questions/50149464
复制相似问题