From df1d47c7558e3617f2c11a85ab654573992fce4f Mon Sep 17 00:00:00 2001 From: guss84 Date: Tue, 16 Apr 2024 10:31:14 +0200 Subject: [PATCH] handle null values for toTime with wms getMap --- src/layer/wms.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/layer/wms.ts b/src/layer/wms.ts index b9d7236f..8c8fc9a2 100644 --- a/src/layer/wms.ts +++ b/src/layer/wms.ts @@ -96,13 +96,17 @@ export function wmsWmtMsGetMapUrl( queryParams.bbox = `${bbox.minX},${bbox.minY},${bbox.maxX},${bbox.maxY}`; queryParams.srs = bbox.crs.authId; - if (!params.fromTime) { - queryParams.time = moment.utc(params.toTime).format('YYYY-MM-DD'); - } else { + // time is an optional param, and sentinelhub will atleast return the latest image if time=none https://docs.sentinel-hub.com/api/latest/api/ogc/wms/ + // set time range with fromTime and toTime + if (params.fromTime !== null && params.toTime !== null) { queryParams.time = `${moment.utc(params.fromTime).format('YYYY-MM-DDTHH:mm:ss') + 'Z'}/${moment .utc(params.toTime) .format('YYYY-MM-DDTHH:mm:ss') + 'Z'}`; } + // only toTime available + if (params.fromTime === null && params.toTime !== null) { + queryParams.time = moment.utc(params.toTime).format('YYYY-MM-DD'); + } if (params.width && params.height) { queryParams.width = Math.round(params.width);