# 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`](https://docs.weatherlayers.com/types#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`](https://docs.weatherlayers.com/types#datetimeisostring)`[], datetime:` [`DatetimeISOString`](https://docs.weatherlayers.com/types#datetimeisostring)`):` [`DatetimeISOString`](https://docs.weatherlayers.com/types#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`](https://docs.weatherlayers.com/types#datetimeisostring)`[], datetime:` [`DatetimeISOString`](https://docs.weatherlayers.com/types#datetimeisostring)`):` [`DatetimeISOString`](https://docs.weatherlayers.com/types#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`](https://docs.weatherlayers.com/types#datetimeisostring)`, endDatetime:` [`DatetimeISOString`](https://docs.weatherlayers.com/types#datetimeisostring)`, datetime:` [`DatetimeISOString`](https://docs.weatherlayers.com/types#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`](https://docs.weatherlayers.com/types#datetimeisostring)`, hour: number):` [`DatetimeISOString`](https://docs.weatherlayers.com/types#datetimeisostring)

Adds hours to the given datetime.

#### `offsetDatetimeRange(datetime:` [`DatetimeISOString`](https://docs.weatherlayers.com/types#datetimeisostring)`, startHour: number, endHour: number):` [`DatetimeISOStringRange`](https://docs.weatherlayers.com/types#datetimeisostringrange)

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

### Raster functions

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

Gets raster points for the given positions.
