Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert GetImageParameters to WMSGetMapParameters #2799

Merged
merged 2 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
});