Skip to content

Commit 92b37ee

Browse files
committedFeb 19, 2021
fix date going up one day && SHOWLOGO options
1 parent 51dbf69 commit 92b37ee

File tree

5 files changed

+23
-18
lines changed

5 files changed

+23
-18
lines changed
 

‎package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@ciag/sentinel-hub",
33
"private": false,
4-
"version": "0.0.1-beta.23",
4+
"version": "0.0.3",
55
"description": "a API to create the sentinel ogs requests, and tools to apply on the data",
66
"main": "dist/index.js",
77
"scripts": {

‎src/WFS/index.ts

+9-8
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { TYPENAMES } from './GetFeatures/TYPENAMES';
44
import { GetFeaturesRequest } from './GetFeatures/GetFeaturesRequest';
55
import { GetFeaturesRequestOptions, RawGetFeatureRequestOptions } from './GetFeatures/GetFeaturesRequestOptions';
66
import { defer, from, Observable } from 'rxjs';
7-
import { _SafeFetch,_ArgumentTypes } from '..';
7+
import { _SafeFetch, _ArgumentTypes } from '..';
88
import { GetFeatureReturn } from './GetFeatures/GetFeatureReturn';
99

1010
export namespace SentinelHubWfs {
@@ -97,13 +97,14 @@ export namespace SentinelHubWfs {
9797
* @description Used to fetch avaliable dates for sattelite data
9898
*
9999
* it can be created with a proxy URL
100-
* @param {GetFeaturesRequestOptions} options for each option effect and more details: https://www.sentinel-hub.com/develop/api/ogc/standard-parameters/wfs/
100+
* @param {GetFeaturesRequestOptions} dateOptions for each option effect and more details: https://www.sentinel-hub.com/develop/api/ogc/standard-parameters/wfs/
101101
*/
102-
export async function getAvaliableDates(polygonList: FeatureCollection<Polygon> | Feature<Polygon>, uuid: string, options: { from: Date, to: Date, proxy?: RequestInfo, requestOption?: RequestInit }): Promise<Date[]> {
103-
const requestOptions = Object.assign({}, defaultGetDateOptions)
104-
requestOptions.DATE_START = options.from
105-
requestOptions.DATE_END = options.to
106-
const dates: GetFeatureReturn = await GetFeature(polygonList, uuid, requestOptions, options.proxy, options.requestOption).then(r => r.json())
102+
export async function getAvaliableDates(polygonList: FeatureCollection<Polygon> | Feature<Polygon>, uuid: string, dateOptions: { from: Date, to: Date, proxy?: RequestInfo, requestOption?: RequestInit }, options: GetFeaturesRequestOptions = defaultGetDateOptions): Promise<Date[]> {
103+
let requestOptions = {...defaultGetDateOptions,...options}
104+
105+
requestOptions.DATE_START = dateOptions.from
106+
requestOptions.DATE_END = dateOptions.to
107+
const dates: GetFeatureReturn = await GetFeature(polygonList, uuid, requestOptions, dateOptions.proxy, dateOptions.requestOption).then(r => r.json())
107108
return dates.features.map(i => new Date(i.properties.date))
108109
}
109110

@@ -114,7 +115,7 @@ export namespace SentinelHubWfs {
114115
* it can be created with a proxy URL
115116
* @param {GetFeaturesRequestOptions} options for each option effect and more details: https://www.sentinel-hub.com/develop/api/ogc/standard-parameters/wfs/
116117
*/
117-
export const getAvaliableDatesAsync = (...args:_ArgumentTypes< typeof getAvaliableDates>)=>defer(() => from(getAvaliableDates(...args)))
118+
export const getAvaliableDatesAsync = (...args: _ArgumentTypes<typeof getAvaliableDates>) => defer(() => from(getAvaliableDates(...args)))
118119

119120

120121
}

‎src/WMS/GetMap/GetMap.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export class GetMap {
5353

5454
public proxyOptions: RequestInit = {}
5555

56-
constructor(UUID: string, params: { DATE: Date, BBOX: BBox, CRS?: string, SRS?: string, FORMAT: GetMapParameters.Format, WIDTH?: number, HEIGHT?: number, RESX?: string, RESY?: string, BGCOLOR?: GetMapParameters.BgColor, TRANSPARENT?: boolean, LAYERS?: GetMapParameters.Sentinel_2[], EXCEPTIONS?: GetMapParameters.Exceptions,SHOWLOGO?:Boolean }) {
56+
constructor(UUID: string, params: { DATE: Date, BBOX: BBox, CRS?: string, SRS?: string, FORMAT: GetMapParameters.Format, WIDTH?: number, HEIGHT?: number, RESX?: string, RESY?: string, BGCOLOR?: GetMapParameters.BgColor, TRANSPARENT?: boolean, LAYERS?: GetMapParameters.Sentinel_2[], EXCEPTIONS?: GetMapParameters.Exceptions, SHOWLOGO?: boolean }) {
5757
this.DATE = params.DATE ? params.DATE : this.DATE;
5858
this.UUID = UUID;
5959
this.BBOX = new BoxCords(params.BBOX);
@@ -79,6 +79,7 @@ export class GetMap {
7979
this.TRANSPARENT = params.TRANSPARENT ? params.TRANSPARENT : this.TRANSPARENT;
8080
this.LAYERS = params.LAYERS ? params.LAYERS : this.LAYERS;
8181
this.EXCEPTIONS = params.EXCEPTIONS;
82+
this.SHOWLOGO = params.SHOWLOGO || false
8283
}
8384
public async request() {
8485
try {
@@ -115,7 +116,7 @@ export class GetMap {
115116
if (this.TRANSPARENT) { link.addParameter("TRANSPARENT", this.TRANSPARENT); }
116117
if (this.LAYERS) { link.addParameter("LAYERS", this.LAYERS); }
117118
if (this.EXCEPTIONS) { link.addParameter("EXCEPTIONS", this.EXCEPTIONS); }
118-
if (this.SHOWLOGO) { link.addParameter("SHOWLOGO", this.SHOWLOGO); }
119+
if (this.SHOWLOGO !== undefined) { link.addParameter("SHOWLOGO", this.SHOWLOGO); }
119120
link.setTimeFrom(this.DATE);
120121
if (this.proxy) { return link.getProxy() }
121122
else { return link.getLink() };

‎src/WMS/GetMap/SentinelHubURL.ts

+9-6
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
export enum SentinelWMSRequests{
2-
GET_MAP="REQUEST=GetMap",
3-
GET_FEATURE_INFO="REQUEST=GetFeatureInfo"
1+
export enum SentinelWMSRequests {
2+
GET_MAP = "REQUEST=GetMap",
3+
GET_FEATURE_INFO = "REQUEST=GetFeatureInfo"
44
}
55
export class SentinelHubURL {
66
public parameters = [];
77
public link: string;
88
public UUID: string;
99
public timeFrom = null;
1010
public timeTo = null;
11-
constructor(public preset:RequestInfo = "https://services.sentinel-hub.com/ogc/wms/",public request:SentinelWMSRequests|string = SentinelWMSRequests.GET_MAP) {
11+
constructor(public preset: RequestInfo = "https://services.sentinel-hub.com/ogc/wms/", public request: SentinelWMSRequests | string = SentinelWMSRequests.GET_MAP) {
1212
}
1313
public addUUID(uuid: string) { this.UUID = uuid; }
1414
public addParameter(name: string, value: any) {
1515
this.parameters.push(name + "=" + value);
1616
}
1717
public setTimeFrom(date: Date) {
18-
this.timeFrom = "TIME=" + date.toISOString().split("T")[0];
18+
this.timeFrom = "TIME=" + this.formatSentinelUrlDate(date);
1919
}
2020
public setTimeTo(date: Date) {
21-
this.timeTo = "/" + date.toISOString().split("T")[0] + "/P1D";
21+
this.timeTo = "/" + this.formatSentinelUrlDate(date);
2222
}
2323
public clearTime() {
2424
this.timeFrom = null;
@@ -36,4 +36,7 @@ export class SentinelHubURL {
3636
return this.timeFrom ? (this.timeFrom + (this.timeTo ? this.timeTo : "")
3737
+ "&") : "";
3838
}
39+
private formatSentinelUrlDate(date: Date) {
40+
return `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}`
41+
}
3942
}

0 commit comments

Comments
 (0)
Please sign in to comment.