As always, its amazing what a fresh start allows one to see.<div><br></div><div>As an alternate (and, I suspect better solution), one can also accomplish the goal of having activating a control on a panel deactivate controls on other panels by passing in a custom activateControl when generating all panels that are to be linked in this multi panel, as shown below. </div>
<div><br></div><div>The event solution (or some variation of it) is probably more version stable, in the sense that a future change to panel.activateControl would require adjustment in the custom method solution. On the other hand, the custom method works within the structure already set up to accomplish the deactivation of other controls, and therefore seems preferable. Am I missing anything? Any reason to prefer one over the other?</div>
<div><br></div><div>Thanks,</div><div><br></div><div>Josh</div><div><br></div><div>custom activateControl as follows:</div><div><br></div><div><span class="Apple-style-span" style="font-style: italic;"> var multiPanelActivateControl = function (control) {<br>
</span></div><div><div><span class="Apple-style-span" style="font-style: italic;"> if (!this.active) { return false; }</span></div><div><span class="Apple-style-span" style="font-style: italic;"> if (control.type == OpenLayers.Control.TYPE_BUTTON) {</span></div>
<div><span class="Apple-style-span" style="font-style: italic;"> control.trigger();</span></div><div><span class="Apple-style-span" style="font-style: italic;"> this.redraw();</span></div><div>
<span class="Apple-style-span" style="font-style: italic;"> return;</span></div><div><span class="Apple-style-span" style="font-style: italic;"> }</span></div><div><span class="Apple-style-span" style="font-style: italic;"> if (control.type == OpenLayers.Control.TYPE_TOGGLE) {</span></div>
<div><span class="Apple-style-span" style="font-style: italic;"> if (control.active) {</span></div><div><span class="Apple-style-span" style="font-style: italic;"> control.deactivate();</span></div>
<div><span class="Apple-style-span" style="font-style: italic;"> } else {</span></div><div><span class="Apple-style-span" style="font-style: italic;"> control.activate();</span></div><div>
<span class="Apple-style-span" style="font-style: italic;"> }</span></div><div><span class="Apple-style-span" style="font-style: italic;"> this.redraw();</span></div><div><span class="Apple-style-span" style="font-style: italic;"> return;</span></div>
<div><span class="Apple-style-span" style="font-style: italic;"> }</span></div><div><span class="Apple-style-span" style="font-style: italic;"> </span></div><div><span class="Apple-style-span" style="font-style: italic;"> var panelList = map.getControlsByClass("OpenLayers.Control.Panel");</span></div>
<div><span class="Apple-style-span" style="font-style: italic;"> for (var j=0, pLen=panelList.length; j<pLen; j++) {</span></div><div><span class="Apple-style-span" style="font-style: italic;"> var currPanel = panelList[j];</span></div>
<div><span class="Apple-style-span" style="font-style: italic;"> for (var i=0, len=currPanel.controls.length; i<len; i++) {</span></div><div><span class="Apple-style-span" style="font-style: italic;"> if (currPanel.controls[i] != control) {</span></div>
<div><span class="Apple-style-span" style="font-style: italic;"> if (currPanel.controls[i].type != OpenLayers.Control.TYPE_TOGGLE) {</span></div><div><span class="Apple-style-span" style="font-style: italic;"> currPanel.controls[i].deactivate();</span></div>
<div><span class="Apple-style-span" style="font-style: italic;"> }</span></div><div><span class="Apple-style-span" style="font-style: italic;"> }</span></div><div><span class="Apple-style-span" style="font-style: italic;"> }</span></div>
<div><span class="Apple-style-span" style="font-style: italic;"> }</span></div><div><span class="Apple-style-span" style="font-style: italic;"> control.activate();</span></div><div><span class="Apple-style-span" style="font-style: italic;"> };</span></div>
<div><br></div>declare panels like</div><div><span class="Apple-style-span" style="font-style: italic;">panel = new OpenLayers.Control.Panel({div: document.getElementById("mapToolBox2"), activateControl:multiPanelActivateControl});</span></div>
<div><span class="Apple-style-span" style="font-style: italic;"><br></span><div class="gmail_quote">On Mon, Apr 13, 2009 at 7:17 PM, Josh Rosenthal <span dir="ltr"><<a href="mailto:maric423@gmail.com">maric423@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Hi All,<div><br></div><div>I'm running into a bit of a snag and am hoping someone can offer some advice. I'm trying to build a map with multiple control panels, ie: Basic Navigation, Querying (draw a shape, generate a query based off the shape) etc. For the most part its going quite well, but I'm running into a problem where I activate a control in one panel, click on a button in another panel, and the original controls remain active and both try to run... in other words, I'll turn on an Info control, and then switch to DrawPoint, and it'll be trying to do both. Controls deactivate other controls within their own panel when clicked, but don't seem to know to deactivate the other panel's controls.</div>
<div><br></div><div>Is there a straightforward way to do this? Thus far, the best idea I've come up with (shown below) is setting a listener for each control when it activates, such that it runs through everything in the other panel.controls, and deactivates them all. This strikes me as painfully awkward, and gets extremely annoying to scale if I choose to add a few more panels. Is there any way to make the panels aware of each other's existence such that they deactivate the controls appropriately (or can anyone suggest a better of implementing this)?</div>
<div><br></div><div>Thanks!</div><div><br></div><div>Josh</div><div><br></div><div><br></div><div>given two external panels, <span style="font-style:italic">panel</span> and <span style="font-style:italic">selPan2</span>, run the following at the end of initialization.</div>
<div><br></div><div><span style="font-style:italic"><div><div>for (eachControl in panel.controls) {</div><div> panel.controls[eachControl].events.register("activate",selPan2.controls,function () {</div>
<div> for (otherControls in this) {</div><div> this[otherControls].deactivate();</div><div> }</div><div> });</div><div>}</div><div><br></div><div>for (eachControl in selPan2.controls) {</div><div>
selPan2.controls[eachControl].events.register("activate",panel.controls,function () {</div><div> for (otherControls in this) {</div><div> this[otherControls].deactivate();</div><div> }</div>
<div> });</div><div>}</div><div><br></div></div></span></div>
</blockquote></div><br></div>