Skip to content

Commit

Permalink
Apply code review
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin ETOURNEAU committed Dec 22, 2023
1 parent aa91f0f commit 532985b
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 5 deletions.
11 changes: 9 additions & 2 deletions src/Provider/URLBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,19 @@ export default {
* // http://server.geo/wms/BBOX=12,35,14,46&FORMAT=jpg&SERVICE=WMS
*
* @param {Extent} bbox - the bounding box
* @param {Source} source
* @param {Object} source
* @param {string} source.crs
* @param {number} source.bboxDigits
* @param {string} source.url
* @param {string} source.axisOrder
*
* @return {string} the formed url
*/
bbox: function bbox(bbox, source) {
const precision = ((source.bboxUrlPrecision === undefined) && (source.crs == 'EPSG:4326')) ? 9 : source.bboxUrlPrecision;
let precision = source.crs == 'EPSG:4326' ? 9 : 2;
if (source.bboxDigits !== undefined) {
precision = source.bboxDigits;
}
bbox.as(source.crs, extent);
const w = extent.west.toFixed(precision);
const s = extent.south.toFixed(precision);
Expand Down
2 changes: 0 additions & 2 deletions src/Source/Source.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ 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 @@ -146,7 +145,6 @@ 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
2 changes: 2 additions & 0 deletions src/Source/WFSSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import CRS from 'Core/Geographic/Crs';
* is 0.
* @property {number} zoom.max - The maximum level of the source. Default value
* is 21.
* @property {string} bboxDigits - The bbox digits precision used in URL
* @property {Object} vendorSpecific - An object containing vendor specific
* parameters. See for example a [list of these parameters for GeoServer]{@link
* https://docs.geoserver.org/latest/en/user/services/wfs/vendor.html}. This
Expand Down Expand Up @@ -123,6 +124,7 @@ class WFSSource extends Source {
this.isWFSSource = true;
this.typeName = source.typeName;
this.version = source.version || '2.0.2';
this.bboxDigits = source.bboxDigits;

// Add ? at the end of the url if it is not already in the given URL
if (!this.url.endsWith('?')) {
Expand Down
2 changes: 2 additions & 0 deletions src/Source/WMSSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import URLBuilder from 'Provider/URLBuilder';
* is 0.
* @property {number} zoom.max - The maximum level of the source. Default value
* is 21.
* @property {string} bboxDigits - The bbox digits precision used in URL
* @property {Object} vendorSpecific - An object containing vendor specific
* parameters. See for example a [list of these parameters for GeoServer]{@link
* https://docs.geoserver.org/latest/en/user/services/wms/vendor.html}. This
Expand Down Expand Up @@ -99,6 +100,7 @@ class WMSSource extends Source {
this.height = source.height || source.width || 256;
this.version = source.version || '1.3.0';
this.transparent = source.transparent || false;
this.bboxDigits = source.bboxDigits;

if (!source.axisOrder) {
// 4326 (lat/long) axis order depends on the WMS version used
Expand Down
2 changes: 1 addition & 1 deletion test/unit/provider_url.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe('URL creations', function () {
layer.crs = 'EPSG:4326';
layer.axisOrder = 'wesn';
layer.url = 'http://server.geo/wms/BBOX=%bbox&FORMAT=jpg&SERVICE=WMS';
layer.bboxUrlPrecision = 4;
layer.bboxDigits = 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');
});
Expand Down

0 comments on commit 532985b

Please sign in to comment.