[Users] Setting map layer radio button via JS
Pierre Giraud
pierre.giraud at camptocamp.com
Fri Dec 10 15:44:17 CET 2010
node.getUI().checkbox.nextElementSibling.setValue(1);
could probably be replaced by
Ext.get(node.attributes.radio).setValue(1);
Other than that, your solution is fine.
On Fri, Dec 10, 2010 at 3:04 PM, David E. Reksten <der at dod.no> wrote:
> Nice! Thanks a lot for your answer.
>
> I was also able to accomplish the same with this hack:
>
> function setLayerRadioButton(layerID) {
> selNodes = treePanel.getChecked();
> Ext.each(selNodes, function(node){
> if (node.layer.id == layerID) {
> node.getUI().checkbox.nextElementSibling.setValue(1);
> // trigger the 'radiochange' event manually here...
> }
> });
>
> };
>
> Regards,
> David
>
> 2010/12/10 Pierre Giraud <pierre.giraud at camptocamp.com>:
> > Hi,
> >
> > I've just tried and I've succeeded in using the following piece of code :
> >
> > var node = treePanel.root.findChild('layer', newVectorLayer, true);
> > Ext.get(node.attributes.radio).set({
> > 'checked': 'checked'
> > });
> >
> > This won't fire the 'radiochange' event though. However, I think you can
> > execute the 'set active layer' code on your own at the same time.
> >
> > Please also consider using the new "GeoExt.plugins.TreeNodeRadioButton"
> > instead of the mixin. You may need a recent version of GeoExt though.
> >
> > Regards,
> > Pierre
> >
> > On Thu, Dec 9, 2010 at 10:39 AM, David E. Reksten <der at dod.no> wrote:
> >>
> >> I have layer tree in my application with both checkboxes (visibility)
> >> and radiobuttons ("active layer").
> >>
> >> Users may add new vector layers via a button, but for the moment they
> >> must always manually click the radio button after adding the layer to
> >> activate it. I would have preferred that a new layer was automatically
> >> checked, but I am unable to find out how to do it. Ideally, I would
> >> like to set the radio button at the same time as after having added
> >> the new layer to the map. I have googled extensively, but I suspect
> >> that I am using the wrong terminology here, as I have been unable to
> >> find out how to achieve this. Any hints would be very much
> >> appreciated!
> >>
> >> My tree panel is defined like this:
> >>
> >> treeConfig = [{
> >> nodeType: "gx_baselayercontainer",
> >> text: "Base layers",
> >> expanded: true
> >> }, {
> >> nodeType: "gx_overlaylayercontainer",
> >> text: "My overlays",
> >> expanded: true,
> >> loader: {
> >> baseAttrs: {
> >> radioGroup: "foo",
> >> uiProvider: "use_radio"
> >> }
> >> }
> >> }];
> >>
> >> treePanel = new Ext.tree.TreePanel({
> >> id: 'mainpanel',
> >> border: true,
> >> region: "west",
> >> title: "My layers",
> >> width: 200,
> >> split: true,
> >> collapsible: true,
> >> margins: '0 0 5 5',
> >> collapseMode: "mini",
> >> autoScroll: true,
> >> loader: new Ext.tree.TreeLoader({
> >> // applyLoader has to be set to false to not interfere with
> >> loaders
> >> // of nodes further down the tree hierarchy
> >> applyLoader: false,
> >> uiProviders: {
> >> "use_radio": Ext.extend(GeoExt.tree.LayerNodeUI, new
> >> GeoExt.tree.RadioButtonMixin());
> >> }
> >> }),
> >> root: {
> >> nodeType: "async",
> >> children: treeConfig
> >> },
> >> listeners: {
> >> "radiochange": function(node){
> >> // toggle active layer
> >> }
> >> },
> >> rootVisible: false,
> >> lines: false
> >> });
> >>
> >> After the user has clicked the button to add a layer:
> >> // ... newVectorLayer is defined here ...
> >> map.addLayer(newVectorLayer);
> >> // would now like to activate the radio button in the TreePanel
> >> for "newVectorLayer", so that the "radiochange" event is triggered:
> >> but how?
> >>
> >>
> >> Regards,
> >> David
> >> _______________________________________________
> >> Users mailing list
> >> Users at geoext.org
> >> http://www.geoext.org/cgi-bin/mailman/listinfo/users
> >
> >
> >
> > --
> > Pierre GIRAUD
> > Géomaticien, Analyste
> >
> > Camptocamp France SAS
> > Savoie Technolac, BP 352
> > 73377 Le Bourget du Lac, Cedex
> >
> > Tel : 00 33 4 79 44 44 93
> > Mail : pierre.giraud at camptocamp.com
> > http://www.camptocamp.com
> >
>
--
Pierre GIRAUD
Géomaticien, Analyste
Camptocamp France SAS
Savoie Technolac, BP 352
73377 Le Bourget du Lac, Cedex
Tel : 00 33 4 79 44 44 93
Mail : pierre.giraud at camptocamp.com
http://www.camptocamp.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.geoext.org/pipermail/users/attachments/20101210/53f08d5f/attachment.htm
More information about the Users
mailing list