Skip to content

Commit

Permalink
Added a method to get all the tile collections
Browse files Browse the repository at this point in the history
  • Loading branch information
ronitjadhav committed Apr 18, 2024
1 parent d19471b commit c50282b
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
6 changes: 6 additions & 0 deletions src/ogc-api/endpoint.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,12 @@ describe('OgcApiEndpoint', () => {
]);
});
});
describe('#tileCollections', () => {
it('returns collection ids', async () => {
await expect(endpoint.tileCollections).resolves.toEqual([
]);
});
});
describe('#hasTiles', () => {
it('returns true', async () => {
await expect(endpoint.hasTiles).resolves.toBe(true);
Expand Down
13 changes: 11 additions & 2 deletions src/ogc-api/endpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export default class OgcApiEndpoint {
get recordCollections(): Promise<string[]> {
return Promise.all([this.data, this.hasRecords])
.then(([data, hasRecords]) => (hasRecords ? data : { collections: [] }))
.then(parseCollections('record'));
.then(parseCollections('record', null));
}

/**
Expand All @@ -106,7 +106,16 @@ export default class OgcApiEndpoint {
get featureCollections(): Promise<string[]> {
return Promise.all([this.data, this.hasFeatures])
.then(([data, hasFeatures]) => (hasFeatures ? data : { collections: [] }))
.then(parseCollections('feature'));
.then(parseCollections('feature', null));
}

/**
* A Promise which resolves to an array of tile collection identifiers as strings.
*/
get tileCollections(): Promise<string[]> {
return Promise.all([this.data, this.hasTiles])
.then(([data, hasTiles]) => (hasTiles ? data : { collections: [] }))
.then(parseCollections(null,'vector'));
}

/**
Expand Down
7 changes: 5 additions & 2 deletions src/ogc-api/info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,15 @@ export function parseConformance(doc: OgcApiDocument): ConformanceClass[] {
}

export function parseCollections(
itemType: 'record' | 'feature' | null = null
itemType: 'record' | 'feature' | null = null,
dataType: 'vector' | null = null
): (doc: OgcApiDocument) => string[] {
return (doc: OgcApiDocument) =>
(doc.collections as OgcApiCollectionInfo[])
.filter(
(collection) => itemType === null || collection.itemType === itemType
(collection) =>
(itemType === null || collection.itemType === itemType) &&
(dataType === null || collection.dataType === dataType)
)
.map((collection) => collection.id as string);
}
Expand Down
1 change: 1 addition & 0 deletions src/ogc-api/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export interface OgcApiCollectionInfo {
description: string;
id: string;
itemType: 'feature' | 'record';
dataType: 'vector';
formats: MimeType[];
crs: CrsCode[];
storageCrs?: CrsCode;
Expand Down

0 comments on commit c50282b

Please sign in to comment.