Hello everyone:<div><br></div><div>After several days of effort spending on reading the documents about related JavaScript framework (GeoExt, ExtJS, OpenLayers) and on examination of the source code a little bit, the solution to the question of turning on/off radio buttons of map layer tree nodes programmatically turns out to be quite straight forward and easy, although it may be not so consistent with the framework api because it needs to know the implementation details of GeoExt.plugins.TreeNodeRadioButton a little bit.</div>
<div><br></div><div>Francois's code to turn on/off the checkbox do the work exactly and I follow her? good example to present my code:</div><div><br></div><div>if (layerTreeRoot.childNodes[i].attributes.radio) {</div>
<div> layerTreeRoot.childNodes[i].attributes.radio.checked = true</div><div> // or</div><div> layerTreeRoot.childNodes[i].attributes.radio.checked = false</div><div>}</div><div><br></div><div>That's it. If anyone want further explanation, she can read on and I will say a little bit more about the code.</div>
<div><br></div><div>The folks in GeoExt do an excellent work. They use GeoExt.plugins.TreeNodeRadioButton to add the additional UI component to an Ext.tree.TreeNodeUI, and they follow the ExtJS convention to put this custom added UI component, an HTMLInputElement of type "radio" into Ext.tree.TreeNode.attributes property, so I can access it easily and follow the common JavaScript code techniques to turn on/off it by setting the checked property to true or false.</div>
<div><br></div><div>Maybe this method depends on the implementation of GeoExt.plugins.TreeNodeRadioButton, which is not a good practice. I wish they could, in the future, provide some API method, just like what ExtJS does with an Ext.tree.TreeNodeUI.toggleCheck() method, say Ext.tree.TreeNodeUI.toggleRadioCheck()? I know it requires adding some dynamic method to an existing object, which I am not sure if it is a good practice or even possible. That is just my idea.</div>
<div><br></div><div>Again, thanks everyone.</div><div><br></div><div>Chamme<br><br><div class="gmail_quote">2013/3/20 <span dir="ltr"><<a href="mailto:Steve.Toutant@inspq.qc.ca" target="_blank">Steve.Toutant@inspq.qc.ca</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br><font face="sans-serif">Set the layer visibility to false will
also uncheck the node. </font>
<br><font face="sans-serif">Perhaps it depends on how you built
your tree...</font>
<p>
<br>
<br>
<br>
</p><p></p><table width="100%">
<tbody><tr valign="top">
<td width="40%"><font size="1" face="sans-serif"><b>"Valiquette,Francois
[Montreal]" <<a href="mailto:Francois.Valiquette@ec.gc.ca" target="_blank">Francois.Valiquette@ec.gc.ca</a>>@<a href="http://geoext.org" target="_blank">geoext.org</a></b> </font>
<br><font size="1" face="sans-serif">Envoyé par : <a href="mailto:users-bounces@geoext.org" target="_blank">users-bounces@geoext.org</a></font>
<p><font size="1" face="sans-serif">2013-03-20 09:21</font>
</p></td><td width="59%">
<table width="100%">
<tbody><tr valign="top">
<td>
<div align="right"><font size="1" face="sans-serif">A</font></div>
</td><td><font size="1" face="sans-serif"><<a href="mailto:chamme.chane@gmail.com" target="_blank">chamme.chane@gmail.com</a>>, <<a href="mailto:users@geoext.org" target="_blank">users@geoext.org</a>></font>
</td></tr><tr valign="top">
<td>
<div align="right"><font size="1" face="sans-serif">cc</font></div>
</td><td>
</td></tr><tr valign="top">
<td>
<div align="right"><font size="1" face="sans-serif">Objet</font></div>
</td><td><font size="1" face="sans-serif">Re: [Users] How to turn on/off a radio
button in a layer tree nodeprogrammatically?</font></td></tr></tbody></table>
<br>
<table>
<tbody><tr valign="top">
<td>
</td><td></td></tr></tbody></table>
<br></td></tr></tbody></table><div><div class="h5">
<br>
<br>
<br>
<br>
<br><font size="3" color="#1f497d" face="Calibri">Hello,</font>
<br><font size="3" color="#1f497d" face="Calibri"> </font>
<br><font size="3" color="#1f497d" face="Calibri">To check or uncheck the node
“i” of your tree you can use something similar to this :</font>
<br><font size="3" color="#1f497d" face="Calibri"> </font>
<br><font size="3" color="#1f497d" face="Calibri">layerTreeRoot.childNodes[i].ui.toggleCheck(false)</font>
<br><font size="3" color="#1f497d" face="Calibri">or </font>
<br><font size="3" color="#1f497d" face="Calibri">layerTreeRoot.childNodes[i].ui.toggleCheck(true)</font>
<br><font size="3" color="#1f497d" face="Calibri"> </font>
<br><font size="3" color="#1f497d" face="Calibri">And for the radio button
I don’t know but I think it should be something similar.</font>
<br><font size="3" color="#1f497d" face="Calibri"> </font>
<br><font size="3" color="#1f497d" face="Calibri">Good luck</font>
<br><font size="3" color="#1f497d" face="Calibri"> </font>
<br><font size="3" color="#1f497d" face="Calibri">François</font>
<br><font size="3" color="#1f497d" face="Calibri"> </font>
<br><font size="3" color="#1f497d" face="Calibri"> </font>
<br><font size="3" face="Tahoma"><b>De :</b> <a href="mailto:users-bounces@geoext.org" target="_blank">users-bounces@geoext.org</a> [mailto:<a href="mailto:users-bounces@geoext.org" target="_blank">users-bounces@geoext.org</a>]
<b>De la part de</b> ??<b><br>
Envoyé :</b> 20 mars 2013 02:26<b><br>
À :</b> <a href="mailto:users@geoext.org" target="_blank">users@geoext.org</a><b><br>
Objet :</b> [Users] How to turn on/off a radio button in a layer tree nodeprogrammatically?</font>
<br><font size="3" face="Times New Roman"> </font>
<br><font size="3" face="Times New Roman">Hello everyone:</font>
<br><font size="3" face="Times New Roman"> </font>
<br><font size="3" face="Times New Roman">I am learning GeoExt and trying
the example "Tree Node", the url of the example is "</font><a href="http://api.geoext.org/1.1/examples/tree.html" target="_blank"><font size="3" color="blue" face="Times New Roman"><u>http://api.geoext.org/1.1/examples/tree.html</u></font></a><font size="3" face="Times New Roman">".</font>
<br><font size="3" face="Times New Roman"> </font>
<br><font size="3" face="Times New Roman">In the example, the "Overlays"
subtree hosted in the Layers panel contains 3 layer nodes each with a check
box and a radio button, users can click on one of radio buttons to activate
a layer, and through checking on/off check boxes, we can turn on/off the
display of a layer. These functions are excellent.</font>
<br><font size="3" face="Times New Roman"> </font>
<br><font size="3" face="Times New Roman">Now the question is, I want to
turn on/off a radio button in the treenode programmatically, also check
on/off check boxs programmatically. Could anyone provide me some hints
to achieve the goal? Do I need to examine some source code of the library?</font>
<br><font size="3" face="Times New Roman"> </font>
<br><font size="3" face="Times New Roman">Thanks,</font>
<br></div></div><font size="3" face="Times New Roman">Chamme</font><tt><font>_______________________________________________<br>
Users mailing list<br>
<a href="mailto:Users@geoext.org" target="_blank">Users@geoext.org</a><br>
<a href="http://www.geoext.org/cgi-bin/mailman/listinfo/users" target="_blank">http://www.geoext.org/cgi-bin/mailman/listinfo/users</a><br>
</font></tt>
<br>
<br>
<br><p></p></blockquote></div><br></div>