Skip to content

Commit

Permalink
Merge pull request #21 from camptocamp/handle-wgs84-bbox
Browse files Browse the repository at this point in the history
Handle more BoundingBox elements in WMS capabilities
  • Loading branch information
jahow authored Jan 5, 2024
2 parents 4e07d22 + 4e99bf5 commit 32ee5ef
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 18 deletions.
6 changes: 4 additions & 2 deletions fixtures/wms/capabilities-brgm-1-1-1.xml
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,6 @@
<SRS>EPSG:32620</SRS>
<SRS>EPSG:32621</SRS>
<LatLonBoundingBox minx="-5.86764" miny="41.1701" maxx="11.0789" maxy="51.1419" />
<BoundingBox SRS="EPSG:4326"
minx="-5.86764" miny="41.1701" maxx="11.0789" maxy="51.1419" />
<BoundingBox SRS="EPSG:3857"
minx="-653183" miny="5.03746e+06" maxx="1.2333e+06" maxy="6.64644e+06" />
<BoundingBox SRS="CRS:84"
Expand Down Expand Up @@ -306,6 +304,10 @@
</MetadataURL>
<ScaleHint min="3.36759422690005" max="93.9184612168792" />
</Layer>
<Layer queryable="0" opaque="0" cascaded="0">
<Name>INHERIT_BBOX</Name>
<Title>Inherited bounding boxes</Title>
</Layer>
</Layer>
</Layer>
</Capability>
Expand Down
6 changes: 4 additions & 2 deletions fixtures/wms/capabilities-brgm-1-3-0.xml
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,6 @@
<southBoundLatitude>41.1701</southBoundLatitude>
<northBoundLatitude>51.1419</northBoundLatitude>
</EX_GeographicBoundingBox>
<BoundingBox CRS="EPSG:4326"
minx="41.1701" miny="-5.86764" maxx="51.1419" maxy="11.0789" />
<BoundingBox CRS="EPSG:3857"
minx="-653183" miny="5.03746e+06" maxx="1.2333e+06" maxy="6.64644e+06" />
<BoundingBox CRS="CRS:84"
Expand Down Expand Up @@ -332,6 +330,10 @@
<MinScaleDenominator>9000</MinScaleDenominator>
<MaxScaleDenominator>251000</MaxScaleDenominator>
</Layer>
<Layer queryable="0" opaque="0" cascaded="0">
<Name>INHERIT_BBOX</Name>
<Title>Inherited bounding boxes</Title>
</Layer>
</Layer>
</Layer>
</Capability>
Expand Down
38 changes: 37 additions & 1 deletion src/wms/capabilities.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,13 @@ describe('WMS capabilities', () => {
abstract: 'Cartes géologiques',
attribution,
availableCrs,
boundingBoxes: {},
boundingBoxes: {
'CRS:84': ['-180', '-90', '180', '90'],
'EPSG:2154': ['-1e+15', '-1e+15', '1e+15', '1e+15'],
'EPSG:3857': ['-1e+15', '-1e+15', '1e+15', '1e+15'],
'EPSG:4171': ['-180', '-90', '180', '90'],
'EPSG:4326': ['-180', '-90', '180', '90'],
},
name: 'GEOLOGIE',
styles,
title: 'Cartes géologiques',
Expand Down Expand Up @@ -202,6 +208,36 @@ describe('WMS capabilities', () => {
styles,
title: 'Carte géologique image de la France au 1/50 000e',
},
{
abstract: '',
attribution: {
logoUrl: 'http://mapsref.brgm.fr/legendes/brgm_logo.png',
title: 'Brgm',
url: 'http://www.brgm.fr/',
},
availableCrs: [
'EPSG:4326',
'CRS:84',
'EPSG:3857',
'EPSG:4171',
'EPSG:2154',
],
boundingBoxes: {
'CRS:84': ['-180', '-90', '180', '90'],
'EPSG:2154': ['-1e+15', '-1e+15', '1e+15', '1e+15'],
'EPSG:3857': ['-1e+15', '-1e+15', '1e+15', '1e+15'],
'EPSG:4171': ['-180', '-90', '180', '90'],
'EPSG:4326': ['-180', '-90', '180', '90'],
},
name: 'INHERIT_BBOX',
styles: [
{
name: 'default',
title: 'default',
},
],
title: 'Inherited bounding boxes',
},
],
},
],
Expand Down
50 changes: 40 additions & 10 deletions src/wms/capabilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
WmsLayerFull,
WmsVersion,
} from './endpoint';
import { CrsCode, GenericEndpointInfo } from '../shared/models';
import { BoundingBox, CrsCode, GenericEndpointInfo } from '../shared/models';

/**
* Will read a WMS version from the capabilities doc
Expand Down Expand Up @@ -74,7 +74,8 @@ function parseLayer(
version: WmsVersion,
inheritedSrs: CrsCode[] = [],
inheritedStyles: LayerStyle[] = [],
inheritedAttribution: LayerAttribution = null
inheritedAttribution: LayerAttribution = null,
inheritedBoundingBoxes: Record<CrsCode, BoundingBox> = null
): WmsLayerFull {
const srsTag = version === '1.3.0' ? 'CRS' : 'SRS';
const srsList = findChildrenElement(layerEl, srsTag).map(getElementText);
Expand All @@ -91,13 +92,48 @@ function parseLayer(
: ['minx', 'miny', 'maxx', 'maxy'];
return attrs.map((name) => getElementAttribute(bboxEl, name));
}
function parseExGeographicBoundingBox(bboxEl) {
return [
'westBoundLongitude',
'southBoundLatitude',
'eastBoundLongitude',
'northBoundLatitude',
].map((name) => getElementText(findChildElement(bboxEl, name)));
}
function parseLatLonBoundingBox(bboxEl) {
return ['minx', 'miny', 'maxx', 'maxy'].map((name) =>
getElementAttribute(bboxEl, name)
);
}
const attributionEl = findChildElement(layerEl, 'Attribution');
const attribution =
attributionEl !== null
? parseLayerAttribution(attributionEl)
: inheritedAttribution;
const latLonBboxEl =
version === '1.3.0'
? findChildElement(layerEl, 'EX_GeographicBoundingBox')
: findChildElement(layerEl, 'LatLonBoundingBox');
const baseBoundingBox = {};
if (latLonBboxEl) {
baseBoundingBox['EPSG:4326'] =
version === '1.3.0'
? parseExGeographicBoundingBox(latLonBboxEl)
: parseLatLonBoundingBox(latLonBboxEl);
}
let boundingBoxes = findChildrenElement(layerEl, 'BoundingBox').reduce(
(prev, bboxEl) => ({
...prev,
[getElementAttribute(bboxEl, srsTag)]: parseBBox(bboxEl),
}),
baseBoundingBox
);
boundingBoxes =
Object.keys(boundingBoxes).length > 0 || inheritedBoundingBoxes === null
? boundingBoxes
: inheritedBoundingBoxes;
const children = findChildrenElement(layerEl, 'Layer').map((layer) =>
parseLayer(layer, version, availableCrs, styles, attribution)
parseLayer(layer, version, availableCrs, styles, attribution, boundingBoxes)
);
return {
name: getElementText(findChildElement(layerEl, 'Name')),
Expand All @@ -106,13 +142,7 @@ function parseLayer(
availableCrs,
styles,
attribution,
boundingBoxes: findChildrenElement(layerEl, 'BoundingBox').reduce(
(prev, bboxEl) => ({
...prev,
[getElementAttribute(bboxEl, srsTag)]: parseBBox(bboxEl),
}),
{}
),
boundingBoxes,
...(children.length && { children }),
};
}
Expand Down
13 changes: 12 additions & 1 deletion src/wms/endpoint.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ describe('WmsEndpoint', () => {
name: 'SCAN_D_GEOL50',
title: 'Carte géologique image de la France au 1/50 000e',
},
{
abstract: '',
name: 'INHERIT_BBOX',
title: 'Inherited bounding boxes',
},
],
name: 'GEOLOGIE',
title: 'Cartes géologiques',
Expand Down Expand Up @@ -117,7 +122,13 @@ describe('WmsEndpoint', () => {
'EPSG:4171',
'EPSG:2154',
],
boundingBoxes: {},
boundingBoxes: {
'CRS:84': ['-180', '-90', '180', '90'],
'EPSG:2154': ['-1e+15', '-1e+15', '1e+15', '1e+15'],
'EPSG:3857': ['-1e+15', '-1e+15', '1e+15', '1e+15'],
'EPSG:4171': ['-180', '-90', '180', '90'],
'EPSG:4326': ['-180', '-90', '180', '90'],
},
name: 'GEOLOGIE',
styles: [
{
Expand Down
4 changes: 2 additions & 2 deletions src/wms/endpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { EndpointError } from '../shared/errors';
import { parseWmsCapabilities } from '../worker';
import { useCache } from '../shared/cache';
import { setQueryParams } from '../shared/http-utils';
import { CrsCode, GenericEndpointInfo } from '../shared/models';
import { BoundingBox, CrsCode, GenericEndpointInfo } from '../shared/models';

export type LayerStyle = {
name: string;
Expand Down Expand Up @@ -44,7 +44,7 @@ export type WmsLayerFull = {
/**
* Dict of bounding boxes where keys are CRS codes
*/
boundingBoxes: any;
boundingBoxes: Record<CrsCode, BoundingBox>;
attribution?: LayerAttribution;
/**
* Not defined if the layer is a leaf in the tree
Expand Down

0 comments on commit 32ee5ef

Please sign in to comment.