# Functions

### Library Functions

#### `setLibrary<T>(name: string, library: T): void`

Sets an optional dependency.

By default, optional dependencies are loaded with a dynamic import. If the dynamic import is not supported by your environment, use this function to set the optional dependency explicitly.

### Load Functions

#### `loadTextureData(url: string, options?: CachedLoadOptions<TextureData>): Promise<`[`TextureData`](/weatherlayers-gl/types.md#texturedata)`>`

Loads the url as texture data. The url should be PNG, WebP or GeoTIFF image.

GeoTIFF requires [geotiff.js ](https://github.com/geotiffjs/geotiff.js/)as an optional dependency if loading GeoTIFF images.

Use in `image`/`image2` property.

#### `loadJson(url: string, options?: CachedLoadOptions<any>): Promise<any>`

Loads the url as JSON. The response should be a JSON file.

#### `LoadOptions`

```typescript
interface LoadOptions {
  headers?: Record<string, string>;
  signal?: AbortSignal;
}
```

Data request load options.

* `headers` - custom HTTP headers
* `signal` - abort signal for cancelling the request

#### `CachedLoadOptions`

```typescript
interface CachedLoadOptions<T> extends LoadOptions {
  cache?: Map<string, T | Promise<T>> | false;
}
```

The response is cached to the given cache, or to the default global cache, or caching can be disabled by `false`.

### Datetime Functions

#### `getClosestStartDatetime(datetimes:` [`DatetimeISOString`](/weatherlayers-gl/types.md#datetimeisostring)`[], datetime:` [`DatetimeISOString`](/weatherlayers-gl/types.md#datetimeisostring)`):` [`DatetimeISOString`](/weatherlayers-gl/types.md#datetimeisostring) `| undefined`

Gets the closest start datetime (i.e. lower or equal) for the given datetime from the given datetimes.

Use to find the correct start image to load, to be used in `image` property.

#### `getClosestEndDatetime(datetimes:` [`DatetimeISOString`](/weatherlayers-gl/types.md#datetimeisostring)`[], datetime:` [`DatetimeISOString`](/weatherlayers-gl/types.md#datetimeisostring)`):` [`DatetimeISOString`](/weatherlayers-gl/types.md#datetimeisostring) `| undefined`

Gets the closest end datetime (i.e. greater or equal) for the given datetime from the given datetimes.

Use to find the correct end image to load, to be used in `image2` property. Applicable only if `datetimeInterpolate` is enabled.

#### `getDatetimeWeight(startDatetime:` [`DatetimeISOString`](/weatherlayers-gl/types.md#datetimeisostring)`, endDatetime:` [`DatetimeISOString`](/weatherlayers-gl/types.md#datetimeisostring)`, datetime:` [`DatetimeISOString`](/weatherlayers-gl/types.md#datetimeisostring)`): number`

Gets the datetime weight between the given start and end datetime for the given datetime. The returned value is a number `0-1`.

Use in `imageWeight` property. Applicable only if `datetimeInterpolate` is enabled.

#### `offsetDatetime(datetime:` [`DatetimeISOString`](/weatherlayers-gl/types.md#datetimeisostring)`, hour: number):` [`DatetimeISOString`](/weatherlayers-gl/types.md#datetimeisostring)

Adds hours to the given datetime.

#### `offsetDatetimeRange(datetime:` [`DatetimeISOString`](/weatherlayers-gl/types.md#datetimeisostring)`, startHour: number, endHour: number):` [`DatetimeISOStringRange`](/weatherlayers-gl/types.md#datetimeisostringrange)

Adds start hour and end hour to the given datetime. The returned value is a datetime range.

### Raster functions

#### `getRasterPoints(imageProperties:` [`ImageProperties`](/weatherlayers-gl/types.md#imageproperties)`, bounds: GeoJSON.BBox, positions: GeoJSON.Position[]): GeoJSON.FeatureCollection<GeoJSON.Point,` [`RasterPointProperties`](/weatherlayers-gl/types.md#rasterpointproperties)`>`

Gets raster points for the given positions.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.weatherlayers.com/weatherlayers-gl/functions.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
