Select to view content in your preferred language

SFV: Chart Widget - Make Layer Visible when widget is activated.

1458
9
05-05-2010 01:55 PM
RichWestfall
Emerging Contributor
Hello,

I am using the chart widget to serve up census information.  I have the census block layer accessible to the SFV.  I would like the census block layer to be visible when the chart widget is activated.  When the chart widget is closed or minimized I would like the census block layer invisible. 

Has anyone attempted something similiar?  Any help would be appreciated.

Rich
Tags (2)
0 Kudos
9 Replies
RobertScheitlin__GISP
MVP Emeritus
richwestfall,

   If the census block layer is in the map the you can just do something like

map.getLayer(yourName).visible = true;
0 Kudos
RichWestfall
Emerging Contributor
Robert,

I appreciate the help.  I have tried entering the code in the chart widget in the openhandler/closedhandler to no avail.  Is there another section I should try this in?

Thanks for your help.

Rich
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Rich,

   Is the layer that you are trying to make visible a sublayer of a map service? If so that requires some more code.
0 Kudos
RichWestfall
Emerging Contributor
Robert,

Yes it is a grouped layer in a large service.  Attached is a pdf showing the location.  It is layer id 48. 

Rich
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Rich,

   Here is two function to use one for hiding the sublayer one for showing

private hideSubLayer(layer:Layer,id:int):void
   {
    var visibleLayers:ArrayCollection;
    if (layer is ArcGISDynamicMapServiceLayer)
    {
     visibleLayers = ArcGISDynamicMapServiceLayer(layer).visibleLayers;
     var idIndex:int = visibleLayers.getItemIndex(id);
     if (idIndex != -1)
     {
      visibleLayers.removeItemAt(idIndex);
     }
    }
   }
   
   private showSubLayer(layer:Layer,id:int):void
   {
    var visibleLayers:ArrayCollection;
    if (layer is ArcGISDynamicMapServiceLayer)
    {
     visibleLayers = ArcGISDynamicMapServiceLayer(layer).visibleLayers;
     visibleLayers.addItem(id);
    }
   }
0 Kudos
RichWestfall
Emerging Contributor
Robert,

Thank you for this.  I have been working with it but I'm unsure where to put the sublayer information the function is refering too. All avenues I have tried will either not get the function to work or not compile. 

Rich
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Rich,

   Hmm. Have you tried something like

showSubLayer(map.getLayer("Planning"),48);
0 Kudos
RichWestfall
Emerging Contributor
Robert,

Yes I have tried that and the error is need rightpar before dot.  I have also tried the following attached code and don't get and error message it just hangs flex builder and will not compile the chart widget. 

Rich

private function hideSubLayer (map.getLayer("Planning"),48):void
   {
    var visibleLayers:ArrayCollection;
    if (layer is ArcGISDynamicMapServiceLayer)
    {
     visibleLayers = ArcGISDynamicMapServiceLayer(layer).visibleLayers;
     var idIndex:int = visibleLayers.getItemIndex(id);
     if (idIndex != -1)
     {
      visibleLayers.removeItemAt(idIndex);
     }
    }
   }
   
   private function showSubLayer (map.getLayer("Planning"),48):void
   {
    var visibleLayers:ArrayCollection;
    if (layer is ArcGISDynamicMapServiceLayer)
    {
     visibleLayers = ArcGISDynamicMapServiceLayer(layer).visibleLayers;
     visibleLayers.addItem(id);
    }
   }  
0 Kudos
MichaelHoff
Deactivated User
richwestfall,

   If the census block layer is in the map the you can just do something like

map.getLayer(yourName).visible = true;


With the chart widget, where would I put this in the mxml? I have tried under the widgetOpenHandler but had no success.
0 Kudos