Select to view content in your preferred language

Legend Doesn't Auto Update Visible Layers

1635
7
Jump to solution
01-25-2012 07:41 AM
JHayes
by
Frequent Contributor
Hello,

I'm creating an application using the button bar categories to reveal layers.  I'm in the testing phase right now so I'm using feature server and map server services.  I have the default visibility set to 'false' for all the layers.  When a user selects a category in the button bar it reveals a list of check boxes to activate layers on the map. Only when you check the box the layer appears on the map but not in the legend until the scale is changed.  How can I get the legend to show the layer immediately?  The funny thing is, this doesn't happen with the feature server services, only the map server services.

Here's a code sample to the services:
<esri:ArcGISDynamicMapServiceLayer id="sidewalkMapServer"     name=" "     visible="false"     url="http://......DOE_Sidewalk/MapServer"/>    <esri:FeatureLayer id="sidewalkComments"  mode="snapshot"  visible="false"  url="http://......SidewalkComment/FeatureServer/0"/>


Here's the code to the check box buttons:
public function sintBox(evt:MouseEvent):void    {      sidewalkMapServer.visible = true;          if(CheckBox(evt.target).selected)      {            }      else      {      sidewalkMapServer.visible = false;      }    }  public function scomBox(evt:MouseEvent):void    {      sidewalkComments.visible = true;          if(CheckBox(evt.target).selected)      {            }      else      {      sidewalkComments.visible = false;      }


Any help on this would be great.  I have a feeling it has something to do with 'LayerInfo' but I'm not sure on how to use it.

Joe
GIS Tech II
Long Range Planning
Washington County, Oregon
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
JHayes
by
Frequent Contributor
Nicki,

I had ESRI tech support check it out - it's been logged as a bug.  Hopefully they'll fix it soon.

For now the tech said to use the work-around we found the other day.  Not sure how you're handling the change events for the radio button, but adding "myMap.zoom(1);" method to your ActionScript updates the legend because it refreshes the map.

The tech also showed me how to turn my layers on/off with data binding rather than an event handler.  Instead of setting the dynamic layers visibility to ???false??? and use an eventHandler to turn it back on, she suggested I use do this to the services visibility property: set the dynamic service's
visibility=???{theCheckBoxName.selected}??? and set the default selection on the check boxes to ???false??? - Worked like a charm!!  Should work for the radio button.  Let me know.

Joe

View solution in original post

0 Kudos
7 Replies
nicolalodge
Emerging Contributor
Hi

we are having a simliar issue here. We have a control to allow users to select a single layer using radio buttons. The radiobuttons update on the fly if users select a different map service. The map service is selected by dropdown boxes.

The map updates fine but the legend does not change when the layer in the map changes (it only shows the legend for the first later in the first service).

Any advice would be appreciated.

Nicki
0 Kudos
JHayes
by
Frequent Contributor
Nicki,

Sorry to hear that your having the same problem, but also happy to know the issue isn't isolated to my case.

I'm haven't looked into in ain a few days but will continue this week.

I'll let you know when I get the answer.

Joe
0 Kudos
JHayes
by
Frequent Contributor
Nicki,

I had ESRI tech support check it out - it's been logged as a bug.  Hopefully they'll fix it soon.

For now the tech said to use the work-around we found the other day.  Not sure how you're handling the change events for the radio button, but adding "myMap.zoom(1);" method to your ActionScript updates the legend because it refreshes the map.

The tech also showed me how to turn my layers on/off with data binding rather than an event handler.  Instead of setting the dynamic layers visibility to ???false??? and use an eventHandler to turn it back on, she suggested I use do this to the services visibility property: set the dynamic service's
visibility=???{theCheckBoxName.selected}??? and set the default selection on the check boxes to ???false??? - Worked like a charm!!  Should work for the radio button.  Let me know.

Joe
0 Kudos
JHayes
by
Frequent Contributor
Oh and if this works, hook me up with the up-arrow thing.  It'll be my first points ever! 😄
0 Kudos
JHayes
by
Frequent Contributor
Guess I could just post the code.

Map Service Code:
<esri:ArcGISDynamicMapServiceLayer id="opsMapServer"
                                   name=" "
                                   visible="{opsCheckBox.selected}"
                                   url="http://........../>


Check Box Code:
  <s:CheckBox id="opsCheckBox"  
              label="Watershed Enhancement"
              fontSize="14"
              selected="false"
              click="CheckBox_clickHandler(event)"/>


And the update legend work-around click handler event for the check boxes:
protected function CheckBox_clickHandler(event:MouseEvent):void
            {
                myMap.zoom(1);
            }


Just make sure if something is housing your check box's/radioButtons is creating  everything upon the initialization of the application.  In my case it's a  button Bar with a viewStack as the datProvider.

Code to that:
<mx:ViewStack id="myViewStack" width="330" height="72" creationPolicy="all">
0 Kudos
nicolalodge
Emerging Contributor
Hi Robert

Thanks for this.

I have been meaning to post but its all been a bit chaos! My issue was a bit different as my legend wasn't changing at all when the radio button was changed.

I got around the issue by adding in the legend perameters to the function which loads the layers in to the radio button, rather than in the mxml and this seemed to work

Actionscript code


public function loadLayerName():void
    
   {
    radioSelect.removeAllChildren();
    //myLayerId = null;
    //loop through each layer and add as a radiobutton
    
    for(var i:uint = 0; i < (statsLayer.layerInfos.length); i++) 
    {
     var radioBtn:RadioButton = new RadioButton;
     radioBtn.groupName = "radioBtnGroup";
     radioBtn.value = i;
     radioBtn.label = statsLayer.layerInfos.name;
     radioSelect.addChild(radioBtn);
     
    }
    
    //set the visible layer the first radio button
    
    radioBtnGroup.selectedValue = null;
    statsLayer.visibleLayers = new ArrayCollection();
    
    
    //refresh the legend
    map1StatsLegend.layers = [statsLayer, contextLayer];
    map1StatsLegend.map = Map1;
    //myLayerId += radioBtnGroup.selectedValue;
   }



Mxml for legend:


<esri:Legend 
     id ="map1StatsLegend" 
     x= "470" y = "57"
     respectCurrentMapScale="true"/>



Ill do the arrow thing for you when i work out how the forum works-  its all a bit new to me!!

Thanks again

Nicki
0 Kudos
MohammedIsmail
Emerging Contributor
hi

i dont know weather your problem has been solved or not

you can use the "Updatecomplete="true"" option to update your legend


Thanks
ismail
0 Kudos