Implement getPointResolution for EPSG:3587

This commit is contained in:
Tom Payne
2013-03-03 17:17:13 +01:00
parent d3e49d0a19
commit 98d7391024
2 changed files with 59 additions and 0 deletions

View File

@@ -4,6 +4,7 @@ goog.require('goog.array');
goog.require('ol.Extent');
goog.require('ol.Projection');
goog.require('ol.ProjectionUnits');
goog.require('ol.math');
goog.require('ol.projection');
@@ -128,3 +129,12 @@ ol.projection.EPSG3857.toEPSG4326 = function(input, opt_output, opt_dimension) {
}
return output;
};
/**
* @inheritDoc
*/
ol.projection.EPSG3857.prototype.getPointResolution =
function(resolution, point) {
return resolution / ol.math.cosh(point.y / ol.projection.EPSG3857.RADIUS);
};

View File

@@ -0,0 +1,49 @@
goog.provide('ol.test.projection.EPSG3857');
describe('ol.projection.EPSG3857', function() {
describe('getPointResolution', function() {
it('returns the correct point scale at the equator', function() {
// @see http://msdn.microsoft.com/en-us/library/aa940990.aspx
var epsg3857 = ol.projection.getFromCode('EPSG:3857');
var resolution = 19.11;
var point = new ol.Coordinate(0, 0);
expect(epsg3857.getPointResolution(resolution, point)).
toRoughlyEqual(19.11, 1e-1);
});
it('returns the correct point scale at the latitude of Toronto',
function() {
// @see http://msdn.microsoft.com/en-us/library/aa940990.aspx
var epsg3857 = ol.projection.getFromCode('EPSG:3857');
var epsg4326 = ol.projection.getFromCode('EPSG:4326');
var resolution = 19.11;
var point = ol.projection.transform(
new ol.Coordinate(0, 43.65), epsg4326, epsg3857);
expect(epsg3857.getPointResolution(resolution, point)).
toRoughlyEqual(19.11 * Math.cos(Math.PI * 43.65 / 180), 1e-9);
});
it('returns the correct point scale at various latitudes', function() {
// @see http://msdn.microsoft.com/en-us/library/aa940990.aspx
var epsg3857 = ol.projection.getFromCode('EPSG:3857');
var epsg4326 = ol.projection.getFromCode('EPSG:4326');
var resolution = 19.11;
var latitude;
for (latitude = 0; latitude < 90; ++latitude) {
var point = ol.projection.transform(
new ol.Coordinate(0, latitude), epsg4326, epsg3857);
expect(epsg3857.getPointResolution(resolution, point)).
toRoughlyEqual(19.11 * Math.cos(Math.PI * latitude / 180), 1e-9);
}
});
});
});
goog.require('ol.Coordinate');
goog.require('ol.projection.EPSG3857');