Map fixes.
This commit is contained in:
@@ -19,23 +19,18 @@ 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 if (goog.isObject(opt_arg)) {
|
||||
center = opt_arg['center'];
|
||||
target = opt_arg['target'];
|
||||
zoom = opt_arg['zoom'];
|
||||
}
|
||||
else {
|
||||
throw new Error('ol.map');
|
||||
@@ -43,7 +38,12 @@ ol.map = function(opt_arg){
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
@@ -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);
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user