Loading using a zip file

Works in the browser using jszip.





            
function filesUploaded() {
  const elem = document.getElementById('fileselect')

  // When a zip file is uploaded use jszip to unzip it
  JSZip.loadAsync(elem.files[0]).then(function (zip) {

    // Find the shp and dbf files from the zip
    const fileNames = Object.keys(zip.files)
    const shpName = fileNames.filter(f => f.includes('.shp'))[0]
    const dbfName = fileNames.filter(f => f.includes('.dbf'))[0]
    const projName = fileNames.filter(f => f.includes('.prj'))[0]

    // Use JSZip to retrieve the arraybuffers of those files
    Promise.all([
      zip.files[shpName].async("arraybuffer"),
      zip.files[dbfName].async("arraybuffer"),
      zip.files[projName].async("text")
      ]).then((values) => {
      
      // Once we have both the arraybuffers construct our ShpToGeoJson  
      const zippedShp = new ShpToGeoJson({
        arraybuffers: {
          shpBuffer: values[0],
          dbfBuffer: values[1],
          projString: values[2]
        }
      })
      const zippedGeoJson = L.geoJSON(zippedShp.getGeoJson()).addTo(map)
      map.fitBounds(zippedGeoJson.getBounds())
    });
  });
}