diff --git a/lib/OpenLayers/Projection.js b/lib/OpenLayers/Projection.js index 3209b361ef..e12d108dd1 100644 --- a/lib/OpenLayers/Projection.js +++ b/lib/OpenLayers/Projection.js @@ -89,7 +89,11 @@ OpenLayers.Projection = OpenLayers.Class({ * {Boolean} The two projections are equivalent. */ equals: function(projection) { - return this.getCode() == projection.getCode(); + if (projection && projection.getCode) { + return this.getCode() == projection.getCode(); + } else { + return false; + } }, /* Method: destroy diff --git a/tests/test_Projection.html b/tests/test_Projection.html index c37aafa56c..a98dd57516 100644 --- a/tests/test_Projection.html +++ b/tests/test_Projection.html @@ -18,6 +18,9 @@ out = OpenLayers.Projection.transform({'x':10,'y':12}, projection, projection2); t.eq(out.x, 10, "Null transform has no effect"); t.eq(out.y, 12, "Null transform has no effect"); + + t.eq(projection.equals(null), false, "equals on null projection returns false"); + t.eq(projection.equals({}), false, "equals on null projection object returns false (doesn't call getCode)"); }