Panel: Adding controls, unnecessarily activations occur followed by
deactivations (closes #2769) git-svn-id: http://svn.openlayers.org/trunk/openlayers@10699 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -156,15 +156,7 @@ OpenLayers.Control.Panel = OpenLayers.Class(OpenLayers.Control, {
|
||||
*/
|
||||
draw: function() {
|
||||
OpenLayers.Control.prototype.draw.apply(this, arguments);
|
||||
for (var i=0, len=this.controls.length; i<len; i++) {
|
||||
this.map.addControl(this.controls[i]);
|
||||
this.controls[i].deactivate();
|
||||
this.controls[i].events.on({
|
||||
"activate": this.redraw,
|
||||
"deactivate": this.redraw,
|
||||
scope: this
|
||||
});
|
||||
}
|
||||
this.addControlsToMap(this.controls);
|
||||
return this.div;
|
||||
},
|
||||
|
||||
@@ -261,17 +253,36 @@ OpenLayers.Control.Panel = OpenLayers.Class(OpenLayers.Control, {
|
||||
}
|
||||
|
||||
if (this.map) { // map.addControl() has already been called on the panel
|
||||
this.addControlsToMap(controls);
|
||||
this.redraw();
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: addControlsToMap
|
||||
* Only for internal use in draw() and addControls() methods.
|
||||
*
|
||||
* Parameters:
|
||||
* controls - {Array(<OpenLayers.Control>)} Controls to add into map.
|
||||
*/
|
||||
addControlsToMap: function (controls) {
|
||||
var control;
|
||||
for (var i=0, len=controls.length; i<len; i++) {
|
||||
this.map.addControl(controls[i]);
|
||||
controls[i].deactivate();
|
||||
controls[i].events.on({
|
||||
control = controls[i];
|
||||
if (control.autoActivate === true) {
|
||||
control.autoActivate = false;
|
||||
this.map.addControl(control);
|
||||
control.autoActivate = true;
|
||||
} else {
|
||||
this.map.addControl(control);
|
||||
control.deactivate();
|
||||
}
|
||||
control.events.on({
|
||||
"activate": this.redraw,
|
||||
"deactivate": this.redraw,
|
||||
scope: this
|
||||
});
|
||||
}
|
||||
this.redraw();
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
@@ -211,6 +211,23 @@
|
||||
map.destroy();
|
||||
}
|
||||
|
||||
function test_Control_Panel_autoActivate (t) {
|
||||
t.plan(1);
|
||||
var map = new OpenLayers.Map('map');
|
||||
var controlNoDeactive = new OpenLayers.Control({autoActivate:true});
|
||||
var chkDeactivate = function () {
|
||||
t.ok(false, "Tool control autoActivate:true was deactivated unnecessarily");
|
||||
};
|
||||
controlNoDeactive.events.on({deactivate: chkDeactivate});
|
||||
var panel = new OpenLayers.Control.Panel();
|
||||
|
||||
map.addControl(panel);
|
||||
panel.addControls([controlNoDeactive]);
|
||||
controlNoDeactive.events.un({deactivate: chkDeactivate});
|
||||
t.ok(!controlNoDeactive.active, "Tool control autoActivate:true is not active");
|
||||
|
||||
}
|
||||
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
Reference in New Issue
Block a user