This commit is contained in:
Marc Jansen
2012-06-20 14:59:18 +02:00
7 changed files with 155 additions and 36 deletions
+3 -3
View File
@@ -33,9 +33,9 @@ ol.Loc = function(x, y, opt_z, opt_projection) {
/**
* @private
* @type {ol.Projection|undefined}
* @type {ol.Projection}
*/
this.projection_ = opt_projection;
this.projection_ = goog.isDef(opt_projection) ? opt_projection : null;
};
@@ -73,7 +73,7 @@ ol.Loc.prototype.getZ = function() {
/**
* @param {ol.Projection|undefined} projection Projection.
* @param {ol.Projection} projection Projection.
*/
ol.Loc.prototype.setProjection = function(projection) {
this.projection_ = projection;
+63 -4
View File
@@ -42,16 +42,28 @@ ol.Map = function() {
/**
* @private
* @type {Array|undefined}
* @type {Array}
*/
this.resolutions_ = null;
/**
* @private
* @type {Array|undefined}
* @type {Array}
*/
this.layers_ = null;
/**
* @private
* @type {ol.UnreferencedBounds}
*/
this.maxExtent_ = null;
/**
* @private
* @type {number|undefined}
*/
this.maxRes_ = undefined;
};
/**
@@ -64,7 +76,16 @@ ol.Map.prototype.DEFAULT_PROJECTION = "EPSG:3857";
@type {string}
*/
ol.Map.prototype.DEFAULT_USER_PROJECTION = "EPSG:4326";
/**
@const
@type {number}
*/
ol.Map.ZOOM_FACTOR = 2;
/**
@const
@type {number}
*/
ol.Map.DEFAULT_TILE_SIZE = 256;
/**
* @return {ol.Loc} Location.
@@ -145,6 +166,37 @@ ol.Map.prototype.getMaxExtent = function() {
};
/**
* @return {number} the max resolution for the map
*/
ol.Map.prototype.getMaxRes = function() {
if (goog.isDefAndNotNull(this.maxRes_)) {
return this.maxRes_;
} else {
var extent = this.getMaxExtent();
var dim = Math.max(
(extent.getMaxX()-extent.getMinX()),
(extent.getMaxY()-extent.getMinY())
);
return dim/ol.Map.DEFAULT_TILE_SIZE;
}
};
/**
* @param {number} zoom the zoom level being requested
* @return {number} the resolution for the map at the given zoom level
*/
ol.Map.prototype.getResolutionForZoom = function(zoom) {
if (goog.isDefAndNotNull(this.resolutions_)) {
return this.resolutions_[zoom];
} else {
var maxRes = this.getMaxRes();
return maxRes/Math.pow(ol.Map.ZOOM_FACTOR, zoom);
}
};
/**
* @param {ol.Loc} center Center.
*/
@@ -199,12 +251,19 @@ ol.Map.prototype.setLayers = function(layers) {
};
/**
* @param {ol.Bounds} extent the maxExtent for the map
* @param {ol.UnreferencedBounds} extent the maxExtent for the map
*/
ol.Map.prototype.setMaxExtent = function(extent) {
this.maxExtent_ = extent;
};
/**
* @param {number} res the max resolution for the map
*/
ol.Map.prototype.setMaxRes = function(res) {
this.maxRes_ = res;
};
/**
*/
ol.Map.prototype.destroy = function() {
+14 -5
View File
@@ -21,15 +21,15 @@ ol.Projection = function(code) {
/**
* @private
* @type {!Object|undefined}
* @type {Object}
*/
this.proj_ = undefined;
this.proj_ = null;
/**
* @private
* @type {!ol.UnreferencedBounds|undefined}
* @type {ol.UnreferencedBounds}
*/
this.extent_ = undefined;
this.extent_ = null;
};
@@ -65,9 +65,18 @@ ol.Projection.prototype.setUnits = function(units) {
/**
* Get the validity extent of the coordinate reference system.
*
* @return {!ol.UnreferencedBounds|undefined} The valididty extent.
* @return {ol.UnreferencedBounds} The valididty extent.
*/
ol.Projection.prototype.getExtent = function() {
if (goog.isNull(this.extent_)) {
var defs = ol.Projection['defaults'][this.code_];
if (goog.isDef(defs)) {
var ext = defs['maxExtent'];
if (goog.isDef(ext)) {
this.setExtent(new ol.UnreferencedBounds(ext[0],ext[1],ext[2],ext[3]));
}
}
}
return this.extent_;
};