Libraries used:
Create kml file - https://www.npmjs.com/package/@maphubs/tokml Create geojson - https://www.npmjs.com/package/geojson Create kmz using zip - https://www.npmjs.com/package/jszip
Create KML File
const points = [
{latitude: 39.984, longitude: -75.343},
{latitude: 39.284, longitude: -75.833},
{latitude: 39.123, longitude: -74.534},
{line: [[102.0, 0.0], [103.0, 1.0], [104.0, 0.0], [105.0, 1.0]],}
]
const geojsonObject = geojson.parse(points, {
Point: ['latitude', 'longitude'],
LineString: 'line',
}), {
documentName: 'Document Name',
documentDescription: 'KML Export'
}
const response = tokml(geojsonObject);
Content-type for kml:
'Content-Type': 'application/vnd.google-earth.kml+xml',
Create KMZ File
const zip = new JSZip();
zip.file('doc.kml', kmlFile);
return zip.generateAsync({ type: 'nodebuffer' });
Content-type for kml:
'Content-Type': 'application/vnd.google-earth.kmz',
Top comments (0)