@deltares/fews-web-oc-composables
@deltares/fews-web-oc-composables / useWmsLegend
Function: useWmsLegend()
useWmsLegend(
options):UseWmsLegendReturn
Defined in: useWms/useWmsLegend.ts:76
Alpha
This API is not yet stable and may change in future versions.
Loads a WMS legend graphic for a layer, reactively reloading when legend options change and supporting automatic refresh through refresh. Clears the previous graphic when those options change and preserves the last successful graphic when a refresh for the same options fails. By default, no scheduled refresh policies are enabled.
Parameters
options
| Member | Type | Description |
|---|---|---|
colorScaleRange? | MaybeRefOrGetter<string> | Optional "min,max" color scale range override. |
enabled? | Ref<boolean, boolean> | Controls whether requests and automatic refreshes are enabled. |
layerName | MaybeRefOrGetter<string | undefined> | Name of the layer to load the legend for. |
refresh? | UseWmsRefreshOptions | Configuration for automatic request refreshing. |
style? | MaybeRefOrGetter<Style> | Optional WMS style to render the legend with. |
useDisplayUnits | MaybeRefOrGetter<boolean> | Whether to render the legend using display units. |
webservice? | PiWebserviceOptions | Optional webservice configuration for standalone usage. When omitted, the host-provided webservice context is used. |
Request configuration. See UseWmsLegendOptions.
Returns
| Member | Type | Description |
|---|---|---|
cancel | () => void | Cancels the currently running request, if any. |
error | Readonly<Ref<Error | null>> | Error from the most recent request, or null when there is no error. |
fetch | () => Promise<void> | Fetches the requested WMS data immediately. |
hasAttempted | Readonly<Ref<boolean>> | Whether a request has completed for the current inputs, successfully or not. |
hasLoaded | Readonly<Ref<boolean>> | Whether a successful response is available for the current inputs. |
lastRefreshAt | Readonly<Ref<Date | undefined>> | Time at which the most recent refresh completed successfully. |
lastTriggerPolicy | Readonly<Ref<RefreshPolicy | undefined>> | Policy that caused the most recent refresh. |
legendGraphic | Readonly<Ref<GetLegendGraphicResponse | undefined>> | The loaded WMS legend graphic. |
loading | Readonly<Ref<boolean>> | Whether the initial request is in progress. |
pauseRefresh | () => void | Pauses automatic refreshes. |
refreshing | Readonly<Ref<boolean>> | Whether a subsequent request is in progress. |
requestRefresh | () => void | Requests a refresh through the refresh coordinator. |
resumeRefresh | () => void | Resumes automatic refreshes. |
The legend graphic and request state. See UseWmsLegendReturn.
Example
ts
import { ref } from 'vue'
import { useWmsLegend } from '@deltares/fews-web-oc-composables'
const options = {
layerName: ref('waterlevel'),
useDisplayUnits: true,
webservice: { baseUrl: 'https://example.localhost/fewswebservices' },
refresh: { policies: ['onInterval'], intervalMs: 30_000 },
}
const { legendGraphic, loading, error } = useWmsLegend(options)