diff --git a/src/api/bounds.js b/src/api/bounds.js index e5bb790280..9097443dcd 100644 --- a/src/api/bounds.js +++ b/src/api/bounds.js @@ -49,12 +49,7 @@ ol.bounds = function(opt_arg){ throw new Error('ol.bounds'); } - var bounds = new ol.Bounds(); - bounds.setMinX(minX); - bounds.setMinY(minY); - bounds.setMaxX(maxX); - bounds.setMaxY(maxY); - bounds.setProjection(projection); + var bounds = new ol.Bounds(minX, minY, maxX, maxY, projection); return bounds; }; diff --git a/src/api/loc.js b/src/api/loc.js index 74138b049a..3afe6d6cd2 100644 --- a/src/api/loc.js +++ b/src/api/loc.js @@ -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,28 @@ 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(x, y, z, projection); + return loc; }; @@ -68,7 +60,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(); diff --git a/src/api/map.js b/src/api/map.js index e2058d5a9c..fa8d967551 100644 --- a/src/api/map.js +++ b/src/api/map.js @@ -19,57 +19,38 @@ ol.MapLike; */ ol.map = function(opt_arg){ - /** @type {ol.Loc|undefined} */ var center; - /** @type {number|undefined} */ - var zoom; - /** @type {number|undefined} */ - var numZoomLevels; - /** @type {ol.Projection|undefined} */ - var projection; var target; - - var map = new ol.Map(); + 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); - map.setCenter(center); - } - if (goog.isDef(config.zoom)) { - zoom = config.zoom; - map.setZoom(zoom); - } - if (goog.isDef(config.numZoomLevels)) { - numZoomLevels = config.numZoomLevels; - map.setNumZoomLevels(numZoomLevels); - } - if (goog.isDef(config.projection)) { - projection = config.projection; - map.setProjection(projection); - } - 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; }; /** - * @param {ol.LocLike=} opt_arg Get or set the map center. - * @returns {ol.Map|ol.Loc|undefined} The map center, or the map on set. + * @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)) { @@ -80,8 +61,8 @@ ol.Map.prototype.center = function(opt_arg) { }; /** - * @param {ol.Projection|string|undefined} opt_arg Get or set the map projection. - * @returns {ol.Map|number|undefined} the current zoom level, or the map on set. + * @param {ol.ProjectionLike=} opt_arg + * @returns {ol.Map|ol.Projection|undefined} */ ol.Map.prototype.projection = function(opt_arg) { if (arguments.length == 1 && goog.isDef(opt_arg)) { @@ -93,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)) { @@ -104,8 +85,8 @@ ol.Map.prototype.userProjection = function(opt_arg) { }; /** - * @param {number|undefined} opt_arg Get or set the current zoom level. - * @returns {ol.Map|number|undefined} current zoom level on get or the map. + * @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)) { @@ -114,15 +95,3 @@ ol.Map.prototype.zoom = function(opt_arg) { return this.getZoom(); } }; - -/** - * @param {number|undefined} opt_arg Get or set the number of zoom levels. - * @returns {ol.Map|number|undefined} the number of zoom levels, or the map on set. - */ -ol.Map.prototype.numZoomLevels = function(opt_arg) { - if (arguments.length == 1 && goog.isDef(opt_arg)) { - return this.setNumZoomLevels(opt_arg); - } else { - return this.getNumZoomLevels(); - } -}; diff --git a/src/ol/Bounds.js b/src/ol/Bounds.js index 0b8e99179e..0b9d7ddf9d 100644 --- a/src/ol/Bounds.js +++ b/src/ol/Bounds.js @@ -30,13 +30,13 @@ ol.Bounds = function(minX, minY, maxX, maxY, opt_projection) { * @private * @type {number} */ - this.minX_ = minX; + this.maxX_ = maxX; /** * @private * @type {number} */ - this.minY_ = minY; + this.maxY_ = maxY; /** * @private diff --git a/src/ol/Map.js b/src/ol/Map.js index 4134c581e9..b80ff36932 100644 --- a/src/ol/Map.js +++ b/src/ol/Map.js @@ -14,13 +14,13 @@ ol.Map = function() { * @private * @type {ol.Projection} */ - this.projection_ ; + this.projection_ = new ol.Projection('EPSG:900913'); /** * @private * @type {ol.Projection} */ - this.userProjection_; + this.userProjection_ = new ol.Projection('EPSG:4326'); /** * @private @@ -120,8 +120,8 @@ ol.Map.prototype.setProjection = function(projection) { * @param {ol.Projection} projection set the user projection. * @return {ol.Map} This. */ -ol.Map.prototype.setUserProjection = function(projection) { - this.userProjection_ = projection; +ol.Map.prototype.setUserProjection = function(userProjection) { + this.userProjection_ = userProjection; return this; }; diff --git a/test/spec/ol/Loc.test.js b/test/spec/ol/Loc.test.js index d6d3306e33..2f50be703e 100644 --- a/test/spec/ol/Loc.test.js +++ b/test/spec/ol/Loc.test.js @@ -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]); diff --git a/test/spec/ol/Map.test.js b/test/spec/ol/Map.test.js index ac22a5c2af..10f9ff4176 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); });