From 22bbf98398038b43edd5623c835adc322a6a2579 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Junod?= Date: Fri, 14 Dec 2007 08:36:36 +0000 Subject: [PATCH] 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 --- lib/OpenLayers/Projection.js | 113 +++++++++++++++++++++++++++++++++++ tests/test_Projection.html | 27 +++++++++ 2 files changed, 140 insertions(+) create mode 100644 lib/OpenLayers/Projection.js create mode 100644 tests/test_Projection.html diff --git a/lib/OpenLayers/Projection.js b/lib/OpenLayers/Projection.js new file mode 100644 index 0000000000..750970735a --- /dev/null +++ b/lib/OpenLayers/Projection.js @@ -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: + * {} 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; +}; diff --git a/tests/test_Projection.html b/tests/test_Projection.html new file mode 100644 index 0000000000..c37aafa56c --- /dev/null +++ b/tests/test_Projection.html @@ -0,0 +1,27 @@ + + + + + + + +