Adding fractionalZoom property to the map. This allows zooming to an arbitrary level, making it possible to have non-discrete resolutions for layers that support it. This property should not be set to true for layers with fixed zoom levels (commercial layers or others with cached tiles). r=elemoine,crschmidt,ahocevar (closes #1243)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@5982 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -758,7 +758,7 @@ OpenLayers.Layer = OpenLayers.Class({
|
||||
*/
|
||||
getResolution: function() {
|
||||
var zoom = this.map.getZoom();
|
||||
return this.resolutions[zoom];
|
||||
return this.getResolutionForZoom(zoom);
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -812,6 +812,29 @@ OpenLayers.Layer = OpenLayers.Class({
|
||||
//to be implemented by subclasses
|
||||
},
|
||||
|
||||
/**
|
||||
* APIMethod: getResolutionForZoom
|
||||
*
|
||||
* Parameter:
|
||||
* zoom - {Float}
|
||||
*
|
||||
* Returns:
|
||||
* {Float} A suitable resolution for the specified zoom.
|
||||
*/
|
||||
getResolutionForZoom: function(zoom) {
|
||||
zoom = Math.max(0, Math.min(zoom, this.resolutions.length - 1));
|
||||
var resolution;
|
||||
if(this.map.fractionalZoom) {
|
||||
var low = Math.floor(zoom);
|
||||
var high = Math.ceil(zoom);
|
||||
resolution = this.resolutions[high] +
|
||||
((zoom-low) * (this.resolutions[low]-this.resolutions[high]));
|
||||
} else {
|
||||
resolution = this.resolutions[Math.round(zoom)];
|
||||
}
|
||||
return resolution;
|
||||
},
|
||||
|
||||
/**
|
||||
* APIMethod: getZoomForResolution
|
||||
*
|
||||
@@ -831,22 +854,50 @@ OpenLayers.Layer = OpenLayers.Class({
|
||||
* value and the 'closest' specification.
|
||||
*/
|
||||
getZoomForResolution: function(resolution, closest) {
|
||||
var diff;
|
||||
var minDiff = Number.POSITIVE_INFINITY;
|
||||
for(var i=0; i < this.resolutions.length; i++) {
|
||||
if (closest) {
|
||||
diff = Math.abs(this.resolutions[i] - resolution);
|
||||
if (diff > minDiff) {
|
||||
break;
|
||||
var zoom;
|
||||
if(this.map.fractionalZoom) {
|
||||
var lowZoom = 0;
|
||||
var highZoom = this.resolutions.length - 1;
|
||||
var highRes = this.resolutions[lowZoom];
|
||||
var lowRes = this.resolutions[highZoom];
|
||||
var res;
|
||||
for(var i=0; i<this.resolutions.length; ++i) {
|
||||
res = this.resolutions[i];
|
||||
if(res >= resolution) {
|
||||
highRes = res;
|
||||
lowZoom = i;
|
||||
}
|
||||
minDiff = diff;
|
||||
} else {
|
||||
if (this.resolutions[i] < resolution) {
|
||||
if(res <= resolution) {
|
||||
lowRes = res;
|
||||
highZoom = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
var dRes = highRes - lowRes;
|
||||
if(dRes > 0) {
|
||||
zoom = lowZoom + ((resolution - lowRes) / dRes);
|
||||
} else {
|
||||
zoom = lowZoom;
|
||||
}
|
||||
} else {
|
||||
var diff;
|
||||
var minDiff = Number.POSITIVE_INFINITY;
|
||||
for(var i=0; i < this.resolutions.length; i++) {
|
||||
if (closest) {
|
||||
diff = Math.abs(this.resolutions[i] - resolution);
|
||||
if (diff > minDiff) {
|
||||
break;
|
||||
}
|
||||
minDiff = diff;
|
||||
} else {
|
||||
if (this.resolutions[i] < resolution) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
zoom = Math.max(0, i-1);
|
||||
}
|
||||
return Math.max(0, i-1);
|
||||
return zoom;
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user