-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #48 from camptocamp/wxs-add-mandatory-version
Add utility in WMS endpoint to build a GetMap url
- Loading branch information
Showing
9 changed files
with
180 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { generateGetMapUrl } from './url.js'; | ||
|
||
describe('generateGetMapUrl', () => { | ||
it('generates a correct URL (v1.1.0, no styles)', () => { | ||
expect( | ||
generateGetMapUrl( | ||
'http://example.com/wms', | ||
'1.1.0', | ||
'layer1,layer2', | ||
100, | ||
200, | ||
'EPSG:4326', | ||
[10, 20, 100, 200], | ||
'image/png' | ||
) | ||
).toBe( | ||
'http://example.com/wms?SERVICE=WMS&REQUEST=GetMap&VERSION=1.1.0&LAYERS=layer1%2Clayer2&STYLES=&WIDTH=100&HEIGHT=200&FORMAT=image%2Fpng&SRS=EPSG%3A4326&BBOX=10%2C20%2C100%2C200' | ||
); | ||
}); | ||
it('generates a correct URL (v1.3.0, with styles)', () => { | ||
expect( | ||
generateGetMapUrl( | ||
'http://example.com/wms', | ||
'1.3.0', | ||
'layer1,layer2', | ||
100, | ||
200, | ||
'EPSG:4326', | ||
[10, 20, 100, 200], | ||
'image/png', | ||
'style1,style2' | ||
) | ||
).toBe( | ||
'http://example.com/wms?SERVICE=WMS&REQUEST=GetMap&VERSION=1.3.0&LAYERS=layer1%2Clayer2&STYLES=style1%2Cstyle2&WIDTH=100&HEIGHT=200&FORMAT=image%2Fpng&CRS=EPSG%3A4326&BBOX=10%2C20%2C100%2C200' | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { setQueryParams } from '../shared/http-utils.js'; | ||
import { BoundingBox, CrsCode, MimeType } from '../shared/models.js'; | ||
import { WmsVersion } from './model.js'; | ||
|
||
/** | ||
* Generates an URL for a GetMap operation | ||
* @param serviceUrl | ||
* @param version | ||
* @param layers Comma-separated list of layers to render | ||
* @param widthPx | ||
* @param heightPx | ||
* @param crs Coordinate reference system to use for the image | ||
* @param extent Expressed in the requested CRS | ||
* @param outputFormat | ||
* @param [styles] Comma-separated list of styles to use; leave out for default style | ||
*/ | ||
export function generateGetMapUrl( | ||
serviceUrl: string, | ||
version: WmsVersion, | ||
layers: string, | ||
widthPx: number, | ||
heightPx: number, | ||
crs: CrsCode, | ||
extent: BoundingBox, | ||
outputFormat: MimeType, | ||
styles?: string | ||
): string { | ||
const crsParam = version === '1.3.0' ? 'CRS' : 'SRS'; | ||
|
||
const newParams = { | ||
SERVICE: 'WMS', | ||
REQUEST: 'GetMap', | ||
VERSION: version, | ||
LAYERS: layers, | ||
STYLES: styles ?? '', | ||
}; | ||
newParams['WIDTH'] = widthPx.toString(); | ||
newParams['HEIGHT'] = heightPx.toString(); | ||
newParams['FORMAT'] = outputFormat ?? 'image/png'; | ||
newParams[crsParam] = crs; | ||
newParams['BBOX'] = extent.join(','); | ||
|
||
return setQueryParams(serviceUrl, newParams); | ||
} |