[Users] Setting map layer radio button via JS

David E. Reksten der at dod.no
Thu Dec 9 10:39:32 CET 2010


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


More information about the Users mailing list