Map fixes.
This commit is contained in:
+29
-17
@@ -19,31 +19,31 @@ ol.MapLike;
|
|||||||
*/
|
*/
|
||||||
ol.map = function(opt_arg){
|
ol.map = function(opt_arg){
|
||||||
|
|
||||||
/** @type {ol.Loc|undefined} */
|
|
||||||
var center;
|
var center;
|
||||||
var target;
|
var target;
|
||||||
|
var zoom;
|
||||||
|
|
||||||
if (arguments.length == 1) {
|
if (arguments.length == 1) {
|
||||||
if (opt_arg instanceof ol.Map) {
|
if (opt_arg instanceof ol.Map) {
|
||||||
return opt_arg;
|
return opt_arg;
|
||||||
}
|
}
|
||||||
else
|
else if (goog.isObject(opt_arg)) {
|
||||||
if (goog.isObject(opt_arg)) {
|
center = opt_arg['center'];
|
||||||
var config = opt_arg;
|
target = opt_arg['target'];
|
||||||
if (goog.isDef(config.center)) {
|
zoom = opt_arg['zoom'];
|
||||||
center = ol.loc(config.center);
|
}
|
||||||
}
|
else {
|
||||||
if (goog.isDef(config.target)) {
|
throw new Error('ol.map');
|
||||||
target = config.target;
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
throw new Error('ol.map');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var map = new 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;
|
return map;
|
||||||
|
|
||||||
};
|
};
|
||||||
@@ -62,7 +62,7 @@ ol.Map.prototype.center = function(opt_arg) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {ol.ProjectionLike=} 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) {
|
ol.Map.prototype.projection = function(opt_arg) {
|
||||||
if (arguments.length == 1 && goog.isDef(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
|
* @param {ol.ProjectionLike=} opt_arg
|
||||||
* @returns {ol.Map|ol.Loc|undefined}
|
* @returns {ol.Map|ol.Projection|undefined}
|
||||||
*/
|
*/
|
||||||
ol.Map.prototype.userProjection = function(opt_arg) {
|
ol.Map.prototype.userProjection = function(opt_arg) {
|
||||||
if (arguments.length == 1 && goog.isDef(opt_arg)) {
|
if (arguments.length == 1 && goog.isDef(opt_arg)) {
|
||||||
@@ -83,3 +83,15 @@ ol.Map.prototype.userProjection = function(opt_arg) {
|
|||||||
return this.getUserProjection();
|
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();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|||||||
+3
-3
@@ -14,13 +14,13 @@ ol.Map = function() {
|
|||||||
* @private
|
* @private
|
||||||
* @type {ol.Projection}
|
* @type {ol.Projection}
|
||||||
*/
|
*/
|
||||||
this.projection_ = new ol.Projection();
|
this.projection_ = new ol.Projection('EPSG:900913');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
* @type {ol.Projection}
|
* @type {ol.Projection}
|
||||||
*/
|
*/
|
||||||
this.userProjection_ = new ol.Projection();
|
this.userProjection_ = new ol.Projection('EPSG:4326');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
@@ -93,7 +93,7 @@ ol.Map.prototype.setProjection = function(projection) {
|
|||||||
* @param {ol.Projection} userProjection User projection.
|
* @param {ol.Projection} userProjection User projection.
|
||||||
* @return {ol.Map} This.
|
* @return {ol.Map} This.
|
||||||
*/
|
*/
|
||||||
ol.Map.prototype.setProjection = function(userProjection) {
|
ol.Map.prototype.setUserProjection = function(userProjection) {
|
||||||
this.userProjection_ = userProjection;
|
this.userProjection_ = userProjection;
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -63,8 +63,8 @@ describe("ol.Map", function() {
|
|||||||
|
|
||||||
center = map.center();
|
center = map.center();
|
||||||
zoom = map.zoom();
|
zoom = map.zoom();
|
||||||
expect(center.x().toFixed(3)).toBe("4.000");
|
expect(center.x().toFixed(3)).toBe("1.000");
|
||||||
expect(center.y().toFixed(3)).toBe("5.000");
|
expect(center.y().toFixed(3)).toBe("2.000");
|
||||||
expect(zoom).toBe(6);
|
expect(zoom).toBe(6);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user