Skip to main content

load

load(url: string | File, loaders: Loader, options?: LoaderOptions]): Promise<unknown>
load(url: string | File, loaders: Loader[], options?: LoaderOptions]): Promise<unknown>
load(url: string | File, options?: LoaderOptions): Promise<unknown>

The load() function is used to load and parse data with a specific loader object. An array of loader objects can be provided, in which case load will attempt to autodetect which loader is appropriate for the file.

The load() function can also be used with multiple loaders. load() takes a url and one or more loader objects, checks what type of data that loader prefers to work on (e.g. text, JSON, binary, stream, ...), loads the data in the appropriate way, and passes it to the loader.

The loaders parameter can also be omitted, in which case any loader objects previously registered with registerLoaders will be used.

  • url - Urls can be data urls (data://) or a request (http:// or https://) urls, or a file name (Node.js only). Also accepts File or Blob object (Browser only). Can also accept any format that is accepted by parse, with the exception of strings that are interpreted as urls.
  • loaders - can be a single loader or an array of loaders. If single loader is provided, will force to use it. If ommitted, will use the list of pre-registered loaders (see registerLoaders)
  • options - see LoaderOptions.

Returns:

  • If options.fetch is not overridden with a new function.
  • Return value depends on the loader category.

Notes:

  • If url is not a string, load will call parse directly.
  • Any path prefix set by setPathPrefix will be appended to relative urls.
  • load takes a url and a loader object, checks what type of data that loader prefers to work on (e.g. text, binary, stream, ...), loads the data in the appropriate way, and passes it to the loader.
  • If @loaders.gl/polyfills is installed, load will work under Node.js as well.

Options

A loader object, that can contain a mix of options:

  • options defined by the parse function can be specified.
  • options specific to any loaders can also be specified (in loader specific sub-objects).

Please refer to the corresponding documentation page for for parse and for each loader for details.