Select to view content in your preferred language

Customize Map Switcher

849
7
12-22-2010 09:10 AM
RyanGillen
Deactivated User
I would like to add a basemap button in the mapswitcher that is only visible/enabled once the user is zoomed into a certain level. I cannot figure out how to get at the buttons in the button bar to disable the one I want. Has anyone attempted anything like this?
Tags (2)
0 Kudos
7 Replies
RobertScheitlin__GISP
MVP Emeritus
Ryan,

   Here is some code for disabling/enabling a specific butonbar button:

private function toggleButton(idx:uint, selected:Boolean):void {
                var b3:ButtonBarButton = buttonBar.getChildAt(idx) as ButtonBarButton;
                b3.enabled = selected;
            }
0 Kudos
RyanGillen
Deactivated User
Robert,

This is how I was attempting to modify the buttons, but I always get index out of bounds errors. The button I want to modify is the third one, however calling the function you posted giving it 2 as the parameter throws an error. I have 3 basemaps so it should be a valid index. Do I need to listen for a certain event before trying to call that function?
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Ryan,

   I am not sure where or when you are calling it but you do have to be sure the the buttonbars dataprovider is set before you try to disable a button.
0 Kudos
RyanGillen
Deactivated User
Well I tried putting the call to the function in the init function after reading the list of basemaps into the mapList variable, which is bound to the button bar as the data provider. I also tried putting the function call in the creationCompleteHandler and setTbbSelectedIndex functions, both give the same index out of bounds error. I want the button to be disabled inititally, then I will listen for the maps zoom level to change and if the zoom level is in far enough then I will set the button to enabled. I cant figure out where to call the function from so that the button is initially disabled.
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Ryan,

  You could try adding this to the end of the init function

this.callLater(yourDisablefunction);
0 Kudos
RyanGillen
Deactivated User
Thanks Robert, that worked out. I did have to change this line:

var b3:ButtonBarButton = tbb.getChildAt(idx) as ButtonBarButton;


To This:

var b3:ButtonBarButton = tbb.dataGroup.getElementAt(idx) as ButtonBarButton;
0 Kudos
RyanGillen
Deactivated User
It is still really flaky even after using the call later function you posted above. Sometimes it works sometimes it errors out trying to get the button from the datagroup. I must be missing something.
0 Kudos