diff --git a/src/Converter/textureConverter.js b/src/Converter/textureConverter.js index 5455e9d96f..7dee2c674c 100644 --- a/src/Converter/textureConverter.js +++ b/src/Converter/textureConverter.js @@ -2,7 +2,7 @@ import * as THREE from 'three'; import Feature2Texture from 'Converter/Feature2Texture'; import Extent from 'Core/Geographic/Extent'; -const extentTexture = new Extent('EPSG:4326', [0, 0, 0, 0]); +const extentTexture = new Extent('EPSG:4326'); const textureLayer = (texture, layer) => { texture.generateMipmaps = false; diff --git a/src/Core/Geographic/Extent.js b/src/Core/Geographic/Extent.js index dce3334611..3599cbc71e 100644 --- a/src/Core/Geographic/Extent.js +++ b/src/Core/Geographic/Extent.js @@ -44,7 +44,7 @@ class Extent { * @param {number} [v2] south value * @param {number} [v3] north value */ - constructor(crs, v0, v1, v2, v3) { + constructor(crs, v0 = 0, v1 = 0, v2 = 0, v3 = 0) { if (CRS.isGeocentric(crs)) { throw new Error(`${crs} is a geocentric projection, it doesn't make sense with a geographical extent`); } @@ -76,7 +76,7 @@ class Extent { */ as(crs, target) { CRS.isValid(crs); - target = target || new Extent('EPSG:4326', [0, 0, 0, 0]); + target = target || new Extent('EPSG:4326'); if (this.crs != crs) { // Compute min/max in x/y by projecting 8 cardinal points, // and then taking the min/max of each coordinates. @@ -272,7 +272,7 @@ class Extent { */ intersect(extent) { if (!this.intersectsExtent(extent)) { - return new Extent(this.crs, 0, 0, 0, 0); + return new Extent(this.crs); } if (extent.crs != this.crs) { extent = extent.as(this.crs, _extent); @@ -302,29 +302,18 @@ class Extent { if (v0 == undefined) { throw new Error('No values to set in the extent'); } - if (v0.isExtent) { - v1 = v0.east; - v2 = v0.south; - v3 = v0.north; - v0 = v0.west; - } - - if (v0.isCoordinates) { - // seem never used - this.west = v0.x; - this.east = v1.x; - this.south = v0.y; - this.north = v1.y; - } else if (v0.west !== undefined) { - this.west = v0.west; - this.east = v0.east; - this.south = v0.south; - this.north = v0.north; + if (v0.west !== undefined) { + console.warn( + 'Deprecated Extent#constructor(string, Extent) and Extent#set(Extent),', + 'use new Extent(string).setFromExtent(Extent) instead.', + ); + this.setFromExtent(v0); } else if (v0.length == 4) { - this.west = v0[0]; - this.east = v0[1]; - this.south = v0[2]; - this.north = v0[3]; + console.warn( + 'Deprecated Extent#constructor(string, number[]) and Extent#set(number[]),', + 'use new Extent(string).setFromArray(number[]) instead.', + ); + this.setFromArray(v0); } else if (v3 !== undefined) { this.west = v0; this.east = v1; @@ -372,7 +361,7 @@ class Extent { */ copy(extent) { this.crs = extent.crs; - return this.set(extent); + return this.setFromExtent(extent); } /** @@ -463,7 +452,7 @@ class Extent { cNorthEast.setFromVector3(box.max).as(crs, cNorthEast).toVector3(box.max); } - return new Extent(crs, { + return new Extent(crs).setFromExtent({ west: box.min.x, east: box.max.x, south: box.min.y, @@ -576,6 +565,6 @@ class Extent { } } -_extent = new Extent('EPSG:4326', [0, 0, 0, 0]); +_extent = new Extent('EPSG:4326'); export default Extent; diff --git a/src/Core/Prefab/Planar/PlanarTileBuilder.ts b/src/Core/Prefab/Planar/PlanarTileBuilder.ts index 30a18e7650..73ee75bf1c 100644 --- a/src/Core/Prefab/Planar/PlanarTileBuilder.ts +++ b/src/Core/Prefab/Planar/PlanarTileBuilder.ts @@ -97,7 +97,7 @@ export class PlanarTileBuilder implements TileBuilder { // the geometry in common extent is identical to the existing input // with a translation return { - shareableExtent: new Extent(extent.crs, { + shareableExtent: new Extent(extent.crs).setFromExtent({ west: 0, east: Math.abs(extent.west - extent.east), south: 0, diff --git a/src/Core/Tile/Tile.js b/src/Core/Tile/Tile.js index d0912b7c90..7be73427ca 100644 --- a/src/Core/Tile/Tile.js +++ b/src/Core/Tile/Tile.js @@ -18,8 +18,8 @@ function _rowColfromParent(/** @type {Tile} */ tile, /** @type {number} */ zoom) return r; } -const _extent = new Extent('EPSG:4326', [0, 0, 0, 0]); -const _extent2 = new Extent('EPSG:4326', [0, 0, 0, 0]); +const _extent = new Extent('EPSG:4326'); +const _extent2 = new Extent('EPSG:4326'); const _c = new Coordinates('EPSG:4326', 0, 0); @@ -57,7 +57,7 @@ class Tile { */ toExtent(crs, target) { CRS.isValid(crs); - target = target || new Extent('EPSG:4326', [0, 0, 0, 0]); + target = target || new Extent('EPSG:4326'); const { epsg, globalExtent, globalDimension } = getInfoTms(this.crs); const countTiles = getCountTiles(this.crs, this.zoom); diff --git a/src/Source/Source.js b/src/Source/Source.js index 11c54b5f20..1e8f986c98 100644 --- a/src/Source/Source.js +++ b/src/Source/Source.js @@ -125,7 +125,7 @@ class Source extends InformationsData { this.whenReady = Promise.resolve(); this._featuresCaches = {}; if (source.extent && !(source.extent.isExtent)) { - this.extent = new Extent(this.crs, source.extent); + this.extent = new Extent(this.crs).setFromExtent(source.extent); } else { this.extent = source.extent; } diff --git a/src/Source/WFSSource.js b/src/Source/WFSSource.js index 5d2c771fa6..fa4154f051 100644 --- a/src/Source/WFSSource.js +++ b/src/Source/WFSSource.js @@ -2,7 +2,7 @@ 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]); +const _extent = new Extent('EPSG:4326'); /** * An object defining the source of resources to get from a diff --git a/src/Source/WMSSource.js b/src/Source/WMSSource.js index 41dab478b1..26f483e488 100644 --- a/src/Source/WMSSource.js +++ b/src/Source/WMSSource.js @@ -3,7 +3,7 @@ import URLBuilder from 'Provider/URLBuilder'; import Extent from 'Core/Geographic/Extent'; import * as CRS from 'Core/Geographic/Crs'; -const _extent = new Extent('EPSG:4326', [0, 0, 0, 0]); +const _extent = new Extent('EPSG:4326'); /** * Proj provides an optional param to define axis order and orientation for a diff --git a/test/unit/extent.js b/test/unit/extent.js index 3bc50d1222..2f8c24eb87 100644 --- a/test/unit/extent.js +++ b/test/unit/extent.js @@ -14,29 +14,6 @@ describe('Extent', function () { const minZ = -50; const maxZ = 42; - it('should build the expected extent using Coordinates', function () { - const withCoords = new Extent('EPSG:4326', - new Coordinates('EPSG:4326', minX, minY), - new Coordinates('EPSG:4326', maxX, maxY)); - assert.equal(minX, withCoords.west); - assert.equal(maxX, withCoords.east); - assert.equal(minY, withCoords.south); - assert.equal(maxY, withCoords.north); - }); - - it('should build the expected extent using keywords', function () { - const withKeywords = new Extent('EPSG:4326', { - south: minY, - east: maxX, - north: maxY, - west: minX, - }); - assert.equal(minX, withKeywords.west); - assert.equal(maxX, withKeywords.east); - assert.equal(minY, withKeywords.south); - assert.equal(maxY, withKeywords.north); - }); - it('should build the expected extent using values', function () { const withValues = new Extent('EPSG:4326', minX, @@ -49,14 +26,6 @@ describe('Extent', function () { assert.equal(maxY, withValues.north); }); - it('should build the expected extent using Array', function () { - const withValues = new Extent('EPSG:4326', [minX, maxX, minY, maxY]); - assert.equal(minX, withValues.west); - assert.equal(maxX, withValues.east); - assert.equal(minY, withValues.south); - assert.equal(maxY, withValues.north); - }); - it('should build the expected extent from box3', function () { const box = new Box3( new Vector3(Math.random(), Math.random()), @@ -125,7 +94,7 @@ describe('Extent', function () { }); it('should clone extent like expected', function () { - const withValues = new Extent('EPSG:4326', [minX, maxX, minY, maxY]); + const withValues = new Extent('EPSG:4326', minX, maxX, minY, maxY); const clonedExtent = withValues.clone(); assert.equal(clonedExtent.west, withValues.west); assert.equal(clonedExtent.east, withValues.east); @@ -134,7 +103,7 @@ describe('Extent', function () { }); it('should convert extent EPSG:4326 like expected', function () { - const withValues = new Extent('EPSG:4326', [minX, maxX, minY, maxY]).as('EPSG:3857'); + const withValues = new Extent('EPSG:4326', minX, maxX, minY, maxY).as('EPSG:3857'); assert.equal(0, withValues.west); assert.equal(1113194.9079327357, withValues.east); assert.equal(-111325.14286638597, withValues.south); @@ -142,33 +111,33 @@ describe('Extent', function () { }); it('should return center of extent expected', function () { - const withValues = new Extent('EPSG:4326', [minX, maxX, minY, maxY]); + const withValues = new Extent('EPSG:4326', minX, maxX, minY, maxY); const center = withValues.center(); assert.equal(5, center.longitude); assert.equal(1, center.latitude); }); it('should return dimensions of extent expected', function () { - const withValues = new Extent('EPSG:4326', [minX, maxX, minY, maxY]); + const withValues = new Extent('EPSG:4326', minX, maxX, minY, maxY); const dimensions = withValues.planarDimensions(); assert.equal(10, dimensions.x); assert.equal(4, dimensions.y); }); it('should return true is point is inside extent expected', function () { - const withValues = new Extent('EPSG:4326', [minX, maxX, minY, maxY]); + const withValues = new Extent('EPSG:4326', minX, maxX, minY, maxY); const coord = new Coordinates('EPSG:4326', minX + 1, minY + 2); assert.ok(withValues.isPointInside(coord)); }); it('should return true is extent is inside extent expected', function () { - const withValues = new Extent('EPSG:4326', [minX, maxX, minY, maxY]); - const inside = new Extent('EPSG:4326', [minX + 1, maxX - 1, minY + 1, maxY - 1]); + const withValues = new Extent('EPSG:4326', minX, maxX, minY, maxY); + const inside = new Extent('EPSG:4326', minX + 1, maxX - 1, minY + 1, maxY - 1); assert.ok(withValues.isInside(inside, 1)); }); it('should return expected offset', function () { - const withValues = new Extent('EPSG:4326', [minX, maxX, minY, maxY]); - const inside = new Extent('EPSG:4326', [minX + 1, maxX - 1, minY + 1, maxY - 1]); + const withValues = new Extent('EPSG:4326', minX, maxX, minY, maxY); + const inside = new Extent('EPSG:4326', minX + 1, maxX - 1, minY + 1, maxY - 1); const offset = withValues.offsetToParent(inside); assert.equal(offset.x, -0.125); assert.equal(offset.y, -0.5); @@ -177,14 +146,14 @@ describe('Extent', function () { }); it('should return true if intersect other extent', function () { - const withValues = new Extent('EPSG:4326', [minX, maxX, minY, maxY]); - const inter = new Extent('EPSG:4326', [minX + 1, maxX - 1, maxY - 1, maxY + 2]); + const withValues = new Extent('EPSG:4326', minX, maxX, minY, maxY); + const inter = new Extent('EPSG:4326', minX + 1, maxX - 1, maxY - 1, maxY + 2); assert.ok(withValues.intersectsExtent(inter)); }); it('should intersect like expected', function () { - const withValues = new Extent('EPSG:4326', [minX, maxX, minY, maxY]); - const extent = new Extent('EPSG:4326', [minX + 1, maxX - 1, maxY - 1, maxY + 2]); + const withValues = new Extent('EPSG:4326', minX, maxX, minY, maxY); + const extent = new Extent('EPSG:4326', minX + 1, maxX - 1, maxY - 1, maxY + 2); const inter = withValues.intersect(extent); assert.equal(1, inter.west); assert.equal(9, inter.east); @@ -193,7 +162,7 @@ describe('Extent', function () { }); it('should set values', function () { - const withValues = new Extent('EPSG:4326', [0, 0, 0, 0]); + const withValues = new Extent('EPSG:4326'); withValues.set(minX, maxX, minY, maxY); assert.equal(minX, withValues.west); assert.equal(maxX, withValues.east); @@ -202,7 +171,7 @@ describe('Extent', function () { }); it('should set values from array', function () { - const extent = new Extent('EPSG:4326', 0, 0, 0, 0); + const extent = new Extent('EPSG:4326'); const array = [minX, maxX, minY, maxY, minZ, maxZ]; extent.setFromArray(array); @@ -219,7 +188,7 @@ describe('Extent', function () { }); it('sould set values from an extent-like object', function () { - const extent = new Extent('EPSG:4326', 0, 0, 0, 0); + const extent = new Extent('EPSG:4326'); extent.setFromExtent({ west: minX, east: maxX, @@ -233,8 +202,8 @@ describe('Extent', function () { }); it('should copy extent', function () { - const toCopy = new Extent('EPSG:2154', [minX, maxX, minY, maxY]); - const withValues = new Extent('EPSG:4326', [0, 0, 0, 0]); + const toCopy = new Extent('EPSG:2154', minX, maxX, minY, maxY); + const withValues = new Extent('EPSG:4326'); withValues.copy(toCopy); assert.equal('EPSG:2154', withValues.crs); assert.equal(minX, withValues.west); @@ -244,8 +213,8 @@ describe('Extent', function () { }); it('should union like expected', function () { - const withValues = new Extent('EPSG:4326', [minX, maxX, minY, maxY]); - const extent = new Extent('EPSG:4326', [minX + 1, maxX - 1, maxY - 1, maxY + 2]); + const withValues = new Extent('EPSG:4326', minX, maxX, minY, maxY); + const extent = new Extent('EPSG:4326', minX + 1, maxX - 1, maxY - 1, maxY + 2); withValues.union(extent); assert.equal(0, withValues.west); assert.equal(10, withValues.east); @@ -254,7 +223,7 @@ describe('Extent', function () { }); it('should expand by point', function () { - const withValues = new Extent('EPSG:4326', [minX, maxX, minY, maxY]); + const withValues = new Extent('EPSG:4326', minX, maxX, minY, maxY); const coord = new Coordinates('EPSG:4326', maxX + 1, maxY + 2); withValues.expandByCoordinates(coord); assert.equal(0, withValues.west); @@ -264,7 +233,7 @@ describe('Extent', function () { }); it('should convert EPSG extent values to string', function () { - const withValues = new Extent('EPSG:4326', [minX, maxX, minY, maxY]); + const withValues = new Extent('EPSG:4326', minX, maxX, minY, maxY); const tostring = withValues.toString(','); const toValues = tostring.split(',').map(s => Number(s)); assert.equal(toValues[0], withValues.east); @@ -274,8 +243,8 @@ describe('Extent', function () { }); it('should copy and transform extent', function () { - const withValues = new Extent('EPSG:4326', [0, 0, 0, 0]); - const extent = new Extent('EPSG:4326', [minX + 1, maxX - 1, maxY - 1, maxY + 2]); + const withValues = new Extent('EPSG:4326', 0, 0, 0, 0); + const extent = new Extent('EPSG:4326', minX + 1, maxX - 1, maxY - 1, maxY + 2); const position = new Vector3(1, 2, 0); const scale = new Vector3(2, -2, 1); const quaternion = new Quaternion();