wasm-spatial-core
    Preparing search index...

    Function parseGeoJsonStream

    • Parse a GeoJSON FeatureCollection in chunks, calling on_chunk with each batch of coordinate data and progress information.

      • input — The full GeoJSON string (must be a FeatureCollection).
      • chunk_size — Number of features to process per chunk (e.g. 1000). Larger chunks = fewer JS↔WASM transitions but longer UI blocking.
      • on_chunk — A JS callback: (coords: Float64Array, processed: u32, total: u32) => void
      parseGeoJsonStream(hugeGeoJson, 500, (coords, processed, total) => {
      // Upload coords to GPU, update progress bar
      progressBar.value = processed / total;
      gl.bufferSubData(gl.ARRAY_BUFFER, offset, coords);
      });

      Standard JSON parsers (serde_json) build the full DOM in memory. For a 200 MB FeatureCollection this costs ~400 MB WASM heap.

      This function first parses the full FeatureCollection (unavoidable with the geojson crate), but then processes and emits features in chunks, allowing the JS side to consume and discard coordinate data incrementally rather than holding all coordinates in memory at once.

      For true streaming (constant memory), a custom tokeniser would be needed. This is planned for a future release using serde_json::StreamDeserializer over raw bytes.

      Parameters

      • input: string
      • chunk_size: number
      • on_chunk: Function

      Returns number