Skip to content

Commit

Permalink
Merge pull request #64 from RobQuincey-DC/feature-add-formats-to-wms
Browse files Browse the repository at this point in the history
Add formats from WMS Capabilities to `outputFormats`
  • Loading branch information
jahow authored Jul 26, 2024
2 parents 377887e + 0324648 commit c75dcba
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/shared/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ export type GenericEndpointInfo = {
fees: string;
constraints: string;
keywords: string[];
/**
* Can contain the list of outputFormats from a WFS GetCapabilities,
* or the list of 'Formats' from a WMS GetCapabilities
*/
outputFormats?: MimeType[];
};

Expand Down
10 changes: 10 additions & 0 deletions src/wms/capabilities.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,16 @@ describe('WMS capabilities', () => {
fees: 'no conditions apply',
name: 'WMS',
title: 'GéoServices : géologie, hydrogéologie et gravimétrie',
outputFormats: [
'image/png',
'image/gif',
'image/jpeg',
'image/ecw',
'image/tiff',
'image/png; mode=8bit',
'application/x-pdf',
'image/svg+xml',
],
keywords: [
'Géologie',
'BRGM',
Expand Down
19 changes: 19 additions & 0 deletions src/wms/capabilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,23 @@ export function readLayersFromCapabilities(capabilitiesDoc: XmlDocument) {
);
}

export function readOutputFormatsFromCapabilities(
capabilitiesDoc: XmlDocument
) {
const capability = findChildElement(
getRootElement(capabilitiesDoc),
'Capability'
);
const getMap = findChildElement(
findChildElement(capability, 'Request'),
'GetMap'
);
const outputFormats = findChildrenElement(getMap, 'Format').map(
getElementText
);
return outputFormats;
}

/**
* Will read service-related info from the capabilities doc
* @param capabilitiesDoc Capabilities document
Expand All @@ -49,6 +66,7 @@ export function readInfoFromCapabilities(
capabilitiesDoc: XmlDocument
): GenericEndpointInfo {
const service = findChildElement(getRootElement(capabilitiesDoc), 'Service');
const formats = readOutputFormatsFromCapabilities(capabilitiesDoc);
const keywords = findChildrenElement(
findChildElement(service, 'KeywordList'),
'Keyword'
Expand All @@ -60,6 +78,7 @@ export function readInfoFromCapabilities(
title: getElementText(findChildElement(service, 'Title')),
name: getElementText(findChildElement(service, 'Name')),
abstract: getElementText(findChildElement(service, 'Abstract')),
outputFormats: formats,
fees: getElementText(findChildElement(service, 'Fees')),
constraints: getElementText(findChildElement(service, 'AccessConstraints')),
keywords,
Expand Down
10 changes: 10 additions & 0 deletions src/wms/endpoint.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,16 @@ describe('WmsEndpoint', () => {
fees: 'no conditions apply',
name: 'WMS',
title: 'GéoServices : géologie, hydrogéologie et gravimétrie',
outputFormats: [
'image/png',
'image/gif',
'image/jpeg',
'image/ecw',
'image/tiff',
'image/png; mode=8bit',
'application/x-pdf',
'image/svg+xml',
],
keywords: [
'Géologie',
'BRGM',
Expand Down

0 comments on commit c75dcba

Please sign in to comment.