Include tests/test_Projection.html and lib/OpenLayers/Projection.js (taken from

projections.2.patch). (Closes #1035)



git-svn-id: http://svn.openlayers.org/trunk/openlayers@5405 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
Frédéric Junod
2007-12-14 08:36:36 +00:00
parent 47edbf4524
commit 22bbf98398
2 changed files with 140 additions and 0 deletions
+113
View File
@@ -0,0 +1,113 @@
/* Copyright (c) 2006-2007 MetaCarta, Inc., published under a modified BSD license.
* See http://svn.openlayers.org/trunk/openlayers/repository-license.txt
* for the full text of the license. */
/**
* @requires OpenLayers/Util.js
*
* Class: OpenLayers.Projection
* Class for coordinate transformations between coordinate systems.
* Depends on the proj4js library. If proj4js is not available,
* then this is just an empty stub.
*/
OpenLayers.Projection = OpenLayers.Class({
/**
* Constructor: OpenLayers.Projection
* This class offers several methods for interacting with a wrapped
* pro4js projection object.
*
* Parameters:
* options - {Object} An optional object with properties to set on the
* format
*
* Returns:
* {<OpenLayers.Projection>} A projection object.
*/
initialize: function(projCode, options) {
OpenLayers.Util.extend(this, options);
this.projCode = projCode;
if (window.Proj4js) {
this.proj = new Proj4js.Proj(projCode);
}
},
/**
* APIMethod: getCode
* Get the string SRS code.
*
* Returns:
* {String} The SRS code.
*/
getCode: function() {
return this.proj ? this.proj.srsCode : this.projCode;
},
/**
* APIMethod: getUnits
* Get the units string for the projection -- returns null if
* proj4js is not available.
*
* Returns:
* {String} The units abbreviation.
*/
getUnits: function() {
return this.proj ? this.proj.units : null;
},
/**
* Method: toString
* Convert projection to string (getCode wrapper).
*
* Returns:
* {String} The projection code.
*/
toString: function() {
return this.getCode();
},
/**
* Method: equals
* Test equality of two projection instances. Determines equality based
* soley on the projection code.
*
* Returns:
* {Boolean} The two projections are equivalent.
*/
equals: function(projection) {
if (this.getCode() == projection.getCode()) {
return true;
}
return false;
},
/* Method: destroy
* Destroy projection object.
*/
destroy: function() {
delete this.proj;
delete this.projCode;
},
CLASS_NAME: "OpenLayers.Projection"
});
/**
* APIMethod: transform
* Read data from a string, and return an object whose type depends on the
* subclass.
*
* Parameters:
* point - {object} input horizontal coodinate
* sourceProj - {OpenLayers.Projection} source map coordinate system
* destProj - {OpenLayers.Projection} destination map coordinate system
*
* Returns:
* point - {object} trasnformed coordinate
*/
OpenLayers.Projection.transform = function(point, source, dest) {
if (source.proj && dest.proj) {
point = Proj4js.transform(source.proj, dest.proj, point);
}
return point;
};
+27
View File
@@ -0,0 +1,27 @@
<html>
<head>
<script src="../lib/OpenLayers.js"></script>
<script type="text/javascript">
function test_01_Projection_constructor(t) {
t.plan(7);
var options = {'foo': 'bar'};
var projection = new OpenLayers.Projection("code", options);
t.ok(projection instanceof OpenLayers.Projection,
"new OpenLayers.Projection returns object" );
t.eq(projection.projCode, "code", "The proj code is maintained");
t.eq(projection.getCode(), "code", "The proj code is maintained.");
t.eq(projection.getUnits(), null, "Null units with no proj4js library.");
t.eq(projection.foo, "bar", "constructor sets options correctly");
var projection2 = new OpenLayers.Projection("epsg:4325", options);
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");
}
</script>
</head>
<body>
</body>
</html>