From 8b741bc666fb5c889276e5ce1ff63c2b31f4dce9 Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Fri, 24 Jul 2009 21:58:39 +0000 Subject: [PATCH] Adding an autoActivate property for controls. If this is set to true, the control will be activated when it is added to a map. This is true for the Navigation, NavigationHistory, KeyboardDefaults, and Panel controls. False for others. r=elemoine (closes #2200) git-svn-id: http://svn.openlayers.org/trunk/openlayers@9589 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- lib/OpenLayers/Control.js | 7 ++++++ lib/OpenLayers/Control/KeyboardDefaults.js | 8 ++++++- lib/OpenLayers/Control/Navigation.js | 8 ++++++- lib/OpenLayers/Control/NavigationHistory.js | 11 ++++----- lib/OpenLayers/Control/Panel.js | 8 ++++++- lib/OpenLayers/Map.js | 3 +++ tests/Control.html | 25 +++++++++++++++++++++ 7 files changed, 60 insertions(+), 10 deletions(-) diff --git a/lib/OpenLayers/Control.js b/lib/OpenLayers/Control.js index 81cc596290..57997667a2 100644 --- a/lib/OpenLayers/Control.js +++ b/lib/OpenLayers/Control.js @@ -105,6 +105,13 @@ OpenLayers.Control = OpenLayers.Class({ */ title: "", + /** + * APIProperty: autoActivate + * {Boolean} Activate the control when it is added to a map. Default is + * false. + */ + autoActivate: false, + /** * Property: active * {Boolean} The control is active. diff --git a/lib/OpenLayers/Control/KeyboardDefaults.js b/lib/OpenLayers/Control/KeyboardDefaults.js index 2ab4a604e5..70bc6148cf 100644 --- a/lib/OpenLayers/Control/KeyboardDefaults.js +++ b/lib/OpenLayers/Control/KeyboardDefaults.js @@ -21,6 +21,13 @@ */ OpenLayers.Control.KeyboardDefaults = OpenLayers.Class(OpenLayers.Control, { + /** + * APIProperty: autoActivate + * {Boolean} Activate the control when it is added to a map. Default is + * true. + */ + autoActivate: true, + /** * APIProperty: slideFactor * Pixels to slide by. @@ -53,7 +60,6 @@ OpenLayers.Control.KeyboardDefaults = OpenLayers.Class(OpenLayers.Control, { draw: function() { this.handler = new OpenLayers.Handler.Keyboard( this, { "keydown": this.defaultKeyPress }); - this.activate(); }, /** diff --git a/lib/OpenLayers/Control/Navigation.js b/lib/OpenLayers/Control/Navigation.js index 4ace37b429..f671ff85e9 100644 --- a/lib/OpenLayers/Control/Navigation.js +++ b/lib/OpenLayers/Control/Navigation.js @@ -65,6 +65,13 @@ OpenLayers.Control.Navigation = OpenLayers.Class(OpenLayers.Control, { */ zoomBoxKeyMask: OpenLayers.Handler.MOD_SHIFT, + /** + * APIProperty: autoActivate + * {Boolean} Activate the control when it is added to a map. Default is + * true. + */ + autoActivate: true, + /** * Constructor: OpenLayers.Control.Navigation * Create a new navigation control @@ -153,7 +160,6 @@ OpenLayers.Control.Navigation = OpenLayers.Class(OpenLayers.Control, { this.handlers.wheel = new OpenLayers.Handler.MouseWheel( this, {"up" : this.wheelUp, "down": this.wheelDown} ); - this.activate(); }, /** diff --git a/lib/OpenLayers/Control/NavigationHistory.js b/lib/OpenLayers/Control/NavigationHistory.js index b7b37aa351..baed374f47 100644 --- a/lib/OpenLayers/Control/NavigationHistory.js +++ b/lib/OpenLayers/Control/NavigationHistory.js @@ -67,11 +67,11 @@ OpenLayers.Control.NavigationHistory = OpenLayers.Class(OpenLayers.Control, { limit: 50, /** - * Property: activateOnDraw - * {Boolean} Activate the control when it is first added to the map. - * Default is true. + * APIProperty: autoActivate + * {Boolean} Activate the control when it is added to a map. Default is + * true. */ - activateOnDraw: true, + autoActivate: true, /** * Property: clearOnDeactivate @@ -224,9 +224,6 @@ OpenLayers.Control.NavigationHistory = OpenLayers.Class(OpenLayers.Control, { OpenLayers.Control.prototype.draw.apply(this, arguments); this.next.draw(); this.previous.draw(); - if(this.activateOnDraw) { - this.activate(); - } }, /** diff --git a/lib/OpenLayers/Control/Panel.js b/lib/OpenLayers/Control/Panel.js index a6045a3139..1b65ebee0d 100644 --- a/lib/OpenLayers/Control/Panel.js +++ b/lib/OpenLayers/Control/Panel.js @@ -21,6 +21,13 @@ OpenLayers.Control.Panel = OpenLayers.Class(OpenLayers.Control, { */ controls: null, + /** + * APIProperty: autoActivate + * {Boolean} Activate the control when it is added to a map. Default is + * true. + */ + autoActivate: true, + /** * APIProperty: defaultControl * {} The control which is activated when the control is @@ -107,7 +114,6 @@ OpenLayers.Control.Panel = OpenLayers.Class(OpenLayers.Control, { scope: this }); } - this.activate(); return this.div; }, diff --git a/lib/OpenLayers/Map.js b/lib/OpenLayers/Map.js index f7aef8ad81..111bf5d205 100644 --- a/lib/OpenLayers/Map.js +++ b/lib/OpenLayers/Map.js @@ -1197,6 +1197,9 @@ OpenLayers.Map = OpenLayers.Class({ this.viewPortDiv.appendChild( div ); } } + if(control.autoActivate) { + control.activate(); + } }, /** diff --git a/tests/Control.html b/tests/Control.html index 6bf6966258..a94426f2b5 100644 --- a/tests/Control.html +++ b/tests/Control.html @@ -72,6 +72,31 @@ t.ok(control.map == null, "Control.map is null"); t.ok(control.handler == null, "Control.handler is null"); } + + function test_autoActivate(t) { + + t.plan(3); + + var control, map = new OpenLayers.Map("map"); + + // confirm that a control is not activated by default + control = new OpenLayers.Control(); + map.addControl(control); + t.ok(!control.active, "control is not activated by default"); + + // confirm that control is activated with autoActivate true + control = new OpenLayers.Control({autoActivate: true}); + map.addControl(control); + t.ok(control.active, "control is activated with autoActivate true"); + + // confirm that control is not activated with autoActivate false + control = new OpenLayers.Control({autoActivate: false}); + map.addControl(control); + t.ok(!control.active, "control is not activated with autoActivate false"); + + map.destroy(); + + }