Map fixes.

This commit is contained in:
Tom Payne
2012-06-19 13:08:50 +02:00
parent f435bb1874
commit 7358529c4e
3 changed files with 34 additions and 22 deletions

View File

@@ -19,31 +19,31 @@ ol.MapLike;
*/
ol.map = function(opt_arg){
/** @type {ol.Loc|undefined} */
var center;
var target;
var zoom;
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');
}
else if (goog.isObject(opt_arg)) {
center = opt_arg['center'];
target = opt_arg['target'];
zoom = opt_arg['zoom'];
}
else {
throw new Error('ol.map');
}
}
var map = new ol.Map();
if (goog.isDef(center)) {
map.setCenter(ol.loc(center));
}
if (goog.isDef(zoom)) {
map.setZoom(zoom);
}
return map;
};
@@ -62,7 +62,7 @@ ol.Map.prototype.center = function(opt_arg) {
/**
* @param {ol.ProjectionLike=} opt_arg
* @returns {ol.Map|ol.Loc|undefined}
* @returns {ol.Map|ol.Projection|undefined}
*/
ol.Map.prototype.projection = function(opt_arg) {
if (arguments.length == 1 && goog.isDef(opt_arg)) {
@@ -74,7 +74,7 @@ ol.Map.prototype.projection = function(opt_arg) {
/**
* @param {ol.ProjectionLike=} opt_arg
* @returns {ol.Map|ol.Loc|undefined}
* @returns {ol.Map|ol.Projection|undefined}
*/
ol.Map.prototype.userProjection = function(opt_arg) {
if (arguments.length == 1 && goog.isDef(opt_arg)) {
@@ -83,3 +83,15 @@ ol.Map.prototype.userProjection = function(opt_arg) {
return this.getUserProjection();
}
};
/**
* @param {number=} opt_arg
* @returns {ol.Map|number|undefined} Map center.
*/
ol.Map.prototype.zoom = function(opt_arg) {
if (arguments.length == 1 && goog.isDef(opt_arg)) {
return this.setZoom(opt_arg);
} else {
return this.getZoom();
}
};