Skip to content

Commit

Permalink
refacto: URLBuilder as pure functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Desplandis committed Oct 3, 2024
1 parent 0d6b611 commit 8ba1376
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 15 deletions.
35 changes: 22 additions & 13 deletions src/Provider/URLBuilder.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import Extent from 'Core/Geographic/Extent';

const extent = new Extent('EPSG:4326', [0, 0, 0, 0]);

let subDomainsCount = 0;

/**
* @param {string} url
* @returns {string}
*/
function subDomains(url) {
const subDomainsPtrn = /\$\{u:([\w-_.|]+)\}/.exec(url);

Expand Down Expand Up @@ -57,8 +58,13 @@ export default {
* // The resulting url is:
* // http://server.geo/tms/15/2142/3412.jpg;
*
* @param {Extent} coords - the coordinates
* @param {Source} source
* @param {Object} coords - tile coordinates
* @param {number} coords.row - tile row
* @param {number} coords.col - tile column
* @param {number} coords.zoom - tile zoom
* @param {Object} source
* @param {string} source.url
* @param {Function} source.tileMatrixCallback
*
* @return {string} the formed url
*/
Expand Down Expand Up @@ -88,8 +94,12 @@ export default {
* // The resulting url is:
* // http://server.geo/wms/BBOX=12,35,14,46&FORMAT=jpg&SERVICE=WMS
*
* @param {Extent} bbox - the bounding box
* @param {Object} source
* @param {Object} bbox - the bounding box
* @param {number} bbox.west
* @param {number} bbox.south
* @param {number} bbox.east
* @param {number} bbox.north
* @param {Object} source - the source of data
* @param {string} source.crs
* @param {number} source.bboxDigits
* @param {string} source.url
Expand All @@ -102,11 +112,10 @@ export default {
if (source.bboxDigits !== undefined) {
precision = source.bboxDigits;
}
bbox.as(source.crs, extent);
const w = extent.west.toFixed(precision);
const s = extent.south.toFixed(precision);
const e = extent.east.toFixed(precision);
const n = extent.north.toFixed(precision);
const w = bbox.west.toFixed(precision);
const s = bbox.south.toFixed(precision);
const e = bbox.east.toFixed(precision);
const n = bbox.north.toFixed(precision);

let bboxInUnit = source.axisOrder || 'wsen';
bboxInUnit = bboxInUnit.replace('w', `${w},`)
Expand Down
6 changes: 5 additions & 1 deletion src/Source/WFSSource.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import Source from 'Source/Source';
import URLBuilder from 'Provider/URLBuilder';
import CRS from 'Core/Geographic/Crs';
import Extent from 'Core/Geographic/Extent';

const _extent = new Extent('EPSG:4326', [0, 0, 0, 0]);

/**
* An object defining the source of resources to get from a
Expand Down Expand Up @@ -167,7 +170,8 @@ class WFSSource extends Source {
}

urlFromExtent(extent) {
return URLBuilder.bbox(extent, this);
extent.as(this.crs, _extent);
return URLBuilder.bbox(_extent, this);
}

extentInsideLimit(extent) {
Expand Down
6 changes: 5 additions & 1 deletion src/Source/WMSSource.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import Source from 'Source/Source';
import URLBuilder from 'Provider/URLBuilder';
import Extent from 'Core/Geographic/Extent';

const _extent = new Extent('EPSG:4326', [0, 0, 0, 0]);

/**
* An object defining the source of images to get from a
Expand Down Expand Up @@ -136,7 +139,8 @@ class WMSSource extends Source {
}

urlFromExtent(extent) {
return URLBuilder.bbox(extent, this);
extent.as(this.crs, _extent);
return URLBuilder.bbox(_extent, this);
}

extentInsideLimit(extent) {
Expand Down

0 comments on commit 8ba1376

Please sign in to comment.