Skip to content

Function: writeLayersZip() ​

ts
function writeLayersZip(layers, options?): Promise<Uint8Array<ArrayBufferLike>>;

Defined in: layers.ts:116

Converts several GeoJSON inputs into a single zip archive.

Per-layer options override the shared ones, so a common epsg can be set once and a single layer can still opt out.

Parameters ​

ParameterTypeDescription
layersreadonly LayerInput[]The layers to write. Each needs a name and geojson.
optionsWriteLayersOptionsShared write options, plus layout, folder and level.

Returns ​

Promise<Uint8Array<ArrayBufferLike>>

The zip archive as bytes.

Throws ​

If layers is empty, if two layers resolve to the same name, or if any layer fails to convert. A layer's failure names the layer, so a bad geometry in a batch of twenty is still traceable.

Examples ​

A utility network as one archive

ts
const zip = await writeLayersZip(
  [
    { name: 'StormManholes', geojson: manholes },
    { name: 'StormPipes', geojson: pipes },
    { name: 'Basins', geojson: basins },
  ],
  { epsg: 26915, folder: 'storm-network' },
);

One inner zip per layer, for an uploader that wants them separately

ts
const zip = await writeLayersZip(layers, { layout: 'nested', epsg: 26915 });

Re-pack what you just read

ts
const layers = await readShapefileZip(incoming);
const repacked = await writeLayersZip(layers, { layout: 'folders' });

Released under the MIT License.