Projection cannot be null.
This commit is contained in:
+2
-2
@@ -75,7 +75,7 @@ ol.Map.prototype.getCenter = function() {
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return {ol.Projection} Projection.
|
* @return {!ol.Projection} Projection.
|
||||||
*/
|
*/
|
||||||
ol.Map.prototype.getProjection = function() {
|
ol.Map.prototype.getProjection = function() {
|
||||||
if (goog.isNull(this.projection_)) {
|
if (goog.isNull(this.projection_)) {
|
||||||
@@ -86,7 +86,7 @@ ol.Map.prototype.getProjection = function() {
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return {ol.Projection} User projection.
|
* @return {!ol.Projection} User projection.
|
||||||
*/
|
*/
|
||||||
ol.Map.prototype.getUserProjection = function() {
|
ol.Map.prototype.getUserProjection = function() {
|
||||||
if (goog.isNull(this.userProjection_)) {
|
if (goog.isNull(this.userProjection_)) {
|
||||||
|
|||||||
+22
-24
@@ -65,7 +65,7 @@ ol.Projection.prototype.getUnits = function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {string|undefined} units Units abbreviation.
|
* @param {string} units Units abbreviation.
|
||||||
* @return {ol.Projection} This.
|
* @return {ol.Projection} This.
|
||||||
*/
|
*/
|
||||||
ol.Projection.prototype.setUnits = function(units) {
|
ol.Projection.prototype.setUnits = function(units) {
|
||||||
@@ -111,12 +111,13 @@ ol.Projection.prototype.units = function(opt_units){
|
|||||||
ol.Projection.transforms = {};
|
ol.Projection.transforms = {};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* APIProperty: defaults
|
* Defaults for the SRS codes known to OpenLayers (currently EPSG:4326, CRS:84,
|
||||||
* {Object} Defaults for the SRS codes known to OpenLayers (currently
|
* urn:ogc:def:crs:EPSG:6.6:4326, EPSG:900913, EPSG:3857, EPSG:102113 and
|
||||||
* EPSG:4326, CRS:84, urn:ogc:def:crs:EPSG:6.6:4326, EPSG:900913, EPSG:3857,
|
* EPSG:102100). Keys are the SRS code, values are units, maxExtent (the
|
||||||
* EPSG:102113 and EPSG:102100). Keys are the SRS code, values are units,
|
* validity extent for the SRS) and yx (true if this SRS is known to have a
|
||||||
* maxExtent (the validity extent for the SRS) and yx (true if this SRS is
|
* reverse axis order).
|
||||||
* known to have a reverse axis order).
|
*
|
||||||
|
* @type {Object}
|
||||||
*/
|
*/
|
||||||
ol.Projection.defaults = {
|
ol.Projection.defaults = {
|
||||||
"EPSG:4326": {
|
"EPSG:4326": {
|
||||||
@@ -135,17 +136,16 @@ ol.Projection.defaults = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* APIMethod: addTransform
|
|
||||||
* Set a custom transform method between two projections. Use this method in
|
* Set a custom transform method between two projections. Use this method in
|
||||||
* cases where the proj4js lib is not available or where custom projections
|
* cases where the proj4js lib is not available or where custom projections
|
||||||
* need to be handled.
|
* need to be handled.
|
||||||
*
|
*
|
||||||
* Parameters:
|
* @param {string} from The code for the source projection.
|
||||||
* from - {String} The code for the source projection
|
* @param {string} to The code for the destination projection.
|
||||||
* to - {String} the code for the destination projection
|
* @param {function(Object)} method A function that takes an object with x and
|
||||||
* method - {Function} A function that takes a point as an argument and
|
* y properties as an argument and transforms that point from the source to
|
||||||
* transforms that point from the source to the destination projection
|
* the destination projection in place. The original point should be
|
||||||
* in place. The original point should be modified.
|
* modified.
|
||||||
*/
|
*/
|
||||||
ol.Projection.addTransform = function(from, to, method) {
|
ol.Projection.addTransform = function(from, to, method) {
|
||||||
if (method === ol.Projection.nullTransform) {
|
if (method === ol.Projection.nullTransform) {
|
||||||
@@ -166,7 +166,7 @@ ol.Projection.addTransform = function(from, to, method) {
|
|||||||
* @param {Object} point Object with x and y properties.
|
* @param {Object} point Object with x and y properties.
|
||||||
* @param {!string|!ol.Projection} source Source projection.
|
* @param {!string|!ol.Projection} source Source projection.
|
||||||
* @param {!string|!ol.Projection} dest Destination projection.
|
* @param {!string|!ol.Projection} dest Destination projection.
|
||||||
* @returns {Object} Object with x and y properties.
|
* @private
|
||||||
*/
|
*/
|
||||||
ol.Projection.transform = function(point, source, dest) {
|
ol.Projection.transform = function(point, source, dest) {
|
||||||
if (!(source instanceof ol.Projection)) {
|
if (!(source instanceof ol.Projection)) {
|
||||||
@@ -176,7 +176,7 @@ ol.Projection.transform = function(point, source, dest) {
|
|||||||
dest = new ol.Projection(dest);
|
dest = new ol.Projection(dest);
|
||||||
}
|
}
|
||||||
if (source.proj_ && dest.proj_) {
|
if (source.proj_ && dest.proj_) {
|
||||||
// point = Proj4js.transform(source.proj, dest.proj, point);
|
// point = Proj4js.transform(source.proj_, dest.proj_, point);
|
||||||
} else {
|
} else {
|
||||||
var sourceCode = source.getCode();
|
var sourceCode = source.getCode();
|
||||||
var destCode = dest.getCode();
|
var destCode = dest.getCode();
|
||||||
@@ -185,20 +185,18 @@ ol.Projection.transform = function(point, source, dest) {
|
|||||||
transforms[sourceCode][destCode](point);
|
transforms[sourceCode][destCode](point);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return point;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* APIFunction: nullTransform
|
|
||||||
* A null transformation - useful for defining projection aliases when
|
* A null transformation - useful for defining projection aliases when
|
||||||
* proj4js is not available:
|
* proj4js is not available:
|
||||||
*
|
*
|
||||||
* (code)
|
* ol.Projection.addTransform("EPSG:3857", "EPSG:900913",
|
||||||
* ol.Projection.addTransform("EPSG:3857", "EPSG:900913",
|
* ol.Projection.nullTransform);
|
||||||
* ol.Projection.nullTransform);
|
* ol.Projection.addTransform("EPSG:900913", "EPSG:3857",
|
||||||
* ol.Projection.addTransform("EPSG:900913", "EPSG:3857",
|
* ol.Projection.nullTransform);
|
||||||
* ol.Projection.nullTransform);
|
*
|
||||||
* (end)
|
* @type {function(Object)}
|
||||||
*/
|
*/
|
||||||
ol.Projection.nullTransform = function(point) {
|
ol.Projection.nullTransform = function(point) {
|
||||||
return point;
|
return point;
|
||||||
|
|||||||
@@ -27,19 +27,17 @@ describe("ol.Projection", function() {
|
|||||||
|
|
||||||
it("handles transforms", function() {
|
it("handles transforms", function() {
|
||||||
|
|
||||||
var orig = {x: 10, y: 20, z: 30};
|
var point = {x: 10, y: 20, z: 30};
|
||||||
|
|
||||||
var point = ol.Projection.transform(orig, "EPSG:4326", "EPSG:900913");
|
var ret = ol.Projection.transform(point, "EPSG:4326", "EPSG:900913");
|
||||||
|
|
||||||
|
expect(ret).toBeUndefined();
|
||||||
|
|
||||||
|
// original is modified
|
||||||
expect(point.x.toFixed(3)).toBe("1113194.908");
|
expect(point.x.toFixed(3)).toBe("1113194.908");
|
||||||
expect(point.y.toFixed(3)).toBe("2273030.927");
|
expect(point.y.toFixed(3)).toBe("2273030.927");
|
||||||
expect(point.z).toBe(30);
|
expect(point.z).toBe(30);
|
||||||
|
|
||||||
// original remains unchanged
|
|
||||||
expect(orig.x).toBe(10);
|
|
||||||
expect(orig.y).toBe(20);
|
|
||||||
expect(orig.z).toBe(30);
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user