diff --git a/examples/fractional-zoom.html b/examples/fractional-zoom.html
index e5d7377498..f8c51f22f4 100644
--- a/examples/fractional-zoom.html
+++ b/examples/fractional-zoom.html
@@ -13,7 +13,10 @@
var map;
function init() {
- map = new OpenLayers.Map('map');
+ map = new OpenLayers.Map('map',
+ {controls: [new OpenLayers.Control.Navigation(),
+ new OpenLayers.Control.PanZoomBar()],
+ numZoomLevels: 10 });
var wms = new OpenLayers.Layer.WMS(
"OpenLayers WMS",
"http://labs.metacarta.com/wms/vmap0",
@@ -22,7 +25,6 @@
map.addLayers([wms]);
map.events.register("moveend", null, displayZoom);
- map.addControl( new OpenLayers.Control.LayerSwitcher() );
map.zoomToMaxExtent();
@@ -36,6 +38,7 @@
function update(input) {
map.fractionalZoom = input.checked;
+ map.zoomTo(Math.round(map.zoom));
}
diff --git a/lib/OpenLayers/Control/PanZoomBar.js b/lib/OpenLayers/Control/PanZoomBar.js
index adb7c65cc5..fca45c9844 100644
--- a/lib/OpenLayers/Control/PanZoomBar.js
+++ b/lib/OpenLayers/Control/PanZoomBar.js
@@ -241,8 +241,14 @@ OpenLayers.Control.PanZoomBar = OpenLayers.Class(OpenLayers.Control.PanZoom, {
}
var y = evt.xy.y;
var top = OpenLayers.Util.pagePosition(evt.object)[1];
- var levels = Math.floor((y - top)/this.zoomStopHeight);
- this.map.zoomTo((this.map.getNumZoomLevels() -1) - levels);
+ var levels = (y - top)/this.zoomStopHeight;
+ var zoom = (this.map.getNumZoomLevels() - 1) - levels;
+ if(this.map.fractionalZoom) {
+ zoom = Math.min(Math.max(zoom, 0), this.map.getNumZoomLevels() - 1);
+ } else {
+ zoom = Math.floor(zoom);
+ }
+ this.map.zoomTo(zoom);
OpenLayers.Event.stop(evt);
},
@@ -314,7 +320,15 @@ OpenLayers.Control.PanZoomBar = OpenLayers.Class(OpenLayers.Control.PanZoom, {
scope: this
});
var deltaY = this.zoomStart.y - evt.xy.y;
- this.map.zoomTo(this.map.zoom + Math.round(deltaY/this.zoomStopHeight));
+ var zoomLevel = this.map.zoom;
+ if (this.map.fractionalZoom) {
+ zoomLevel += deltaY/this.zoomStopHeight;
+ zoomLevel = Math.min(Math.max(zoomLevel, 0),
+ this.map.getNumZoomLevels() - 1);
+ } else {
+ zoomLevel += Math.round(deltaY/this.zoomStopHeight);
+ }
+ this.map.zoomTo(zoomLevel);
this.moveZoomBar();
this.mouseDragStart = null;
OpenLayers.Event.stop(evt);