diff --git a/lib/OpenLayers/Projection.js b/lib/OpenLayers/Projection.js index 7e652ba27d..7e42b8459b 100644 --- a/lib/OpenLayers/Projection.js +++ b/lib/OpenLayers/Projection.js @@ -101,6 +101,9 @@ OpenLayers.Projection = OpenLayers.Class({ equals: function(projection) { var p = projection, equals = false; if (p) { + if (!(projection instanceof OpenLayers.Projection)) { + projection = new OpenLayers.Projection(projection); + } if (window.Proj4js && this.proj.defData && p.proj.defData) { equals = this.proj.defData.replace(this.titleRegEx, "") == p.proj.defData.replace(this.titleRegEx, ""); diff --git a/tests/Projection.html b/tests/Projection.html index 6ef317dde2..bb458b6f17 100644 --- a/tests/Projection.html +++ b/tests/Projection.html @@ -24,7 +24,7 @@ } function test_Projection_equals(t) { - t.plan(8); + t.plan(12); var origTransforms = OpenLayers.Util.extend({}, OpenLayers.Projection.transforms); OpenLayers.Projection.addTransform("EPSG:4326", "FOO", OpenLayers.Projection.nullTransform); OpenLayers.Projection.addTransform("FOO", "EPSG:4326", OpenLayers.Projection.nullTransform); @@ -57,6 +57,12 @@ t.eq(proj1.equals(proj4), true, "EPSG:4326 and EPSG:4326 are equal with proj4js"); t.eq(proj2.equals(proj5), false, "Projection.equals() returns false for unknown projections with proj4js"); + // allow comparison with identifier + t.eq(proj1.equals("EPSG:4326"), true, "EPSG:4326 equality with string"); + t.eq(proj1.equals("EPSG:4327"), false, "EPSG:4326 inequality with string"); + t.eq(proj1.equals("EPSG:900913"), true, "EPSG:900913 equality with string"); + t.eq(proj1.equals("EPSG:900914"), false, "EPSG:900913 inequality with string"); + if (!hasProj) { window.Proj4js = undefined; }