Reuse half size

This commit is contained in:
Tim Schaub
2016-10-05 08:23:41 -06:00
parent 321c65b023
commit 8ac6c85f0f

View File

@@ -116,14 +116,15 @@ ol.proj.EPSG3857.fromEPSG4326 = function(input, opt_output, opt_dimension) {
}
ol.DEBUG && console.assert(output.length % dimension === 0,
'modulus of output.length with dimension should be 0');
var halfSize = ol.proj.EPSG3857.HALF_SIZE;
for (var i = 0; i < length; i += dimension) {
output[i] = ol.proj.EPSG3857.RADIUS * Math.PI * input[i] / 180;
output[i] = halfSize * input[i] / 180;
var y = ol.proj.EPSG3857.RADIUS *
Math.log(Math.tan(Math.PI * (input[i + 1] + 90) / 360));
if (y > ol.proj.EPSG3857.HALF_SIZE) {
y = ol.proj.EPSG3857.HALF_SIZE;
} else if (y < -ol.proj.EPSG3857.HALF_SIZE) {
y = -ol.proj.EPSG3857.HALF_SIZE;
if (y > halfSize) {
y = halfSize;
} else if (y < -halfSize) {
y = -halfSize;
}
output[i + 1] = y;
}
@@ -154,7 +155,7 @@ ol.proj.EPSG3857.toEPSG4326 = function(input, opt_output, opt_dimension) {
ol.DEBUG && console.assert(output.length % dimension === 0,
'modulus of output.length with dimension should be 0');
for (var i = 0; i < length; i += dimension) {
output[i] = 180 * input[i] / (ol.proj.EPSG3857.RADIUS * Math.PI);
output[i] = 180 * input[i] / ol.proj.EPSG3857.HALF_SIZE;
output[i + 1] = 360 * Math.atan(
Math.exp(input[i + 1] / ol.proj.EPSG3857.RADIUS)) / Math.PI - 90;
}