diff --git a/src/api/map.js b/src/api/map.js index 31ed31f877..fa8d967551 100644 --- a/src/api/map.js +++ b/src/api/map.js @@ -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(); + } +}; diff --git a/src/ol/Map.js b/src/ol/Map.js index d480d46033..af1a9cf6e3 100644 --- a/src/ol/Map.js +++ b/src/ol/Map.js @@ -14,13 +14,13 @@ ol.Map = function() { * @private * @type {ol.Projection} */ - this.projection_ = new ol.Projection(); + this.projection_ = new ol.Projection('EPSG:900913'); /** * @private * @type {ol.Projection} */ - this.userProjection_ = new ol.Projection(); + this.userProjection_ = new ol.Projection('EPSG:4326'); /** * @private @@ -93,7 +93,7 @@ ol.Map.prototype.setProjection = function(projection) { * @param {ol.Projection} userProjection User projection. * @return {ol.Map} This. */ -ol.Map.prototype.setProjection = function(userProjection) { +ol.Map.prototype.setUserProjection = function(userProjection) { this.userProjection_ = userProjection; return this; }; diff --git a/test/spec/ol/Map.test.js b/test/spec/ol/Map.test.js index 7e93171d65..15b6105cf0 100644 --- a/test/spec/ol/Map.test.js +++ b/test/spec/ol/Map.test.js @@ -63,8 +63,8 @@ describe("ol.Map", function() { center = map.center(); zoom = map.zoom(); - expect(center.x().toFixed(3)).toBe("4.000"); - expect(center.y().toFixed(3)).toBe("5.000"); + expect(center.x().toFixed(3)).toBe("1.000"); + expect(center.y().toFixed(3)).toBe("2.000"); expect(zoom).toBe(6); });