Make more Loc tests pass.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
goog.provide('ol.loc');
|
||||
|
||||
goog.require('ol.Loc');
|
||||
goog.require('ol.projection');
|
||||
|
||||
|
||||
/**
|
||||
@@ -12,13 +13,13 @@ ol.LocLike;
|
||||
|
||||
/**
|
||||
* @export
|
||||
* @param {ol.LocLike} loc Location.
|
||||
* @param {ol.LocLike} opt_arg Location.
|
||||
* @return {ol.Loc} Location.
|
||||
*/
|
||||
ol.loc = function(loc){
|
||||
ol.loc = function(opt_arg){
|
||||
|
||||
if (loc instanceof ol.Loc) {
|
||||
return loc;
|
||||
if (opt_arg instanceof ol.Loc) {
|
||||
return opt_arg;
|
||||
}
|
||||
|
||||
var x = 0;
|
||||
@@ -26,37 +27,32 @@ ol.loc = function(loc){
|
||||
var z;
|
||||
var projection;
|
||||
|
||||
if (goog.isArray(loc)) {
|
||||
if (loc.length >= 1) {
|
||||
x = loc[0];
|
||||
if (loc.length >= 2) {
|
||||
y = loc[1];
|
||||
if (loc.length >= 3) {
|
||||
z = loc[2];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
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 {
|
||||
if (arguments.length == 1 && goog.isDef(opt_arg)) {
|
||||
if (goog.isArray(opt_arg)) {
|
||||
x = opt_arg[0];
|
||||
y = opt_arg[1];
|
||||
z = opt_arg[2];
|
||||
projection = opt_arg[3];
|
||||
} else if (goog.isObject(opt_arg)) {
|
||||
x = opt_arg['x'];
|
||||
y = opt_arg['y'];
|
||||
z = opt_arg['z'];
|
||||
projection = opt_arg['projection'];
|
||||
} else {
|
||||
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){
|
||||
if (arguments.length == 1 && goog.isDef(opt_arg)) {
|
||||
return this.setProjection(opt_arg);
|
||||
return this.setProjection(ol.projection(opt_arg));
|
||||
}
|
||||
else {
|
||||
return this.getProjection();
|
||||
|
||||
@@ -16,6 +16,12 @@ ol.Map = function() {
|
||||
*/
|
||||
this.projection_ = new ol.Projection();
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {ol.Projection}
|
||||
*/
|
||||
this.userProjection_ = new ol.Projection();
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @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.
|
||||
*/
|
||||
@@ -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.
|
||||
* @return {ol.Map} This.
|
||||
|
||||
@@ -1,18 +1,25 @@
|
||||
describe("ol.Loc", function() {
|
||||
|
||||
it("allows flexible construction", function() {
|
||||
it("allows empty construction", function() {
|
||||
var loc;
|
||||
|
||||
// nowhere
|
||||
loc = ol.loc();
|
||||
expect(loc instanceof ol.Loc).toBe(true);
|
||||
});
|
||||
|
||||
it("allows construction from an obj config", function() {
|
||||
var loc;
|
||||
|
||||
// obj config
|
||||
loc = ol.loc({x: 10, y: 20});
|
||||
|
||||
expect(loc.x()).toBe(10);
|
||||
expect(loc.y()).toBe(20);
|
||||
});
|
||||
|
||||
it("allows construction from an array config", function() {
|
||||
var loc;
|
||||
// array config
|
||||
loc = ol.loc([30, 40]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user