Select to view content in your preferred language

Can't turn features layers on/off - Why?

834
3
04-25-2011 05:22 AM
WaltBulawa
Emerging Contributor
I have a service with 14 layers.  I would like to be able to selectively turn them on or off.  I'm trying to do this via setting the value of the defaultVisibility variable for the layers but it seems to have no effect.  What do I need to do?  Your help would be very much appreciated.  Here's the code:

<fx:Script>
        <![CDATA[
   import com.esri.ags.Map;
   import com.esri.ags.events.LayerEvent;
   import com.esri.ags.layers.ArcGISDynamicMapServiceLayer;
   import com.esri.ags.layers.Layer;
   import com.esri.ags.layers.supportClasses.LayerInfo;
   import com.esri.viewer.ViewerContainer;
  
   import mx.rpc.soap.LoadEvent;
  
   import spark.events.IndexChangeEvent;
  
   private var myLayer:Layer;
   private var myLayerInfosArray:Array;
  
            private function init():void
            {
                myLayer = new ArcGISDynamicMapServiceLayer("http://gis.idaho.gov/ArcGIS/rest/services/IdahoParcels6/MapServer");    
    myLayer.addEventListener(LayerEvent.LOAD,getLayerInfos);
    map.addLayer(myLayer);
            }
  
   private function getLayerInfos(event:LayerEvent):void
   {
    var thisLayer:ArcGISDynamicMapServiceLayer = event.layer as ArcGISDynamicMapServiceLayer;
    myLayerInfosArray = thisLayer.layerInfos;

    myLayerInfosArray[0].defaultVisibility = true;
    myLayerInfosArray[1].defaultVisibility = false;//turn off default visible layer
    myLayerInfosArray[2].defaultVisibility = true;
    myLayerInfosArray[3].defaultVisibility = true;
    map.addLayer(myLayer);
    myLayer.visible=true;
    //myLayer.refresh();
   }
        ]]>
    </fx:Script>
Tags (2)
0 Kudos
3 Replies
RobertScheitlin__GISP
MVP Emeritus
Walt,

   You turn layers on and off using the visibleLayers property.

http://help.arcgis.com/en/webapi/flex/apiref/com/esri/ags/layers/ArcGISDynamicMapServiceLayer.html
0 Kudos
WaltBulawa
Emerging Contributor
I need to do this in the scripting environment (not xml).

Would you know why the myLayer variable (in the code above) does not offer a "visibleLayers" property while the thisLayer variable does have a "visibleLayers" property even though both were defined as ArcGISDynamicMapServiceLayer type variables?
0 Kudos
WaltBulawa
Emerging Contributor
I need to do this in the scripting environment (not xml).

Would you know why the myLayer variable (in the code above) does not offer a "visibleLayers" property while the thisLayer variable does have a "visibleLayers" property even though both were defined as ArcGISDynamicMapServiceLayer type variables?


Never mind - one was originally defined as an ArcGISDynamicServiceLayer while the other was defined originally as a Layer.  Apparently this makes a lot of difference.
0 Kudos