Skip to content

Commit

Permalink
feature: Add bboxUrlPrecision parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin ETOURNEAU authored and Desplandis committed Jan 10, 2024
1 parent 5a6c7e3 commit 09a037d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Provider/URLBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export default {
* @return {string} the formed url
*/
bbox: function bbox(bbox, source) {
const precision = source.crs == 'EPSG:4326' ? 9 : 2;
const precision = ((source.bboxUrlPrecision === undefined) && (source.crs == 'EPSG:4326')) ? 9 : source.bboxUrlPrecision;
bbox.as(source.crs, extent);
const w = extent.west.toFixed(precision);
const s = extent.south.toFixed(precision);
Expand Down
2 changes: 2 additions & 0 deletions src/Source/Source.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ let uid = 0;
* @property {string} crs - The crs projection of the resources.
* @property {string} attribution - The intellectual property rights for the
* resources.
* @property {string} bboxUrlPrecision - The bbox decimal precision used in URL
* @property {Extent} extent - The extent of the resources.
* @property {function} parser - The method used to parse the resources attached
* to the layer. iTowns provides some parsers, visible in the `Parser/` folder.
Expand Down Expand Up @@ -145,6 +146,7 @@ class Source extends InformationsData {
this.isVectorSource = (source.parser || supportedParsers.get(source.format)) != undefined;
this.networkOptions = source.networkOptions || { crossOrigin: 'anonymous' };
this.attribution = source.attribution;
this.bboxUrlPrecision = source.bboxUrlPrecision === undefined ? 2 : source.bboxUrlPrecision;
this.whenReady = Promise.resolve();
this._featuresCaches = {};
if (source.extent && !(source.extent.isExtent)) {
Expand Down
10 changes: 10 additions & 0 deletions test/unit/provider_url.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ describe('URL creations', function () {
assert.equal(result, 'http://server.geo/wms/BBOX=12.000000000,14.000000000,35.000000000,46.000000000&FORMAT=jpg&SERVICE=WMS');
});

it('should correctly replace %bbox by 12.1235,14.9876,35.4589,46.9877', function () {
const extent = new Extent('EPSG:4326', 12.123466, 14.98764, 35.45898, 46.987674);
layer.crs = 'EPSG:4326';
layer.axisOrder = 'wesn';
layer.url = 'http://server.geo/wms/BBOX=%bbox&FORMAT=jpg&SERVICE=WMS';
layer.bboxUrlPrecision = 4;
const result = URLBuilder.bbox(extent, layer);
assert.equal(result, 'http://server.geo/wms/BBOX=12.1235,14.9876,35.4590,46.9877&FORMAT=jpg&SERVICE=WMS');
});

it('shouldn\'t use the scientific notation', function () {
const extent = new Extent('EPSG:4326', 1 / 9999999999, 14, 35, 46);
layer.crs = 'EPSG:4326';
Expand Down

0 comments on commit 09a037d

Please sign in to comment.