[Users] How to turn on/off a radio button in a layer tree nodeprogrammatically?
程铖
chamme.chane at gmail.com
Wed Mar 27 17:44:38 CET 2013
Hello everyone:
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.
Francois's code to turn on/off the checkbox do the work exactly and I
follow her? good example to present my code:
if (layerTreeRoot.childNodes[i].attributes.radio) {
layerTreeRoot.childNodes[i].attributes.radio.checked = true
// or
layerTreeRoot.childNodes[i].attributes.radio.checked = false
}
That's it. If anyone want further explanation, she can read on and I will
say a little bit more about the code.
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.
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.
Again, thanks everyone.
Chamme
2013/3/20 <Steve.Toutant at inspq.qc.ca>
>
> Set the layer visibility to false will also uncheck the node.
> Perhaps it depends on how you built your tree...
>
>
>
>
> *"Valiquette,Francois [Montreal]" <Francois.Valiquette at ec.gc.ca>@
> geoext.org*
> Envoyé par : users-bounces at geoext.org
>
> 2013-03-20 09:21
> A
> <chamme.chane at gmail.com>, <users at geoext.org>
> cc
> Objet
> Re: [Users] How to turn on/off a radio button in a layer tree
> nodeprogrammatically?
>
>
>
>
>
>
> Hello,
>
> To check or uncheck the node “i” of your tree you can use something
> similar to this :
>
> layerTreeRoot.childNodes[i].ui.toggleCheck(false)
> or
> layerTreeRoot.childNodes[i].ui.toggleCheck(true)
>
> And for the radio button I don’t know but I think it should be something
> similar.
>
> Good luck
>
> François
>
>
> *De :* users-bounces at geoext.org [mailto:users-bounces at geoext.org] *De la
> part de* ??*
> Envoyé :* 20 mars 2013 02:26*
> À :* users at geoext.org*
> Objet :* [Users] How to turn on/off a radio button in a layer tree
> nodeprogrammatically?
>
> Hello everyone:
>
> I am learning GeoExt and trying the example "Tree Node", the url of the
> example is "*http://api.geoext.org/1.1/examples/tree.html*<http://api.geoext.org/1.1/examples/tree.html>
> ".
>
> 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.
>
> 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?
>
> Thanks,
> Chamme_______________________________________________
> Users mailing list
> Users at geoext.org
> http://www.geoext.org/cgi-bin/mailman/listinfo/users
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.geoext.org/pipermail/users/attachments/20130328/c38e1882/attachment.htm
More information about the Users
mailing list