Skip to content

Commit

Permalink
refactor(Extent): throw error if the projection is geocentric.
Browse files Browse the repository at this point in the history
  • Loading branch information
gchoqueux committed Nov 17, 2021
1 parent 1ab76c8 commit e0048f7
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 11 deletions.
6 changes: 6 additions & 0 deletions src/Core/Geographic/Extent.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ class Extent {
* Extent is geographical bounding rectangle defined by 4 limits: west, east, south and north.
* If crs is tiled projection (WMTS or TMS), the extent is defined by zoom, row and column.
*
* Warning, using geocentric projection isn't consistent with geographical extent.
*
* @param {String} crs projection of limit values.
* @param {number|Array.<number>|Coordinates|Object} v0 west value, zoom
* value, Array of values [west, east, south and north], Coordinates of
Expand All @@ -79,6 +81,10 @@ class Extent {
* @param {number} [v3] north value
*/
constructor(crs, v0, v1, v2, v3) {
if (CRS.isGeocentric(crs)) {
throw new Error(`${crs} is geocentric projection, it's not make sense with geographical extent`);
}

this.isExtent = true;
this.crs = crs;
// Scale/zoom
Expand Down
4 changes: 4 additions & 0 deletions test/unit/CameraUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import CameraUtils from 'Utils/CameraUtils';
import DEMUtils from 'Utils/DEMUtils';
import Camera, { CAMERA_TYPE } from 'Renderer/Camera';
import Extent from 'Core/Geographic/Extent';
import proj4 from 'proj4';

proj4.defs('EPSG:2154', '+proj=lcc +lat_1=49 +lat_2=44 +lat_0=46.5 +lon_0=3 +x_0=700000 +y_0=6600000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs');

function equalToFixed(value1, value2, toFixed) {
return value1.toFixed(toFixed) === value2.toFixed(toFixed);
Expand Down Expand Up @@ -113,6 +116,7 @@ describe('Camera utils unit test', function () {
it('should transform camera from given extent', function () {
view.isPlanarView = true;
view.isGlobeView = false;
view.referenceCrs = 'EPSG:2154';
const orthographicCamera = new Camera(view.referenceCrs, 60, 40, { type: CAMERA_TYPE.ORTHOGRAPHIC });
let camera3D = orthographicCamera.camera3D;

Expand Down
6 changes: 5 additions & 1 deletion test/unit/extent.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ describe('Extent', function () {
const box = new Box3(
new Vector3(Math.random(), Math.random()),
new Vector3(Math.random(), Math.random()));
const fromBox = Extent.fromBox3('EPSG:4978', box);
const fromBox = Extent.fromBox3('EPSG:4326', box);

assert.equal(fromBox.west, box.min.x);
assert.equal(fromBox.east, box.max.x);
Expand Down Expand Up @@ -315,4 +315,8 @@ describe('Extent', function () {
assert.equal(90, center.y);
assert.equal(0, center.z);
});

it('should throw error when instance with geocentric projection', () => {
assert.throws(() => new Extent('EPSG:4978'));
});
});
4 changes: 2 additions & 2 deletions test/unit/label.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('LabelLayer', function () {
geometry.closeSubGeometry(3, feature);
geometry.properties = { content: 'foo' };

extent = new Extent('EPSG:4978', -10, 10, -10, 10);
extent = new Extent('EPSG:4326', -10, 10, -10, 10);
});

it('should create Labels from a FeatureCollection like object', function () {
Expand All @@ -43,7 +43,7 @@ describe('LabelLayer', function () {
describe('Label', function () {
let label;
let style;
const c = new Coordinates('EPSG:4978');
const c = new Coordinates('EPSG:4326');
const sprites = {
img: '',
icon: { x: 0, y: 0, width: 10, height: 10 },
Expand Down
8 changes: 0 additions & 8 deletions test/unit/provider_url.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,6 @@ describe('URL creations', function () {
assert.equal(result, 'http://server.geo/wmts/SERVICE=WMTS&TILEMATRIX=12&TILEROW=1410&TILECOL=2072');
});

it('should correctly replace %bbox by 12,35,14,46', function () {
const extent = new Extent('EPSG:4978', 12, 14, 35, 46);
layer.crs = 'EPSG:4978';
layer.url = 'http://server.geo/wms/BBOX=%bbox&FORMAT=jpg&SERVICE=WMS';
const result = URLBuilder.bbox(extent, layer);
assert.equal(result, 'http://server.geo/wms/BBOX=12.00,35.00,14.00,46.00&FORMAT=jpg&SERVICE=WMS');
});

it('should correctly replace %bbox by 12,14,35,46', function () {
const extent = new Extent('EPSG:4326', 12, 14, 35, 46);
layer.crs = 'EPSG:4326';
Expand Down

0 comments on commit e0048f7

Please sign in to comment.