Debugged.

This commit is contained in:
Tim Schaub
2012-06-19 10:39:42 +02:00
parent 738561e417
commit 90f33c587a
6 changed files with 59 additions and 47 deletions

View File

@@ -1,23 +1,23 @@
goog.provide('ol.loc');
goog.require('ol.Location');
goog.require('ol.Loc');
/**
* @typedef {ol.Location|Array.<number>|{{x:number, y:number, z:number=, projection: ol.Projection=}}} loc Location.
* @typedef {ol.Loc|Array.<number>|Object} loc Location.
*/
ol.LocationLike;
ol.LocLike;
/**
* @export
* @param {ol.LocationLike} loc Location.
* @return {ol.Location} Location.
* @param {ol.LocLike} loc Location.
* @return {ol.Loc} Location.
*/
ol.loc = function(loc) {
if (loc instanceof ol.Location) {
if (loc instanceof ol.Loc) {
return loc;
}
@@ -53,7 +53,7 @@ ol.loc = function(loc) {
throw new Error('ol.loc');
}
return new ol.Location(x, y, z, projection);
return new ol.Loc(x, y, z, projection);
};
@@ -61,10 +61,10 @@ ol.loc = function(loc) {
/**
* @export
* @param {ol.Projection=} opt_arg Projection.
* @return {ol.Location|ol.Projection} Result.
* @return {ol.Loc|ol.Projection|undefined} Result.
*/
ol.Location.prototype.projection = function(opt_arg) {
if (arguments.length == 1) {
ol.Loc.prototype.projection = function(opt_arg) {
if (arguments.length == 1 && goog.isDef(opt_arg)) {
return this.setProjection(opt_arg);
} else {
return this.getProjection();
@@ -75,10 +75,10 @@ ol.Location.prototype.projection = function(opt_arg) {
/**
* @export
* @param {number=} opt_arg X.
* @return {ol.Location|number} Result.
* @return {ol.Loc|number} Result.
*/
ol.Location.prototype.x = function(opt_arg) {
if (arguments.length == 1) {
ol.Loc.prototype.x = function(opt_arg) {
if (arguments.length == 1 && goog.isDef(opt_arg)) {
return this.setX(opt_arg);
} else {
return this.getX();
@@ -89,10 +89,10 @@ ol.Location.prototype.x = function(opt_arg) {
/**
* @export
* @param {number=} opt_arg Y.
* @return {ol.Location|number} Result.
* @return {ol.Loc|number} Result.
*/
ol.Location.prototype.y = function(opt_arg) {
if (arguments.length == 1) {
ol.Loc.prototype.y = function(opt_arg) {
if (arguments.length == 1 && goog.isDef(opt_arg)) {
return this.setY(opt_arg);
} else {
return this.getY();
@@ -103,10 +103,10 @@ ol.Location.prototype.y = function(opt_arg) {
/**
* @export
* @param {number=} opt_arg Z.
* @return {ol.Location|number} Result.
* @return {ol.Loc|number|undefined} Result.
*/
ol.Location.prototype.z = function(opt_arg) {
if (arguments.length == 1) {
ol.Loc.prototype.z = function(opt_arg) {
if (arguments.length == 1 && goog.isDef(opt_arg)) {
return this.setZ(opt_arg);
} else {
return this.getZ();

View File

@@ -1,6 +1,6 @@
goog.provide('ol.map');
goog.require('ol.Location');
goog.require('ol.Loc');
goog.require('ol.Map');
goog.require('ol.Projection');
goog.require('ol.loc');
@@ -18,7 +18,7 @@ ol.MapLike;
*/
ol.map = function(opt_arg) {
/** @type {ol.Location|undefined} */
/** @type {ol.Loc|undefined} */
var center;
var target;
@@ -43,3 +43,15 @@ ol.map = function(opt_arg) {
return map;
};
/**
* @param {ol.LocLike=} opt_arg
* @returns {ol.Map|ol.Loc|undefined} Map center.
*/
ol.Map.prototype.center = function(opt_arg) {
if (arguments.length == 1 && goog.isDef(opt_arg)) {
return this.setCenter(ol.loc(opt_arg));
} else {
return this.getCenter();
}
};

View File

@@ -1,4 +1,4 @@
goog.provide('ol.Location');
goog.provide('ol.Loc');
goog.require('ol.Projection');
@@ -11,7 +11,7 @@ goog.require('ol.Projection');
* @param {number=} opt_z Z.
* @param {ol.Projection=} opt_projection Projection.
*/
ol.Location = function(x, y, opt_z, opt_projection) {
ol.Loc = function(x, y, opt_z, opt_projection) {
/**
* @private
@@ -43,7 +43,7 @@ ol.Location = function(x, y, opt_z, opt_projection) {
/**
* @return {ol.Projection|undefined} Projection.
*/
ol.Location.prototype.getProjection = function() {
ol.Loc.prototype.getProjection = function() {
return this.projection_;
};
@@ -51,7 +51,7 @@ ol.Location.prototype.getProjection = function() {
/**
* @return {number} X.
*/
ol.Location.prototype.getX = function() {
ol.Loc.prototype.getX = function() {
return this.x_;
};
@@ -59,7 +59,7 @@ ol.Location.prototype.getX = function() {
/**
* @return {number} Y.
*/
ol.Location.prototype.getY = function() {
ol.Loc.prototype.getY = function() {
return this.y_;
};
@@ -67,16 +67,16 @@ ol.Location.prototype.getY = function() {
/**
* @return {number|undefined} Z.
*/
ol.Location.prototype.getZ = function() {
ol.Loc.prototype.getZ = function() {
return this.z_;
};
/**
* @param {ol.Projection|undefined} projection Projection.
* @return {ol.Location} This.
* @return {ol.Loc} This.
*/
ol.Location.prototype.setProjection = function(projection) {
ol.Loc.prototype.setProjection = function(projection) {
this.projection_ = projection;
return this;
};
@@ -84,9 +84,9 @@ ol.Location.prototype.setProjection = function(projection) {
/**
* @param {number} x X.
* @return {ol.Location} This.
* @return {ol.Loc} This.
*/
ol.Location.prototype.setX = function(x) {
ol.Loc.prototype.setX = function(x) {
this.x_ = x;
return this;
};
@@ -94,9 +94,9 @@ ol.Location.prototype.setX = function(x) {
/**
* @param {number} y Y.
* @return {ol.Location} This.
* @return {ol.Loc} This.
*/
ol.Location.prototype.setY = function(y) {
ol.Loc.prototype.setY = function(y) {
this.y_ = y;
return this;
};
@@ -104,9 +104,9 @@ ol.Location.prototype.setY = function(y) {
/**
* @param {number|undefined} z Z.
* @return {ol.Location} This.
* @return {ol.Loc} This.
*/
ol.Location.prototype.setZ = function(z) {
ol.Loc.prototype.setZ = function(z) {
this.z_ = z;
return this;
};

View File

@@ -1,6 +1,6 @@
goog.provide('ol.Map');
goog.require('ol.Location');
goog.require('ol.Loc');
goog.require('ol.Projection');
@@ -18,9 +18,9 @@ ol.Map = function() {
/**
* @private
* @type {ol.Location}
* @type {ol.Loc}
*/
this.location_ = new ol.Location(0, 0);
this.location_ = new ol.Loc(0, 0);
/**
* @private
@@ -32,7 +32,7 @@ ol.Map = function() {
/**
* @return {ol.Location} Location.
* @return {ol.Loc} Location.
*/
ol.Map.prototype.getCenter = function() {
return this.center_;
@@ -56,7 +56,7 @@ ol.Map.prototype.getZoom = function() {
/**
* @param {ol.Location} center Center.
* @param {ol.Loc} center Center.
* @return {ol.Map} This.
*/
ol.Map.prototype.setCenter = function(center) {

View File

@@ -1,11 +1,11 @@
describe("ol.Location", function() {
describe("ol.Loc", function() {
it("allows flexible construction", function() {
var loc;
// nowhere
loc = ol.loc();
expect(loc instanceof ol.Location).toBe(true);
expect(loc instanceof ol.Loc).toBe(true);
// obj config
loc = ol.loc({x: 10, y: 20});
@@ -80,7 +80,7 @@ describe("ol.Location", function() {
var loc = ol.loc({x: 10, y: 20, projection: "EPSG:4326"});
var trans = loc.transform("EPSG:3857");
expect(trans instanceof ol.Location).toBe(true);
expect(trans instanceof ol.Loc).toBe(true);
expect(trans.projection().code()).toBe("EPSG:3857");
expect(trans.x().toFixed(3)).toBe("1113194.908");
expect(trans.y().toFixed(3)).toBe("2273030.927");
@@ -95,7 +95,7 @@ describe("ol.Location", function() {
var loc = ol.loc({x: 1113195, y: 2273031, projection: "EPSG:3857"});
var trans = loc.transform("EPSG:4326");
expect(trans instanceof ol.Location).toBe(true);
expect(trans instanceof ol.Loc).toBe(true);
expect(trans.projection().code()).toBe("EPSG:4326");
expect(trans.x().toFixed(3)).toBe("10.000");
expect(trans.y().toFixed(3)).toBe("20.000");

View File

@@ -21,7 +21,7 @@ describe("ol.Map", function() {
center = map.center();
expect(center.x().toFixed(3)).toBe("-110.000");
expect(center.y().toFixed(3)).toBe("45.000");
expect(center instanceof ol.Location).toBe(true);
expect(center instanceof ol.Loc).toBe(true);
// with object literal
map.center({x: -111, y: 46});
@@ -29,7 +29,7 @@ describe("ol.Map", function() {
center = map.center();
expect(center.x().toFixed(3)).toBe("-111.000");
expect(center.y().toFixed(3)).toBe("46.000");
expect(center instanceof ol.Location).toBe(true);
expect(center instanceof ol.Loc).toBe(true);
// more verbose
map = ol.map({
@@ -39,7 +39,7 @@ describe("ol.Map", function() {
center = map.center();
expect(center.x().toFixed(3)).toBe("-112.000");
expect(center.y().toFixed(3)).toBe("47.000");
expect(center instanceof ol.Location).toBe(true);
expect(center instanceof ol.Loc).toBe(true);
});