Merge pull request #11719 from ahocevar/less-aggressie-3857-clamping
Clamp EPSG:3857 y to lowest/highest possible value instead of validity extent
This commit is contained in:
@@ -31,6 +31,13 @@ export const EXTENT = [-HALF_SIZE, -HALF_SIZE, HALF_SIZE, HALF_SIZE];
|
|||||||
*/
|
*/
|
||||||
export const WORLD_EXTENT = [-180, -85, 180, 85];
|
export const WORLD_EXTENT = [-180, -85, 180, 85];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Maximum safe value in y direction
|
||||||
|
* @const
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
|
export const MAX_SAFE_Y = RADIUS * Math.log(Math.tan(Math.PI / 2));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @classdesc
|
* @classdesc
|
||||||
* Projection object for web/spherical Mercator (EPSG:3857).
|
* Projection object for web/spherical Mercator (EPSG:3857).
|
||||||
@@ -87,14 +94,13 @@ export function fromEPSG4326(input, opt_output, opt_dimension) {
|
|||||||
output = new Array(length);
|
output = new Array(length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const halfSize = HALF_SIZE;
|
|
||||||
for (let i = 0; i < length; i += dimension) {
|
for (let i = 0; i < length; i += dimension) {
|
||||||
output[i] = (halfSize * input[i]) / 180;
|
output[i] = (HALF_SIZE * input[i]) / 180;
|
||||||
let y = RADIUS * Math.log(Math.tan((Math.PI * (+input[i + 1] + 90)) / 360));
|
let y = RADIUS * Math.log(Math.tan((Math.PI * (+input[i + 1] + 90)) / 360));
|
||||||
if (y > halfSize) {
|
if (y > MAX_SAFE_Y) {
|
||||||
y = halfSize;
|
y = MAX_SAFE_Y;
|
||||||
} else if (y < -halfSize) {
|
} else if (y < -MAX_SAFE_Y) {
|
||||||
y = -halfSize;
|
y = -MAX_SAFE_Y;
|
||||||
}
|
}
|
||||||
output[i + 1] = y;
|
output[i + 1] = y;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,8 @@
|
|||||||
import {HALF_SIZE, fromEPSG4326} from '../../../../src/ol/proj/epsg3857.js';
|
import {
|
||||||
|
HALF_SIZE,
|
||||||
|
MAX_SAFE_Y,
|
||||||
|
fromEPSG4326,
|
||||||
|
} from '../../../../src/ol/proj/epsg3857.js';
|
||||||
import {
|
import {
|
||||||
addCommon,
|
addCommon,
|
||||||
clearAllProjections,
|
clearAllProjections,
|
||||||
@@ -24,11 +28,11 @@ describe('ol/proj/epsg3857', function () {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
g: [-180, -90],
|
g: [-180, -90],
|
||||||
m: [-HALF_SIZE, -HALF_SIZE],
|
m: [-HALF_SIZE, -MAX_SAFE_Y],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
g: [180, 90],
|
g: [180, 90],
|
||||||
m: [HALF_SIZE, HALF_SIZE],
|
m: [HALF_SIZE, MAX_SAFE_Y],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
g: [-111.0429, 45.677],
|
g: [-111.0429, 45.677],
|
||||||
@@ -47,7 +51,7 @@ describe('ol/proj/epsg3857', function () {
|
|||||||
it('does not produce unexpected results for string coordinates', function () {
|
it('does not produce unexpected results for string coordinates', function () {
|
||||||
const transformed = fromEPSG4326(['180', '90']);
|
const transformed = fromEPSG4326(['180', '90']);
|
||||||
expect(transformed[0]).to.roughlyEqual(HALF_SIZE, 1e-5);
|
expect(transformed[0]).to.roughlyEqual(HALF_SIZE, 1e-5);
|
||||||
expect(transformed[1]).to.roughlyEqual(HALF_SIZE, 1e-5);
|
expect(transformed[1]).to.roughlyEqual(MAX_SAFE_Y, 1e-5);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user