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:
@@ -58,6 +58,13 @@ OpenLayers.Control.PanZoomBar = OpenLayers.Class(OpenLayers.Control.PanZoom, {
|
|||||||
*/
|
*/
|
||||||
zoomWorldIcon: false,
|
zoomWorldIcon: false,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* APIProperty: forceFixedZoomLevel
|
||||||
|
* {Boolean} Force a fixed zoom level even though the map has
|
||||||
|
* fractionalZoom
|
||||||
|
*/
|
||||||
|
forceFixedZoomLevel: false,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor: OpenLayers.Control.PanZoomBar
|
* Constructor: OpenLayers.Control.PanZoomBar
|
||||||
*/
|
*/
|
||||||
@@ -266,7 +273,7 @@ OpenLayers.Control.PanZoomBar = OpenLayers.Class(OpenLayers.Control.PanZoom, {
|
|||||||
var y = evt.xy.y;
|
var y = evt.xy.y;
|
||||||
var top = OpenLayers.Util.pagePosition(evt.object)[1];
|
var top = OpenLayers.Util.pagePosition(evt.object)[1];
|
||||||
var levels = (y - top)/this.zoomStopHeight;
|
var levels = (y - top)/this.zoomStopHeight;
|
||||||
if(!this.map.fractionalZoom) {
|
if(this.forceFixedZoomLevel || !this.map.fractionalZoom) {
|
||||||
levels = Math.floor(levels);
|
levels = Math.floor(levels);
|
||||||
}
|
}
|
||||||
var zoom = (this.map.getNumZoomLevels() - 1) - 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 deltaY = this.zoomStart.y - evt.xy.y;
|
||||||
var zoomLevel = this.map.zoom;
|
var zoomLevel = this.map.zoom;
|
||||||
if (this.map.fractionalZoom) {
|
if (!this.forceFixedZoomLevel && this.map.fractionalZoom) {
|
||||||
zoomLevel += deltaY/this.zoomStopHeight;
|
zoomLevel += deltaY/this.zoomStopHeight;
|
||||||
zoomLevel = Math.min(Math.max(zoomLevel, 0),
|
zoomLevel = Math.min(Math.max(zoomLevel, 0),
|
||||||
this.map.getNumZoomLevels() - 1);
|
this.map.getNumZoomLevels() - 1);
|
||||||
|
|||||||
@@ -2,20 +2,20 @@
|
|||||||
<head>
|
<head>
|
||||||
<script src="../../lib/OpenLayers.js"></script>
|
<script src="../../lib/OpenLayers.js"></script>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
var map;
|
var map;
|
||||||
function test_Control_PanZoomBar_constructor (t) {
|
function test_Control_PanZoomBar_constructor (t) {
|
||||||
t.plan( 4 );
|
t.plan( 4 );
|
||||||
|
|
||||||
control = new OpenLayers.Control.PanZoomBar({position: new OpenLayers.Pixel(100,100)});
|
control = new OpenLayers.Control.PanZoomBar({position: new OpenLayers.Pixel(100,100)});
|
||||||
t.ok( control instanceof OpenLayers.Control.PanZoomBar, "new OpenLayers.Control.PanZoomBar returns object" );
|
t.ok( control instanceof OpenLayers.Control.PanZoomBar, "new OpenLayers.Control.PanZoomBar returns object" );
|
||||||
t.eq( control.displayClass, "olControlPanZoomBar", "displayClass is correct" );
|
t.eq( control.displayClass, "olControlPanZoomBar", "displayClass is correct" );
|
||||||
t.eq( control.position.x, 100, "PanZoom X Set correctly.");
|
t.eq( control.position.x, 100, "PanZoom X Set correctly.");
|
||||||
t.eq( control.position.y, 100, "PanZoom y Set correctly.");
|
t.eq( control.position.y, 100, "PanZoom y Set correctly.");
|
||||||
}
|
}
|
||||||
function test_Control_PanZoomBar_addControl (t) {
|
function test_Control_PanZoomBar_addControl (t) {
|
||||||
t.plan( 8 );
|
t.plan( 8 );
|
||||||
map = new OpenLayers.Map('map', {controls:[]});
|
map = new OpenLayers.Map('map', {controls:[]});
|
||||||
var layer = new OpenLayers.Layer.WMS("Test Layer",
|
var layer = new OpenLayers.Layer.WMS("Test Layer",
|
||||||
"http://octo.metacarta.com/cgi-bin/mapserv?",
|
"http://octo.metacarta.com/cgi-bin/mapserv?",
|
||||||
{map: "/mapdata/vmap_wms.map", layers: "basic"});
|
{map: "/mapdata/vmap_wms.map", layers: "basic"});
|
||||||
map.addLayer(layer);
|
map.addLayer(layer);
|
||||||
@@ -33,11 +33,11 @@
|
|||||||
map.addControl(control2, new OpenLayers.Pixel(100,100));
|
map.addControl(control2, new OpenLayers.Pixel(100,100));
|
||||||
t.eq( control2.div.style.top, "100px", "2nd control div is located correctly");
|
t.eq( control2.div.style.top, "100px", "2nd control div is located correctly");
|
||||||
}
|
}
|
||||||
|
|
||||||
function test_Control_PanZoomBar_clearDiv(t) {
|
function test_Control_PanZoomBar_clearDiv(t) {
|
||||||
t.plan(2);
|
t.plan(2);
|
||||||
map = new OpenLayers.Map('map', {controls:[]});
|
map = new OpenLayers.Map('map', {controls:[]});
|
||||||
var layer = new OpenLayers.Layer.WMS("Test Layer",
|
var layer = new OpenLayers.Layer.WMS("Test Layer",
|
||||||
"http://octo.metacarta.com/cgi-bin/mapserv?",
|
"http://octo.metacarta.com/cgi-bin/mapserv?",
|
||||||
{map: "/mapdata/vmap_wms.map", layers: "basic"});
|
{map: "/mapdata/vmap_wms.map", layers: "basic"});
|
||||||
map.addLayer(layer);
|
map.addLayer(layer);
|
||||||
@@ -48,11 +48,11 @@
|
|||||||
t.eq(control.div.childNodes.length, 0, "control's div cleared.");
|
t.eq(control.div.childNodes.length, 0, "control's div cleared.");
|
||||||
t.eq(control.zoombarDiv, null, "zoombar div nullified.")
|
t.eq(control.zoombarDiv, null, "zoombar div nullified.")
|
||||||
}
|
}
|
||||||
|
|
||||||
function test_Control_PanZoomBar_divClick (t) {
|
function test_Control_PanZoomBar_divClick (t) {
|
||||||
t.plan(2);
|
t.plan(2);
|
||||||
map = new OpenLayers.Map('map', {controls:[]});
|
map = new OpenLayers.Map('map', {controls:[]});
|
||||||
var layer = new OpenLayers.Layer.WMS("Test Layer",
|
var layer = new OpenLayers.Layer.WMS("Test Layer",
|
||||||
"http://octo.metacarta.com/cgi-bin/mapserv?",
|
"http://octo.metacarta.com/cgi-bin/mapserv?",
|
||||||
{map: "/mapdata/vmap_wms.map", layers: "basic"});
|
{map: "/mapdata/vmap_wms.map", layers: "basic"});
|
||||||
map.addLayer(layer);
|
map.addLayer(layer);
|
||||||
@@ -64,7 +64,21 @@
|
|||||||
map.fractionalZoom = true;
|
map.fractionalZoom = true;
|
||||||
control.divClick({'xy': {'x': 0, 'y': 49}, which: 1});
|
control.divClick({'xy': {'x': 0, 'y': 49}, which: 1});
|
||||||
t.eq(map.zoom.toFixed(3), '10.545', "zoom is correct on fractional zoom map");
|
t.eq(map.zoom.toFixed(3), '10.545', "zoom is correct on fractional zoom map");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
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>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user