Skip to content

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

UsePiLocationsOptions

MemberTypeDescription
enabled?Ref<boolean, boolean>Controls whether locations may be fetched automatically. When false, refresh-coordinator triggers are ignored.
filterRef<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?PiWebserviceOptionsOptional 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 ​

UsePiLocationsReturn

MemberTypeDescription
cancel() => voidCancels the currently running locations request, if any.
errorReadonly<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. * *
geojsonReadonly<Ref<FeatureCollection<Geometry, PiLocation>>>The currently loaded locations as geojson.
hasAttemptedReadonly<Ref<boolean>>Whether a request has completed for the current filter, successfully or not.
hasLoadedReadonly<Ref<boolean>>Whether a successful result is available for the current filter.
isEmptyComputedRef<boolean>Whether locations have been loaded successfully and the result is empty.
lastRefreshAtReadonly<Ref<Date | undefined>>The time at which the most recent refresh completed successfully.
lastTriggerPolicyReadonly<Ref<RefreshPolicy | undefined>>The policy that caused the most recent refresh.
loadingReadonly<Ref<boolean>>Whether a request is in progress without a successful result for the current filter.
locationsReadonly<Ref<PiLocation[]>>The currently loaded locations.
pauseRefresh() => voidPauses automatic refreshes.
refreshingReadonly<Ref<boolean>>Whether a request is in progress with a successful result for the current filter.
requestRefresh() => voidRequests a refresh through the refresh coordinator.
resumeRefresh() => voidResumes 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,
  },
})