Make more Loc tests pass.

This commit is contained in:
Tom Payne
2012-06-19 12:33:59 +02:00
parent 95fe8762da
commit ef83910c3d
3 changed files with 61 additions and 34 deletions

View File

@@ -1,6 +1,7 @@
goog.provide('ol.loc'); goog.provide('ol.loc');
goog.require('ol.Loc'); goog.require('ol.Loc');
goog.require('ol.projection');
/** /**
@@ -12,13 +13,13 @@ ol.LocLike;
/** /**
* @export * @export
* @param {ol.LocLike} loc Location. * @param {ol.LocLike} opt_arg Location.
* @return {ol.Loc} Location. * @return {ol.Loc} Location.
*/ */
ol.loc = function(loc){ ol.loc = function(opt_arg){
if (loc instanceof ol.Loc) { if (opt_arg instanceof ol.Loc) {
return loc; return opt_arg;
} }
var x = 0; var x = 0;
@@ -26,37 +27,32 @@ ol.loc = function(loc){
var z; var z;
var projection; var projection;
if (goog.isArray(loc)) { if (arguments.length == 1 && goog.isDef(opt_arg)) {
if (loc.length >= 1) { if (goog.isArray(opt_arg)) {
x = loc[0]; x = opt_arg[0];
if (loc.length >= 2) { y = opt_arg[1];
y = loc[1]; z = opt_arg[2];
if (loc.length >= 3) { projection = opt_arg[3];
z = loc[2]; } else if (goog.isObject(opt_arg)) {
} x = opt_arg['x'];
} y = opt_arg['y'];
} z = opt_arg['z'];
} projection = opt_arg['projection'];
else } else {
if (goog.isObject(loc)) {
if (goog.isDef(loc.x)) {
x = loc.x;
}
if (goog.isDef(loc.y)) {
y = loc.y;
}
if (goog.isDef(loc.z)) {
z = loc.z;
}
if (goog.isDef(loc.projection)) {
projection = loc.projection;
}
}
else {
throw new Error('ol.loc'); throw new Error('ol.loc');
} }
}
if (goog.isDef(projection)) {
projection = ol.projection(projection);
}
return new ol.Loc(x, y, z, projection); var loc = new ol.Loc();
loc.setX(x);
loc.setY(y);
loc.setZ(z);
loc.setProjection(projection);
return loc;
}; };
@@ -68,7 +64,7 @@ ol.loc = function(loc){
*/ */
ol.Loc.prototype.projection = function(opt_arg){ ol.Loc.prototype.projection = function(opt_arg){
if (arguments.length == 1 && goog.isDef(opt_arg)) { if (arguments.length == 1 && goog.isDef(opt_arg)) {
return this.setProjection(opt_arg); return this.setProjection(ol.projection(opt_arg));
} }
else { else {
return this.getProjection(); return this.getProjection();

View File

@@ -16,6 +16,12 @@ ol.Map = function() {
*/ */
this.projection_ = new ol.Projection(); this.projection_ = new ol.Projection();
/**
* @private
* @type {ol.Projection}
*/
this.userProjection_ = new ol.Projection();
/** /**
* @private * @private
* @type {ol.Loc} * @type {ol.Loc}
@@ -47,6 +53,14 @@ ol.Map.prototype.getProjection = function() {
}; };
/**
* @return {ol.Projection} User projection.
*/
ol.Map.prototype.getUserProjection = function() {
return this.userProjection_;
};
/** /**
* @return {number} Zoom. * @return {number} Zoom.
*/ */
@@ -75,6 +89,16 @@ ol.Map.prototype.setProjection = function(projection) {
}; };
/**
* @param {ol.Projection} userProjection User projection.
* @return {ol.Map} This.
*/
ol.Map.prototype.setProjection = function(userProjection) {
this.userProjection_ = userProjection;
return this;
};
/** /**
* @param {number} zoom Zoom. * @param {number} zoom Zoom.
* @return {ol.Map} This. * @return {ol.Map} This.

View File

@@ -1,18 +1,25 @@
describe("ol.Loc", function() { describe("ol.Loc", function() {
it("allows flexible construction", function() { it("allows empty construction", function() {
var loc; var loc;
// nowhere // nowhere
loc = ol.loc(); loc = ol.loc();
expect(loc instanceof ol.Loc).toBe(true); expect(loc instanceof ol.Loc).toBe(true);
});
it("allows construction from an obj config", function() {
var loc;
// obj config // obj config
loc = ol.loc({x: 10, y: 20}); loc = ol.loc({x: 10, y: 20});
expect(loc.x()).toBe(10); expect(loc.x()).toBe(10);
expect(loc.y()).toBe(20); expect(loc.y()).toBe(20);
});
it("allows construction from an array config", function() {
var loc;
// array config // array config
loc = ol.loc([30, 40]); loc = ol.loc([30, 40]);