@deltares/fews-web-oc-composables
@deltares/fews-web-oc-composables / usePiLocations
Function: usePiLocations()
usePiLocations(
options):UsePiLocationsReturn
Defined in: usePiLocations/index.ts:221
Beta
Fetches FEWS PI locations matching a reactive filter, and keeps them up to date automatically via a useRefreshCoordinator.
Parameters
options
| Member | Type | Description |
|---|---|---|
enabled? | Ref<boolean, boolean> | Controls whether locations may be fetched automatically. When false, refresh-coordinator triggers are ignored. |
filter | Ref<LocationsFilter | undefined> | Reactive filter used when fetching locations. When undefined, no request is made and the result is empty. The current value is read when fetch() is executed. Meaningful parameter changes clear the current result and fetch locations for the new filter automatically. Equivalent replacements are ignored. |
refresh? | { immediate?: boolean; intervalMs?: number; policies?: RefreshPolicy[]; systemTick?: Ref<Date | undefined, Date | undefined> } | Configuration for automatic location refreshing. |
webservice? | PiWebserviceOptions | Optional webservice configuration for standalone usage. When omitted, the host-provided webservice context is used. |
Configuration for the locations request and automatic refreshing. See UsePiLocationsOptions.
Returns
| Member | Type | Description |
|---|---|---|
cancel | () => void | Cancels the currently running locations request, if any. |
error | Readonly<Ref<Error | null>> | The error from the most recent locations request, or null when there is no error. |
fetch | () => Promise<void> | Fetches locations immediately using the current filter. * Identical pending requests within this instance share the same promise. * * |
geojson | Readonly<Ref<FeatureCollection<Geometry, PiLocation>>> | The currently loaded locations as geojson. |
hasAttempted | Readonly<Ref<boolean>> | Whether a request has completed for the current filter, successfully or not. |
hasLoaded | Readonly<Ref<boolean>> | Whether a successful result is available for the current filter. |
isEmpty | ComputedRef<boolean> | Whether locations have been loaded successfully and the result is empty. |
lastRefreshAt | Readonly<Ref<Date | undefined>> | The time at which the most recent refresh completed successfully. |
lastTriggerPolicy | Readonly<Ref<RefreshPolicy | undefined>> | The policy that caused the most recent refresh. |
loading | Readonly<Ref<boolean>> | Whether a request is in progress without a successful result for the current filter. |
locations | Readonly<Ref<PiLocation[]>> | The currently loaded locations. |
pauseRefresh | () => void | Pauses automatic refreshes. |
refreshing | Readonly<Ref<boolean>> | Whether a request is in progress with a successful result for the current filter. |
requestRefresh | () => void | Requests a refresh through the refresh coordinator. |
resumeRefresh | () => void | Resumes automatic refreshes after they have been paused. |
Reactive locations/geojson data, loading/error state, and controls for fetching and refreshing. See UsePiLocationsReturn.
Examples
ts
import { ref } from 'vue'
import { usePiLocations } from '@deltares/fews-web-oc-composables'
const filter = ref({ filterId: 'example-filter' })
const { locations, loading, error, isEmpty } = usePiLocations({ filter })ts
// Standalone usage, with custom refresh configuration
const { locations, requestRefresh } = usePiLocations({
filter,
webservice: { baseUrl: 'https://example.localhost/fewswebservices' },
refresh: {
policies: ['onInterval'],
intervalMs: 30_000,
immediate: true,
},
})