Small fixes.

This commit is contained in:
Tim Schaub
2012-06-19 09:43:20 +02:00
parent e84a0473d5
commit f24b518f61
7 changed files with 18 additions and 15 deletions

114
src/api/ol/loc.js Normal file
View File

@@ -0,0 +1,114 @@
goog.provide('ol.loc');
goog.require('ol.Location');
/**
* @typedef {ol.Location|Array.<number>|{{x:number, y:number, z:number=, projection: ol.Projection=}}} loc Location.
*/
ol.LocationLike;
/**
* @export
* @param {ol.LocationLike} loc Location.
* @return {ol.Location} Location.
*/
ol.loc = function(loc) {
if (loc instanceof ol.Location) {
return loc;
}
var x = 0;
var y = 0;
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 {
throw new Error('ol.loc');
}
return new ol.Location(x, y, z, projection);
};
/**
* @export
* @param {ol.Projection=} opt_arg Projection.
* @return {ol.Location|ol.Projection} Result.
*/
ol.Location.prototype.projection = function(opt_arg) {
if (arguments.length == 1) {
return this.setProjection(opt_arg);
} else {
return this.getProjection();
}
};
/**
* @export
* @param {number=} opt_arg X.
* @return {ol.Location|number} Result.
*/
ol.Location.prototype.x = function(opt_arg) {
if (arguments.length == 1) {
return this.setX(opt_arg);
} else {
return this.getX();
}
};
/**
* @export
* @param {number=} opt_arg Y.
* @return {ol.Location|number} Result.
*/
ol.Location.prototype.y = function(opt_arg) {
if (arguments.length == 1) {
return this.setY(opt_arg);
} else {
return this.getY();
}
};
/**
* @export
* @param {number=} opt_arg Z.
* @return {ol.Location|number} Result.
*/
ol.Location.prototype.z = function(opt_arg) {
if (arguments.length == 1) {
return this.setZ(opt_arg);
} else {
return this.getZ();
}
};

45
src/api/ol/map.js Normal file
View File

@@ -0,0 +1,45 @@
goog.provide('ol.map');
goog.require('ol.Location');
goog.require('ol.Map');
goog.require('ol.Projection');
goog.require('ol.loc');
/**
* @typedef {ol.Map|Object|string}
*/
ol.MapLike;
/**
* @param {ol.MapLike=} opt_arg Argument.
* @return {ol.Map} Map.
*/
ol.map = function(opt_arg) {
/** @type {ol.Location|undefined} */
var center;
var target;
if (arguments.length == 1) {
if (opt_arg instanceof ol.Map) {
return opt_arg;
} else if (goog.isObject(opt_arg)) {
var config = opt_arg;
if (goog.isDef(config.center)) {
center = ol.loc(config.center);
}
if (goog.isDef(config.target)) {
target = config.target;
}
} else {
throw new Error('ol.map');
}
}
var map = new ol.Map();
return map;
};

43
src/api/ol/projection.js Normal file
View File

@@ -0,0 +1,43 @@
goog.provide('ol.projection');
goog.require('ol.Projection');
/**
* @typedef {ol.Projection|string}
*/
ol.ProjectionLike;
/**
* @export
* @param {ol.ProjectionLike=} opt_arg Argument.
* @return {ol.Projection} Projection.
*/
ol.projection = function(opt_arg) {
var code;
if (arguments.length == 1) {
if (opt_arg instanceof ol.Projection) {
return opt_arg;
} else if (goog.isString(arguments[0])) {
code = arguments[0];
} else {
throw new Error('ol.projection');
}
}
return new ol.Projection(code);
};
/**
* @export
* @param {string=} opt_code Code.
* @return {ol.Projection|string} Result.
*/
ol.Projection.prototype.code = function(opt_code) {
if (goog.isDef(opt_code)) {
return this.setCode(opt_code);
} else {
return this.getCode();
}
};