I want to access local folder in system and auto download zipped shp file which holds .shp, .prj, .shx and .dbf files in it. I want a feature such that after every 10sec all the new shapes drawn in my map should get auto stored in my local folder. Currently I'm able to export .zip file using SHP-Write library but it exports only once and only exports as response to users action but I dont want that. I want to store zip file to be auto saved without prompting to user to save and select the folder for saving the file.
const exportShapefile = async () => {
if (!drawnShapes || drawnShapes.length === 0) {
console.log("returning");
return;
}
const iteratedData = [];
drawnShapes.forEach((shape) => {
if (shape.geometry.type === "LineString") {
const coordinates = [shape.geometry.coordinates];
iteratedData.push({
type: "Feature",
geometry: {
type: "LineString",
coordinates: [coordinates],
},
properties: { name: "Line Feature" },
});
} else {
iteratedData.push(shape);
}
});
console.log("drawnShapes", drawnShapes);
console.log("iteriteratedData", iteratedData);
const geoJson = {
type: "FeatureCollection",
features: drawnShapes,
};
const folderName = exportFolderName.trim() || "myshapes";
var options = {
folder: folderName,
types: {
point: `${folderName}_points`,
polygon: `${folderName}_polygons`,
line: `${folderName}_lines`,
rectangle: `${folderName}_rectangle`,
circle: `${folderName}_circle`,
polyline: `${folderName}_polyline`,
},
};
const fileName = exportFileName.trim() || "shapefile";
await shpwrite.download(geoJson, options, `${fileName}.zip`);
};
I tried with this approach where it exports .zip file when I export it.