Handle projections with different aliases: smarter Projection.equals and Layer.WMS.getFullRequestString methods. r=tschaub (closes #2914)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@10869 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
ahocevar
2010-11-05 07:33:38 +00:00
parent aa9112c494
commit b9517a4cb5
4 changed files with 103 additions and 11 deletions

View File

@@ -252,7 +252,10 @@ OpenLayers.Layer.WMS = OpenLayers.Class(OpenLayers.Layer.Grid, {
* {String}
*/
getFullRequestString:function(newParams, altUrl) {
var projectionCode = this.map.getProjection();
var mapProjection = this.map.getProjectionObject();
var projectionCode = this.projection.equals(mapProjection) ?
this.projection.getCode() :
mapProjection.getCode();
var value = (projectionCode == "none") ? null : projectionCode
if (parseFloat(this.params.VERSION) >= 1.3) {
this.params.CRS = value;

View File

@@ -26,6 +26,12 @@ OpenLayers.Projection = OpenLayers.Class({
* {String}
*/
projCode: null,
/**
* Property: titleRegEx
* {RegEx} regular expression to strip the title from a proj4js definition
*/
titleRegEx: /\+title=[^\+]*/,
/**
* Constructor: OpenLayers.Projection
@@ -92,11 +98,20 @@ OpenLayers.Projection = OpenLayers.Class({
* {Boolean} The two projections are equivalent.
*/
equals: function(projection) {
if (projection && projection.getCode) {
return this.getCode() == projection.getCode();
} else {
return false;
}
var p = projection, equals = false;
if (p) {
if (window.Proj4js && this.proj.defData && p.proj.defData) {
equals = this.proj.defData.replace(this.titleRegEx, "") ==
p.proj.defData.replace(this.titleRegEx, "");
} else if (p.getCode) {
var source = this.getCode(), target = p.getCode();
equals = source == target ||
!!OpenLayers.Projection.transforms[source] &&
OpenLayers.Projection.transforms[source][target] ===
OpenLayers.Projection.nullTransform;
}
}
return equals;
},
/* Method: destroy
@@ -176,3 +191,23 @@ OpenLayers.Projection.transform = function(point, source, dest) {
}
return point;
};
/**
* APIFunction: nullTransform
* A null transformation - useful for defining projection aliases when
* proj4js is not available:
*
* (code)
* OpenLayers.Projection.addTransform("EPSG:4326", "EPSG:3857",
* OpenLayers.Layer.SphericalMercator.projectForward);
* OpenLayers.Projection.addTransform("EPSG:3857", "EPSG:3857",
* OpenLayers.Layer.SphericalMercator.projectInverse);
* OpenLayers.Projection.addTransform("EPSG:3857", "EPSG:900913",
* OpenLayers.Projection.nullTransform);
* OpenLayers.Projection.addTransform("EPSG:900913", "EPSG:3857",
* OpenLayers.Projection.nullTransform);
* (end)
*/
OpenLayers.Projection.nullTransform = function(point) {
return point;
};