diff --git a/lib/OpenLayers/Control/Navigation.js b/lib/OpenLayers/Control/Navigation.js index 10e1387121..c46e9c8a71 100644 --- a/lib/OpenLayers/Control/Navigation.js +++ b/lib/OpenLayers/Control/Navigation.js @@ -49,6 +49,12 @@ OpenLayers.Control.Navigation = OpenLayers.Class(OpenLayers.Control, { */ zoomBox: null, + /** + * APIProperty: zoomBoxEnabled + * {Boolean} Whether the user can draw a box to zoom + */ + zoomBoxEnabled: true, + /** * APIProperty: zoomWheelEnabled * {Boolean} Whether the mousewheel should zoom the map @@ -129,7 +135,9 @@ OpenLayers.Control.Navigation = OpenLayers.Class(OpenLayers.Control, { this.handlers.wheel.activate(); } this.handlers.click.activate(); - this.zoomBox.activate(); + if (this.zoomBoxEnabled) { + this.zoomBox.activate(); + } return OpenLayers.Control.prototype.activate.apply(this,arguments); }, @@ -252,6 +260,24 @@ OpenLayers.Control.Navigation = OpenLayers.Class(OpenLayers.Control, { this.wheelChange(evt, delta || -1); }, + /** + * Method: disableZoomBox + */ + disableZoomBox : function() { + this.zoomBoxEnabled = false; + this.zoomBox.deactivate(); + }, + + /** + * Method: enableZoomBox + */ + enableZoomBox : function() { + this.zoomBoxEnabled = true; + if (this.active) { + this.zoomBox.activate(); + } + }, + /** * Method: disableZoomWheel */ diff --git a/tests/Control/Navigation.html b/tests/Control/Navigation.html index e803e82b66..7569eb5ff0 100644 --- a/tests/Control/Navigation.html +++ b/tests/Control/Navigation.html @@ -71,6 +71,28 @@ OpenLayers.Control.prototype.destroy = temp; } + function test_Control_Navigation_disableZoomBox(t) { + t.plan(2); + var nav = new OpenLayers.Control.Navigation(); + var zb = new OpenLayers.Control.ZoomBox({}); + nav.zoomBox = zb; + zb.activate(); + nav.disableZoomBox(); + t.eq(nav.zoomBoxEnabled, false, "zoom box deactivated"); + t.eq(zb.active, false, "zoom box control deactivated"); + } + + function test_Control_Navigation_enableZoomBox(t) { + t.plan(2); + var nav = new OpenLayers.Control.Navigation(); + var zb = new OpenLayers.Control.ZoomBox({}); + nav.zoomBox = zb; + nav.active = true; + nav.enableZoomBox(); + t.eq(nav.zoomBoxEnabled, true, "zoom box activated"); + t.eq(zb.active, true, "zoom box control activated"); + } + function test_Control_Navigation_disableZoomWheel(t) { t.plan(2); var nav = new OpenLayers.Control.Navigation();