Skip to content

@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 ​

UseWmsLegendOptions

MemberTypeDescription
colorScaleRange?MaybeRefOrGetter<string>Optional "min,max" color scale range override.
enabled?Ref<boolean, boolean>Controls whether requests and automatic refreshes are enabled.
layerNameMaybeRefOrGetter<string | undefined>Name of the layer to load the legend for.
refresh?UseWmsRefreshOptionsConfiguration for automatic request refreshing.
style?MaybeRefOrGetter<Style>Optional WMS style to render the legend with.
useDisplayUnitsMaybeRefOrGetter<boolean>Whether to render the legend using display units.
webservice?PiWebserviceOptionsOptional webservice configuration for standalone usage. When omitted, the host-provided webservice context is used.

Request configuration. See UseWmsLegendOptions.

Returns ​

UseWmsLegendReturn

MemberTypeDescription
cancel() => voidCancels the currently running request, if any.
errorReadonly<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.
hasAttemptedReadonly<Ref<boolean>>Whether a request has completed for the current inputs, successfully or not.
hasLoadedReadonly<Ref<boolean>>Whether a successful response is available for the current inputs.
lastRefreshAtReadonly<Ref<Date | undefined>>Time at which the most recent refresh completed successfully.
lastTriggerPolicyReadonly<Ref<RefreshPolicy | undefined>>Policy that caused the most recent refresh.
legendGraphicReadonly<Ref<GetLegendGraphicResponse | undefined>>The loaded WMS legend graphic.
loadingReadonly<Ref<boolean>>Whether the initial request is in progress.
pauseRefresh() => voidPauses automatic refreshes.
refreshingReadonly<Ref<boolean>>Whether a subsequent request is in progress.
requestRefresh() => voidRequests a refresh through the refresh coordinator.
resumeRefresh() => voidResumes 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)