Skip to content

Commit

Permalink
handle null fromTime and toTime in wms request
Browse files Browse the repository at this point in the history
  • Loading branch information
guss84 committed Apr 17, 2024
1 parent 10ee53a commit 1e68f27
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/layer/wms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,17 @@ function getQueryParams(
queryParams.format = params.format as MimeType;
}

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. Requesting a single value for TIME parameter is deprecated
if (params.fromTime === null && params.toTime !== null) {
queryParams.time = moment.utc(params.toTime).format('YYYY-MM-DD');

Check failure on line 169 in src/layer/wms.ts

View workflow job for this annotation

GitHub Actions / test (8.x)

Delete `·`

Check failure on line 169 in src/layer/wms.ts

View workflow job for this annotation

GitHub Actions / test (10.x)

Delete `·`

Check failure on line 169 in src/layer/wms.ts

View workflow job for this annotation

GitHub Actions / test (12.x)

Delete `·`

Check failure on line 169 in src/layer/wms.ts

View workflow job for this annotation

GitHub Actions / test (8.x)

Delete `·`

Check failure on line 169 in src/layer/wms.ts

View workflow job for this annotation

GitHub Actions / test (10.x)

Delete `·`

Check failure on line 169 in src/layer/wms.ts

View workflow job for this annotation

GitHub Actions / test (12.x)

Delete `·`
}

if (params.width && params.height) {
queryParams.width = params.width;
Expand Down

0 comments on commit 1e68f27

Please sign in to comment.