give PanZoomBar control an option to force fixed zoomlevels even if the map has fractionalZoom, patch by marcjansen, r=me, (closes #2288)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@9751 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
bartvde
2009-10-23 23:31:15 +00:00
parent 4031b304a6
commit caff5d5261
2 changed files with 33 additions and 12 deletions

View File

@@ -58,6 +58,13 @@ OpenLayers.Control.PanZoomBar = OpenLayers.Class(OpenLayers.Control.PanZoom, {
*/
zoomWorldIcon: false,
/**
* APIProperty: forceFixedZoomLevel
* {Boolean} Force a fixed zoom level even though the map has
* fractionalZoom
*/
forceFixedZoomLevel: false,
/**
* Constructor: OpenLayers.Control.PanZoomBar
*/
@@ -266,7 +273,7 @@ OpenLayers.Control.PanZoomBar = OpenLayers.Class(OpenLayers.Control.PanZoom, {
var y = evt.xy.y;
var top = OpenLayers.Util.pagePosition(evt.object)[1];
var levels = (y - top)/this.zoomStopHeight;
if(!this.map.fractionalZoom) {
if(this.forceFixedZoomLevel || !this.map.fractionalZoom) {
levels = Math.floor(levels);
}
var zoom = (this.map.getNumZoomLevels() - 1) - levels;
@@ -344,7 +351,7 @@ OpenLayers.Control.PanZoomBar = OpenLayers.Class(OpenLayers.Control.PanZoom, {
});
var deltaY = this.zoomStart.y - evt.xy.y;
var zoomLevel = this.map.zoom;
if (this.map.fractionalZoom) {
if (!this.forceFixedZoomLevel && this.map.fractionalZoom) {
zoomLevel += deltaY/this.zoomStopHeight;
zoomLevel = Math.min(Math.max(zoomLevel, 0),
this.map.getNumZoomLevels() - 1);

View File

@@ -67,6 +67,20 @@
}
function test_Control_PanZoomBar_forceFixedZoomLevel_divClick (t) {
t.plan(1);
map = new OpenLayers.Map('map', {controls:[], fractionalZoom: true});
var layer = new OpenLayers.Layer.WMS("Test Layer",
"http://octo.metacarta.com/cgi-bin/mapserv?",
{map: "/mapdata/vmap_wms.map", layers: "basic"});
map.addLayer(layer);
control = new OpenLayers.Control.PanZoomBar({forceFixedZoomLevel: true});
map.addControl(control);
control.divClick({'xy': {'x': 0, 'y': 49}, which: 1});
t.eq(map.zoom, 11, "forceFixedZoomLevel makes sure only fixed zoom levels are used even if the map has fractionalZoom");
}
</script>
</head>
<body>