Add fromLonLat and toLonLat convenience functions

This commit is contained in:
Andreas Hocevar
2015-03-31 19:27:35 +02:00
parent fc9563ad65
commit 5579dc53a2
15 changed files with 81 additions and 20 deletions

View File

@@ -78,7 +78,7 @@ describe('ol.proj', function() {
describe('transform from 4326 to 3857 (Alastaira)', function() {
// http://alastaira.wordpress.com/2011/01/23/the-google-maps-bing-maps-spherical-mercator-projection/
it('returns expected value', function() {
it('returns expected value using ol.proj.transform', function() {
var point = ol.proj.transform(
[-5.625, 52.4827802220782], 'EPSG:4326', 'EPSG:900913');
expect(point).not.to.be(undefined);
@@ -86,12 +86,20 @@ describe('ol.proj', function() {
expect(point[0]).to.roughlyEqual(-626172.13571216376, 1e-9);
expect(point[1]).to.roughlyEqual(6887893.4928337997, 1e-8);
});
it('returns expected value using ol.proj.fromLonLat', function() {
var point = ol.proj.fromLonLat([-5.625, 52.4827802220782]);
expect(point).not.to.be(undefined);
expect(point).not.to.be(null);
expect(point[0]).to.roughlyEqual(-626172.13571216376, 1e-9);
expect(point[1]).to.roughlyEqual(6887893.4928337997, 1e-8);
});
});
describe('transform from 3857 to 4326 (Alastaira)', function() {
// http://alastaira.wordpress.com/2011/01/23/the-google-maps-bing-maps-spherical-mercator-projection/
it('returns expected value', function() {
it('returns expected value using ol.proj.transform', function() {
var point = ol.proj.transform([-626172.13571216376, 6887893.4928337997],
'EPSG:900913', 'EPSG:4326');
expect(point).not.to.be(undefined);
@@ -99,6 +107,14 @@ describe('ol.proj', function() {
expect(point[0]).to.roughlyEqual(-5.625, 1e-9);
expect(point[1]).to.roughlyEqual(52.4827802220782, 1e-9);
});
it('returns expected value using ol.proj.toLonLat', function() {
var point = ol.proj.toLonLat([-626172.13571216376, 6887893.4928337997]);
expect(point).not.to.be(undefined);
expect(point).not.to.be(null);
expect(point[0]).to.roughlyEqual(-5.625, 1e-9);
expect(point[1]).to.roughlyEqual(52.4827802220782, 1e-9);
});
});
describe('transformExtent()', function() {
@@ -139,6 +155,21 @@ describe('ol.proj', function() {
delete proj4.defs['EPSG:21781'];
});
it('works with ol.proj.fromLonLat and ol.proj.toLonLat', function() {
proj4.defs('EPSG:21781',
'+proj=somerc +lat_0=46.95240555555556 +lon_0=7.439583333333333 ' +
'+k_0=1 +x_0=600000 +y_0=200000 +ellps=bessel ' +
'+towgs84=674.374,15.056,405.346,0,0,0,0 +units=m +no_defs');
var lonLat = [7.439583333333333, 46.95240555555556];
var point = ol.proj.fromLonLat(lonLat, 'EPSG:21781');
expect(point[0]).to.roughlyEqual(600072.300, 1);
expect(point[1]).to.roughlyEqual(200146.976, 1);
point = ol.proj.toLonLat(point, 'EPSG:21781');
expect(point[0]).to.roughlyEqual(lonLat[0], 1);
expect(point[1]).to.roughlyEqual(lonLat[1], 1);
delete proj4.defs['EPSG:21781'];
});
it('caches the new Proj4js projections given their srsCode', function() {
proj4.defs('EPSG:21781',
'+proj=somerc +lat_0=46.95240555555556 +lon_0=7.439583333333333 ' +