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() {
|
draw: function() {
|
||||||
OpenLayers.Control.prototype.draw.apply(this, arguments);
|
OpenLayers.Control.prototype.draw.apply(this, arguments);
|
||||||
for (var i=0, len=this.controls.length; i<len; i++) {
|
this.addControlsToMap(this.controls);
|
||||||
this.map.addControl(this.controls[i]);
|
|
||||||
this.controls[i].deactivate();
|
|
||||||
this.controls[i].events.on({
|
|
||||||
"activate": this.redraw,
|
|
||||||
"deactivate": this.redraw,
|
|
||||||
scope: this
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return this.div;
|
return this.div;
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -261,19 +253,38 @@ OpenLayers.Control.Panel = OpenLayers.Class(OpenLayers.Control, {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (this.map) { // map.addControl() has already been called on the panel
|
if (this.map) { // map.addControl() has already been called on the panel
|
||||||
for (var i=0, len=controls.length; i<len; i++) {
|
this.addControlsToMap(controls);
|
||||||
this.map.addControl(controls[i]);
|
|
||||||
controls[i].deactivate();
|
|
||||||
controls[i].events.on({
|
|
||||||
"activate": this.redraw,
|
|
||||||
"deactivate": this.redraw,
|
|
||||||
scope: this
|
|
||||||
});
|
|
||||||
}
|
|
||||||
this.redraw();
|
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++) {
|
||||||
|
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
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method: onClick
|
* Method: onClick
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -211,6 +211,23 @@
|
|||||||
map.destroy();
|
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>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|||||||
Reference in New Issue
Block a user