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:
Tim Schaub
2008-02-04 06:23:54 +00:00
parent 1faf641806
commit 211a2834de
6 changed files with 225 additions and 20 deletions

View File

@@ -137,7 +137,7 @@ OpenLayers.Control.Navigation = OpenLayers.Class(OpenLayers.Control, {
var size = this.map.getSize();
var deltaX = size.w/2 - evt.xy.x;
var deltaY = evt.xy.y - size.h/2;
var newRes = this.map.baseLayer.resolutions[newZoom];
var newRes = this.map.baseLayer.getResolutionForZoom(newZoom);
var zoomPoint = this.map.getLonLatFromPixel(evt.xy);
var newCenter = new OpenLayers.LonLat(
zoomPoint.lon + deltaX * newRes,

View File

@@ -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;
},
/**

View File

@@ -66,6 +66,14 @@ OpenLayers.Map = OpenLayers.Class({
*/
id: null,
/**
* Property: fractionalZoom
* {Boolean} For a base layer that supports it, allow the map resolution
* to be set to a value between one of the values in the resolutions
* array. Default is false.
*/
fractionalZoom: false,
/**
* APIProperty: events
* {<OpenLayers.Events>} An events object that handles all
@@ -1266,10 +1274,7 @@ OpenLayers.Map = OpenLayers.Class({
if(zoom == null) {
zoom = this.getZoom();
}
var resolution = null;
if(this.baseLayer != null) {
resolution = this.baseLayer.resolutions[zoom];
}
var resolution = this.getResolutionForZoom(zoom);
var extent = this.calculateBounds(lonlat, resolution);
if(!this.restrictedExtent.containsBounds(extent)) {
var maxCenter = this.restrictedExtent.getCenterLonLat();
@@ -1326,7 +1331,7 @@ OpenLayers.Map = OpenLayers.Class({
if (zoomChanged) {
this.zoom = zoom;
this.resolution = this.baseLayer.getResolution();
this.resolution = this.getResolutionForZoom(zoom);
// zoom level has changed, increment viewRequestID.
this.viewRequestID++;
}
@@ -1594,6 +1599,24 @@ OpenLayers.Map = OpenLayers.Class({
return zoom;
},
/**
* APIMethod: getResolutionForZoom
*
* Parameter:
* zoom - {Float}
*
* Returns:
* {Float} A suitable resolution for the specified zoom. If no baselayer
* is set, returns null.
*/
getResolutionForZoom: function(zoom) {
var resolution = null;
if(this.baseLayer) {
resolution = this.baseLayer.getResolutionForZoom(zoom);
}
return resolution;
},
/**
* APIMethod: getZoomForResolution
*