Files
openlayers/lib/OpenLayers/Projection.js
Frédéric Junod 22bbf98398 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
2007-12-14 08:36:36 +00:00

114 lines
2.9 KiB
JavaScript

/* 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;
};