Skip to content

Function: readShapefileFile() ​

ts
function readShapefileFile(file, options?): Promise<ShapefileLayer[]>;

Defined in: browser.ts:131

Reads a zipped shapefile straight from a File or Blob.

Takes what an <input type="file">, a drop event, or the File System Access API hands you, and returns every layer the archive contains.

Parameters ​

ParameterTypeDescription
fileBlob | FileThe archive, as a File from a picker or any Blob.
optionsReadOptionsDecoding settings passed through to readShapefileZip.

Returns ​

Promise<ShapefileLayer[]>

One entry per layer in the archive, sorted by name.

Throws ​

If the file is not a readable zip, or holds no .shp.

Example ​

ts
input.addEventListener('change', async () => {
  const file = input.files?.[0];
  if (!file) return;

  const layers = await readShapefileFile(file);
  for (const layer of layers) {
    map.addSource(layer.name, { type: 'geojson', data: layer.geojson });
  }
});

Released under the MIT License.