From 12e817e408ce2d227e3c0f3969a1bf3a6d26d467 Mon Sep 17 00:00:00 2001 From: nd0ut Date: Fri, 17 Apr 2015 14:36:37 +0300 Subject: [PATCH] Check projections equivalence also by their code Method ol.proj.equivalent used only reference equality check === That doesn't work for basic checks of two strongly equal projections For example, `EPSG:4326` and `EPSG:4326` In this case method searches similar proj in ol.proj.transforms_ mapping And it finds it if proj is default and not custom But in case of custom proj `EPSG:3413` it doesn't find it --- src/ol/proj/proj.js | 2 ++ test/spec/ol/proj/proj.test.js | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/ol/proj/proj.js b/src/ol/proj/proj.js index d8a13e17b9..f69f02483c 100644 --- a/src/ol/proj/proj.js +++ b/src/ol/proj/proj.js @@ -656,6 +656,8 @@ ol.proj.get = function(projectionLike) { ol.proj.equivalent = function(projection1, projection2) { if (projection1 === projection2) { return true; + } else if (projection1.getCode() === projection2.getCode()) { + return true; } else if (projection1.getUnits() != projection2.getUnits()) { return false; } else { diff --git a/test/spec/ol/proj/proj.test.js b/test/spec/ol/proj/proj.test.js index df97107a21..1714236b0d 100644 --- a/test/spec/ol/proj/proj.test.js +++ b/test/spec/ol/proj/proj.test.js @@ -30,6 +30,27 @@ describe('ol.proj', function() { ]); }); + it('gives that custom 3413 is equivalent to self', function() { + var code = 'EPSG:3413'; + + var source = new ol.proj.Projection({ + code: code + }); + + var destination = new ol.proj.Projection({ + code: code + }); + + expect(ol.proj.equivalent(source, destination)).to.be.ok(); + }); + + it('gives that default 3857 is equivalent to self', function() { + _testAllEquivalent([ + 'EPSG:3857', + 'EPSG:3857' + ]); + }); + it('gives that CRS:84, urn:ogc:def:crs:EPSG:6.6:4326, EPSG:4326 are ' + 'equivalent', function() { _testAllEquivalent([