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

@@ -36,6 +36,10 @@ OpenLayers.Layer.HTTPRequest.prototype =
this.params = Object.extend( new Object(), params);
},
setMap: function(map) {
OpenLayers.Layer.prototype.setMap.apply(this, arguments);
this.initResolutions();
},
/**
*
*/
@@ -137,6 +141,37 @@ OpenLayers.Layer.HTTPRequest.prototype =
}
return requestString;
},
initResolutions: function() {
if (this.scales != null) {
this.resolutions = new Array();
for(var i = 0; i < this.scales.length; i++)
this.resolutions[i] = OpenLayers.Util.getResolutionFromScale(this.scales[i], this.units);
this.maxZoomLevel = this.resolutions.length;
} else if (this.resolutions != null) {
this.maxZoomLevel = this.resolutions.length;
} else {
this.resolutions = new Array();
if (this.minScale)
this.maxResolution = OpenLayers.Util.getResolutionFromScale(this.minScale, this.units);
var maxRes = this.getMaxResolution();
if (this.maxScale) {
/* This will cause this.map.getMaxZoomLevel() to be set the next time
* it is called, which means that the next portion here will succeed. */
var minRes = OpenLayers.Util.getResolutionFromScale(this.maxScale);
this.maxZoomLevel = Math.floor(Math.log(maxRes/minRes) / Math.log(2));
}
for (var i=this.getMinZoomLevel(); i <= this.getMaxZoomLevel(); i++) {
this.resolutions.push(maxRes / Math.pow(2, i));
}
}
},
getResolution: function() {
var zoom = this.map.getZoom();
return this.resolutions[zoom];
},
/** @final @type String */
CLASS_NAME: "OpenLayers.Layer.HTTPRequest"