diff --git a/lib/OpenLayers.js b/lib/OpenLayers.js index d92cf0d767..62e153d8c8 100644 --- a/lib/OpenLayers.js +++ b/lib/OpenLayers.js @@ -175,7 +175,8 @@ "OpenLayers/Layer/WFS.js", "OpenLayers/Control/MouseToolbar.js", "OpenLayers/Control/NavToolbar.js", - "OpenLayers/Control/EditingToolbar.js" + "OpenLayers/Control/EditingToolbar.js", + "OpenLayers/Projection.js" ); // etc. diff --git a/lib/OpenLayers/Format/GeoJSON.js b/lib/OpenLayers/Format/GeoJSON.js index ca1c48b0fe..a894c9d4c2 100644 --- a/lib/OpenLayers/Format/GeoJSON.js +++ b/lib/OpenLayers/Format/GeoJSON.js @@ -488,7 +488,7 @@ OpenLayers.Format.GeoJSON = OpenLayers.Class(OpenLayers.Format.JSON, { * of a GeoJSON object. */ createCRSObject: function(object) { - var proj = object.layer.projection; + var proj = object.layer.projection.toString(); var crs = {}; if (proj.match(/epsg:/i)) { var code = parseInt(proj.substring(proj.indexOf(":") + 1)); diff --git a/lib/OpenLayers/Layer.js b/lib/OpenLayers/Layer.js index ac6209fb98..0e300b836d 100644 --- a/lib/OpenLayers/Layer.js +++ b/lib/OpenLayers/Layer.js @@ -126,9 +126,11 @@ OpenLayers.Layer = OpenLayers.Class({ /** * APIProperty: projection - * {String} Set in the layer options to override the default projection - * string this layer - also set maxExtent, maxResolution, and units if - * appropriate. + * {} or {} Set in the layer options to + * override the default projection string this layer - also set maxExtent, + * maxResolution, and units if appropriate. Can be either a string or + * an object when created -- will be converted + * to an object when setMap is called if a string is passed. */ projection: null, @@ -267,6 +269,7 @@ OpenLayers.Layer = OpenLayers.Class({ if (this.map != null) { this.map.removeLayer(this, setNewBaseLayer); } + this.projection = null; this.map = null; this.name = null; this.div = null; @@ -410,7 +413,15 @@ OpenLayers.Layer = OpenLayers.Class({ // been set this.maxExtent = this.maxExtent || this.map.maxExtent; this.projection = this.projection || this.map.projection; - this.units = this.units || this.map.units; + + if (this.projection && typeof this.projection == "string") { + this.projection = new OpenLayers.Projection(this.projection); + } + + // Check the projection to see if we can get units -- if not, refer + // to properties. + this.units = this.projection.getUnits() || + this.units || this.map.units; this.initResolutions(); diff --git a/lib/OpenLayers/Layer/WFS.js b/lib/OpenLayers/Layer/WFS.js index f1aed8a0b0..81d7353aa0 100644 --- a/lib/OpenLayers/Layer/WFS.js +++ b/lib/OpenLayers/Layer/WFS.js @@ -376,8 +376,8 @@ OpenLayers.Layer.WFS = OpenLayers.Class( * altUrl - {String} Use this as the url instead of the layer's url */ getFullRequestString:function(newParams, altUrl) { - var projection = this.map.getProjection(); - this.params.SRS = (projection == "none") ? null : projection; + var projectionCode = this.map.getProjection(); + this.params.SRS = (projectionCode == "none") ? null : projectionCode; return OpenLayers.Layer.Grid.prototype.getFullRequestString.apply( this, arguments); diff --git a/lib/OpenLayers/Layer/WMS.js b/lib/OpenLayers/Layer/WMS.js index 638c7f7e6d..359af62240 100644 --- a/lib/OpenLayers/Layer/WMS.js +++ b/lib/OpenLayers/Layer/WMS.js @@ -211,8 +211,8 @@ OpenLayers.Layer.WMS = OpenLayers.Class(OpenLayers.Layer.Grid, { * {String} */ getFullRequestString:function(newParams, altUrl) { - var projection = this.map.getProjection(); - this.params.SRS = (projection == "none") ? null : projection; + var projectionCode = this.map.getProjection(); + this.params.SRS = (projectionCode == "none") ? null : projectionCode; return OpenLayers.Layer.Grid.prototype.getFullRequestString.apply( this, arguments); diff --git a/lib/OpenLayers/Map.js b/lib/OpenLayers/Map.js index 5266ed6929..ae695bdd6a 100644 --- a/lib/OpenLayers/Map.js +++ b/lib/OpenLayers/Map.js @@ -1405,11 +1405,30 @@ OpenLayers.Map = OpenLayers.Class({ /** * APIMethod: getProjection + * This method returns a string representing the projection. In + * the case of projection support, this will be the srsCode which + * is loaded -- otherwise it will simply be the string value that + * was passed to the projection at startup. + * + * FIXME: In 3.0, we will remove getProjectionObject, and instead + * return a Projection object from this function. * * Returns: - * {String} The Projection of the base layer. + * {String} The Projection string from the base layer or null. */ getProjection: function() { + var projection = this.getProjectionObject(); + return projection ? projection.getCode() : null; + }, + + /** + * APIMethod: getProjectionObject + * Returns the projection obect from the baselayer. + * + * Returns: + * {} The Projection of the base layer. + */ + getProjectionObject: function() { var projection = null; if (this.baseLayer != null) { projection = this.baseLayer.projection; diff --git a/tests/Layer/test_WMS.html b/tests/Layer/test_WMS.html index 411cac35b1..c547a68f39 100644 --- a/tests/Layer/test_WMS.html +++ b/tests/Layer/test_WMS.html @@ -236,8 +236,10 @@ t.eq(str, tUrl + "?" + OpenLayers.Util.getParameterString(tParams), "getFullRequestString() adds SRS value"); - + + map.removeLayer(tLayer); tLayer.projection = "none"; + map.addLayer(tLayer); str = tLayer.getFullRequestString(); delete tParams['SRS']; t.eq(str, diff --git a/tests/list-tests.html b/tests/list-tests.html index 83e45f8337..b281e3bf39 100644 --- a/tests/list-tests.html +++ b/tests/list-tests.html @@ -87,6 +87,7 @@
  • Handler/test_Path.html
  • Handler/test_Polygon.html
  • Handler/test_RegularPolygon.html
  • +
  • test_Projection.html
  • Renderer/test_Elements.html
  • Renderer/test_SVG.html
  • Renderer/test_VML.html