Select to view content in your preferred language

Problem with ArcGISDynamicMapServiceLayer.visibleLayers in Flex 3.0

1999
2
Jump to solution
06-27-2012 04:36 PM
GerardoArmendariz
Deactivated User
After upgrading to ArcGIS for Flex 3.0, I am getting the following error:

1118: Implicit coercion of a value with static type mx.collections:IList to a possibly unrelated type mx.collections:ArrayCollection.


I am getting this because of a change to the visibleLayers type in 3.0:

 public function showLayer(layerInfo:LayerInfo):void             {                 var visibleLayers:ArrayCollection;                 if (layer is ArcGISDynamicMapServiceLayer)                 {                     visibleLayers = ArcGISDynamicMapServiceLayer(layer).visibleLayers;                     visibleLayers.addItem(layerInfo.layerId); // add id                 }


Has anyone found a solution to this?  I could not find any in the forum.
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus
Rie,

   Sure in the 3.0 API the value of
ArcGISDynamicMapServiceLayer(layer).visibleLayers;
could be null now it does not automatically return the default visibility of the layer as it did in previous version so you need to check if it is null first. If it is null then you need to build an array collection with the layers default visibility like this:

            private function buildVisibleLayers(value:Array):ArrayCollection             {                 var ac:ArrayCollection = new ArrayCollection();                 var li:LayerInfo                 for each( li in value){                     if(li.defaultVisibility)                         ac.addItem(li.layerId);                 }                 return ac;             }


So untimately it would look something like this:

                    if(!ArcGISDynamicMapServiceLayer(layer).visibleLayers){                         visibleLayers = buildVisibleLayers(ArcGISDynamicMapServiceLayer(layer).layerInfos);                     }else{                         visibleLayers = ArcGISDynamicMapServiceLayer(layer).visibleLayers as ArrayCollection;                     }


Don't forget to click the Mark as answer check on this post and to click the top arrow (promote).
Follow the steps as shown in the below graphic:

View solution in original post

0 Kudos
2 Replies
RobertScheitlin__GISP
MVP Emeritus
Rie,

   Sure in the 3.0 API the value of
ArcGISDynamicMapServiceLayer(layer).visibleLayers;
could be null now it does not automatically return the default visibility of the layer as it did in previous version so you need to check if it is null first. If it is null then you need to build an array collection with the layers default visibility like this:

            private function buildVisibleLayers(value:Array):ArrayCollection             {                 var ac:ArrayCollection = new ArrayCollection();                 var li:LayerInfo                 for each( li in value){                     if(li.defaultVisibility)                         ac.addItem(li.layerId);                 }                 return ac;             }


So untimately it would look something like this:

                    if(!ArcGISDynamicMapServiceLayer(layer).visibleLayers){                         visibleLayers = buildVisibleLayers(ArcGISDynamicMapServiceLayer(layer).layerInfos);                     }else{                         visibleLayers = ArcGISDynamicMapServiceLayer(layer).visibleLayers as ArrayCollection;                     }


Don't forget to click the Mark as answer check on this post and to click the top arrow (promote).
Follow the steps as shown in the below graphic:

0 Kudos
GerardoArmendariz
Deactivated User
Thanks for your help.
0 Kudos