Skip to content

Commit

Permalink
Prevent unnecessary legend request if layer is undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
amarkensteijn committed Oct 5, 2023
1 parent d4f6198 commit 34a9503
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/services/useWms/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@ export interface UseWmsReturn {

export function useWmsLayer(
baseUrl: string,
layerName: MaybeRefOrGetter,
layerName: MaybeRefOrGetter<string>,
): UseWmsReturn {
const legendGraphic = ref<GetLegendGraphicResponse>()
let wmsUrl = `${baseUrl.toString()}/wms`
const wmsProvider = new WMSProvider(wmsUrl)
const times = ref<Date[]>()

async function loadTimes(): Promise<void> {
const _layers = toValue(layerName)
try {
let layers = toValue(layerName)
const capabilities = await wmsProvider.getCapabilities({
layers: layers,
layers: _layers,
importFromExternalDataSource: false,
onlyHeaders: false,
forecastCount: 1,
Expand All @@ -40,7 +40,7 @@ export function useWmsLayer(
if (capabilities.layers.length > 0) {
selectedLayer = capabilities.layers[0]
capabilities.layers.forEach((l) => {
if (l.name === layers) {
if (l.name === _layers) {
selectedLayer = l
}
})
Expand Down Expand Up @@ -78,9 +78,11 @@ export function useWmsLayer(
}

async function loadCapabilities(): Promise<void> {
const _layers = toValue(layerName)
if (_layers === '') return
try {
legendGraphic.value = await wmsProvider.getLegendGraphic({
layers: toValue(layerName),
layers: _layers,
})
} catch (error) {
console.log(error)
Expand Down

0 comments on commit 34a9503

Please sign in to comment.