Skip to content

Commit

Permalink
Convert GetImageParameters to WMSGetMapParameters (#2799)
Browse files Browse the repository at this point in the history
  • Loading branch information
felixpalmer authored Nov 22, 2023
1 parent 323bc86 commit 207ff3f
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 12 deletions.
19 changes: 7 additions & 12 deletions modules/wms/src/services/ogc/wms-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,13 @@ export class WMSSource extends ImageSource<WMSSourceProps> {
}

async getImage(parameters: GetImageParameters): Promise<ImageType> {
// @ts-expect-error
return await this.getMap(parameters);
// Replace the GetImage `boundingBox` parameter with the WMS flat `bbox` parameter.
const {boundingBox, ...rest} = parameters;
const wmsParameters: WMSGetMapParameters = {
bbox: [...boundingBox[0], ...boundingBox[1]],
...rest
};
return await this.getMap(wmsParameters);
}

normalizeMetadata(capabilities: WMSCapabilities): ImageSourceMetadata {
Expand Down Expand Up @@ -498,16 +503,6 @@ export class WMSSource extends ImageSource<WMSSourceProps> {
}
break;

case 'boundingBox':
// Coordinate order is flipped for certain CRS in WMS 1.3.0
const boundingBox = value as [[number, number], [number, number]];
let bbox2: number[] | null = [...boundingBox[0], ...boundingBox[1]];
bbox2 = this._flipBoundingBox(boundingBox, wmsParameters);
if (bbox2) {
value = bbox2;
}
break;

case 'bbox':
// Coordinate order is flipped for certain CRS in WMS 1.3.0
const bbox = this._flipBoundingBox(value, wmsParameters);
Expand Down
32 changes: 32 additions & 0 deletions modules/wms/test/services/wms-service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,35 @@ test('WMSSource#fetch override', async (t) => {
t.end();
});
});

test('WMSSource#getImage', async (t) => {
const wmsService = new WMSSource({url: WMS_SERVICE_URL});
let getMapParameters;

// @ts-ignore
wmsService.getMap = (parameters) => {
getMapParameters = parameters;
};

await wmsService.getImage({
width: 800,
height: 600,
boundingBox: [
[30, 70],
[35, 75]
],
layers: ['oms']
});

t.deepEqual(
getMapParameters,
{
width: 800,
height: 600,
bbox: [30, 70, 35, 75],
layers: ['oms']
},
'boundingBox transformed to bbox'
);
t.end();
});

0 comments on commit 207ff3f

Please sign in to comment.