Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 09a037d

Browse files
ketourneauDesplandis
authored andcommitted
feature: Add bboxUrlPrecision parameter
1 parent 5a6c7e3 commit 09a037d

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

src/Provider/URLBuilder.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ export default {
9494
* @return {string} the formed url
9595
*/
9696
bbox: function bbox(bbox, source) {
97-
const precision = source.crs == 'EPSG:4326' ? 9 : 2;
97+
const precision = ((source.bboxUrlPrecision === undefined) && (source.crs == 'EPSG:4326')) ? 9 : source.bboxUrlPrecision;
9898
bbox.as(source.crs, extent);
9999
const w = extent.west.toFixed(precision);
100100
const s = extent.south.toFixed(precision);

src/Source/Source.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ let uid = 0;
104104
* @property {string} crs - The crs projection of the resources.
105105
* @property {string} attribution - The intellectual property rights for the
106106
* resources.
107+
* @property {string} bboxUrlPrecision - The bbox decimal precision used in URL
107108
* @property {Extent} extent - The extent of the resources.
108109
* @property {function} parser - The method used to parse the resources attached
109110
* to the layer. iTowns provides some parsers, visible in the `Parser/` folder.
@@ -145,6 +146,7 @@ class Source extends InformationsData {
145146
this.isVectorSource = (source.parser || supportedParsers.get(source.format)) != undefined;
146147
this.networkOptions = source.networkOptions || { crossOrigin: 'anonymous' };
147148
this.attribution = source.attribution;
149+
this.bboxUrlPrecision = source.bboxUrlPrecision === undefined ? 2 : source.bboxUrlPrecision;
148150
this.whenReady = Promise.resolve();
149151
this._featuresCaches = {};
150152
if (source.extent && !(source.extent.isExtent)) {

test/unit/provider_url.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,16 @@ describe('URL creations', function () {
2929
assert.equal(result, 'http://server.geo/wms/BBOX=12.000000000,14.000000000,35.000000000,46.000000000&FORMAT=jpg&SERVICE=WMS');
3030
});
3131

32+
it('should correctly replace %bbox by 12.1235,14.9876,35.4589,46.9877', function () {
33+
const extent = new Extent('EPSG:4326', 12.123466, 14.98764, 35.45898, 46.987674);
34+
layer.crs = 'EPSG:4326';
35+
layer.axisOrder = 'wesn';
36+
layer.url = 'http://server.geo/wms/BBOX=%bbox&FORMAT=jpg&SERVICE=WMS';
37+
layer.bboxUrlPrecision = 4;
38+
const result = URLBuilder.bbox(extent, layer);
39+
assert.equal(result, 'http://server.geo/wms/BBOX=12.1235,14.9876,35.4590,46.9877&FORMAT=jpg&SERVICE=WMS');
40+
});
41+
3242
it('shouldn\'t use the scientific notation', function () {
3343
const extent = new Extent('EPSG:4326', 1 / 9999999999, 14, 35, 46);
3444
layer.crs = 'EPSG:4326';

0 commit comments

Comments
 (0)