import { WXLOG, fetchJson } from "@metoceanapi/wxtiles-common/utils/wxtools"; import { WxTileSource } from "../wxsource/wxsource"; import type { FrameworkOptions } from "../wxsource/wxsourcetypes"; import type { WxAPI } from "./WxAPI"; import type { WxAllBoundariesMeta, WxAllDatasetsShortMetas, WxDatasetMeta, WxVariableMeta, WxDate, WxLayerVarsNames, WxLayerOptions, WxDataSetManagerOptions, } from "@metoceanapi/wxtiles-common/types"; import { BaseDatasetManager } from "@metoceanapi/wxtiles-common/managers/BaseDatasetManager"; /** * Class for managing a WX dataset and its related operations. * * Instances of this class handle metadata, variables, valid times, zoom levels, * and URI construction for WX datasets. * * **Usage Note:** Do not create instances directly using the constructor. * Use {@link WxAPI.createDatasetManager} instead. * * @example * ```ts * const wxapi = new WxAPI({ dataServerURL: "https://example.com" }); * const wxDatasetManager = await wxapi.createDatasetManager("gfs.glBobal"); * console.log(wxDatasetManager.getAllVariables()); * ``` */ export class WxDataSetManager extends BaseDatasetManager { /** * Creates a source layer for this dataset. * * @param {WxSourceLayerOptions} options - Layer-specific options (e.g., variables). * @param {FrameworkOptions} frwOptions - Framework-specific options. * @returns {WxTileSource} - A new tile source ready for rendering. * * @example * ```ts * const sourceLayer = wxDatasetManager.createSourceLayer( * { variable: "temperature" }, * { framework: "mapbox" } * ); * ``` */ // TODO: existence of this not enforced by WxAPI class definition, can we improve the typing? createSourceLayer( options: WxSourceLayerOptions, frwOptions: FrameworkOptions, ): WxTileSource { WXLOG(`WxDataSetManager.createSourceLayer: ${this.datasetName}`); const layerOptions: WxLayerOptions = { ...options, variables: this._checkCombineVariableIfVector(options.variable), wxdatasetManager: this, }; return new WxTileSource(layerOptions, frwOptions); } } /** * Options for creating a source layer using {@link WxDataSetManager.createSourceLayer}. */ export interface WxSourceLayerOptions extends Omit, "variables" | "wxdatasetManager"> { /** The variable to be displayed in the layer. */ variable: string; }