A custom layer source implementation for displaying weather data tiles. This class integrates with Leaflet and the WxTiles API to fetch, display, and manage tiles representing weather data such as temperature, wind speed, or other meteorological variables.

Example

async function initializeWxSource() {
try {
const wxapi = new WxAPI({ dataServerURL: 'http://dataserver.com' });
const datasetName = 'gfs.global';
const variable = 'air.temperature.at-2m';

// Create a dataset manager
const wxDatasetManager = await wxapi.createDatasetManager(datasetName);

// Create a layer source
const wxsource = wxdatasetManager.createSourceLayer(
{ variable },
{ attribution: 'WxTiles' },
);

console.log('WxTileSource initialized:', wxSource);
} catch (error) {
console.error('Error initializing WxTileSource:', error);
}
}

initializeWxSource();

Alternatively, use createSourceLayer to simplify the creation process.

Hierarchy

Constructors

Properties

_needUpdateDSManager: boolean = false

A boolean flag indicating whether the dataset manager needs to be updated or not.

id: string

Unique Layer Identifier

A required unique identifier for the layer. Useful for managing multiple layers and tracking them within a map instance.

Accessors

  • get wxdatasetManager(): WxDatasetManagerT
  • returns the dataset manager of the source

    Returns

    the dataset manager of the source

    Returns WxDatasetManagerT

Methods

  • Iterates over all tiles and applies a callback function.

    Returns

    An array of results from the callback function.

    Type Parameters

    • T

    Parameters

    • func: ((wxtile: WxTile) => T)

      The callback function to execute for each tile.

        • (wxtile: WxTile): T
        • Parameters

          • wxtile: WxTile

          Returns T

    • name: string

      A name for logging purposes.

    Returns T[]

  • Reloads the visible tiles on the map. This method is typically used during animations or time-based updates.

    Parameters

    • Optional requestInit: WxRequestInit

      Request options such as signals for aborting requests.

    Returns Promise<void>

  • Retrieves the coordinates of tiles currently visible on the map.

    Returns

    An array of tile coordinates.

    Returns XYZ[]

  • Creates a new tile element and loads its data.

    Returns

    The created canvas element representing the tile.

    Parameters

    • coords: Coords

      The coordinates of the tile to load.

    • done: DoneCallback

      A callback function to signal completion.

    Returns HTMLElement

  • Get all available times for the source.

    Returns

    An array of all available times for the source.

    Returns string[]

  • Internal

    Get the raster data cache of the layer. Used in CustomWxTilesLayer.render.

    Returns

    The raster data cache of the layer.

    Returns WxRasterDataCache

  • Get a copy of the current style of the source.

    Returns

    A copy of the current style of the source.

    Returns WxColorStyleStrict

  • Get the metadata of the current variable(s).

    Returns

    • The metadata of the current variable.

    Returns WxVariableMeta

  • Retrieves information about a specific point on the map.

    Returns

    Information about the tile at the specified point, or undefined if unavailable.

    Parameters

    • lnglat: WxLngLat

      The longitude and latitude of the point.

    • anymap: any

      The map instance. This is kept generic to allow flexibility.

    Returns undefined | WxTileInfo

  • Get the metadata of the current variable(s).

    Deprecated

    Returns

    • The metadata of the current variable.

    Returns WxVariableMeta

  • Get the current time of the source.

    Returns

    The current time of the source from array of times.

    Returns string

  • Get current variables (1 or 2) of the source/layer.

    Returns

    variables of the source.

    Returns WxLayerVarsNames

  • Preloads tiles for faster rendering for a specific time is set setTime. If the time is not available, the closest time will be used.

    Returns

    A promise that resolves when the tiles are preloaded.

    Parameters

    • time: WxDate

      The time to preload.

    • Optional requestInit: WxRequestInit

      Request options for fetch.

    Returns Promise<void>

  • Set the coarse maximum zoom level to make tiles load faster during animation.

    Returns

    A promise that resolves when the coarse maximum zoom level is set.

    Parameters

    • level: number = 2

      The coarse maximum zoom level to set.

    Returns Promise<void>

  • Set the style of the source by its name from default styles.

    Returns

    A promise that resolves when the style is set.

    Parameters

    • wxstyleName: string

      Name of the new style to set.

    • reload: boolean = true

      If true, the source will be reloaded and rerendered.

    Returns Promise<void>

  • Set time and render the source. If the time is not available, the closest time will be used.

    Returns

    A promise that resolves with current time step when the time is set and the source is loaded and rendered.

    Parameters

    • Optional time: WxDate

      Time to set.

    • Optional requestInit: WxRequestInit

      Request options for fetch.

    • Optional redraw: boolean

    Returns Promise<string>

  • Redraws the tiles currently visible on the map. This ensures that updated raster data or animations are displayed.

    Returns void

  • Update the current style object of the source partially or completely.

    Returns

    A promise that resolves when the style is set.

    Parameters

    • Optional style: WxColorStyleWeak

      Style's fields to set.

    • reload: boolean = true

      If true, the source will be reloaded and rerendered.

    • Optional requestInit: WxRequestInit

      Request options.

    Returns Promise<void>

Generated using TypeDoc