Commit scale-based methods back into trunk. Layers or Maps now support setting

a list of scales or resolutions in the options to the constructor, from which
resolutions are calculated. Map now has a 'setScale' function which will allow
you to zoom to as close to a given scale as possible.


git-svn-id: http://svn.openlayers.org/trunk/openlayers@1171 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
crschmidt
2006-08-09 19:14:16 +00:00
parent e3df606001
commit 6efaf328e5
5 changed files with 120 additions and 30 deletions

View File

@@ -87,7 +87,7 @@ OpenLayers.Map.prototype = {
* zoom level 0 on gmaps
*
* @type float */
maxResolution: 1.40625,
maxResolution: null,
/** @type int */
minZoomLevel: 0,
@@ -210,14 +210,13 @@ OpenLayers.Map.prototype = {
// if maxResolution is specified as "auto", calculate it
// based on the maxExtent and the viewSize
//
if (this.maxResolution == null && this.minScale) {
this.maxResolution = OpenLayers.Util.getResolutionFromScale(this.minScale, this.units);
} else if (this.maxResolution == "auto" || this.maxResolution == null) {
if (this.maxResolution == "auto") {
var maxExtent = this.getMaxExtent();
var viewSize = this.getSize();
this.maxResolution = Math.max(maxExtent.getWidth() / viewSize.w,
maxExtent.getHeight() / viewSize.h );
} else {
this.maxResolution = 1.40625;
}
},
@@ -826,6 +825,25 @@ OpenLayers.Map.prototype = {
/* */
/********************************************************/
/** zoom to a specified scale
*
* @param {float} scale
*/
setScale: function(scale) {
var res = OpenLayers.Util.getResolutionFromScale(scale, this.baseLayer.units);
var size = this.getSize();
var w_deg = size.w * res;
var h_deg = size.h * res;
var center = this.getCenter();
var extent = new OpenLayers.Bounds(center.lon - w_deg / 2,
center.lat - h_deg / 2,
center.lon + w_deg / 2,
center.lat + h_deg / 2);
this.zoomToExtent(extent);
},
/** Zoom to a specific zoom level
*
* @param {int} zoom