map.getLayer("USA Daytime Population").visible=ture
Faizan,
No getLayer is not for individual layers only the whole map service to enable visibility on a particular layer in the map service you would use visibleLayers array Collection. Look at the documentation for a layer like ArcGISDynamicMapService and you will see visible layers property and some examples of how to use it.
Faizan,
Yes the visibleLayers array collection will never list the id of a group layer but you can add that id to turn on the group.
var visLayers:ArrayCollection = dmsl.visibleLayers; var newVisLayer:ArrayCollection=new ArrayCollection(obj.visLyrs.visibleLayer); for each(var j:int in newVisLayer){ AppEvent.dispatch(AppEvent.LAYER_VISIBILITY_CHANGED,j); }
public function TocItem( parentItem:TocItem = null ) { _parent = parentItem; //ViewerContainer.addEventListener(AppEvent.LAYER_VISIBILITY_CHANGED, updateCB); AppEvent.addListener(AppEvent.LAYER_VISIBILITY_CHANGED,updateCB); } private function updateCB(event:AppEvent):void { if(this is TocLayerInfoItem) { var tli:TocLayerInfoItem = this as TocLayerInfoItem; if(tli.layerInfo.id == event.data){ setVisibleDirect(_visible ? false : true); } }
I got some code from another thread which helped in enabling the toc based upon visibilty of the layer. It works great for child layers in a map service layer but doesnt work for the group layers containing further sub layers.
The result i get is that the unexpectedly all sublayers under the group layer become visible yet the tick boxes for those layers remain unchecked (which is fine), however i am not sure why the sublayers become visible for example
If i have a group layer
Infrastructure
----buildings
----structures
----roads
and i use the code below to only put tick boxes for the group layer called Infrastructure and buildings, it does work and only those checkboxes are ticked but i also get structures and roads visible on the map yet their checkboxes are unticked.var visLayers:ArrayCollection = dmsl.visibleLayers; var newVisLayer:ArrayCollection=new ArrayCollection(obj.visLyrs.visibleLayer); for each(var j:int in newVisLayer){ AppEvent.dispatch(AppEvent.LAYER_VISIBILITY_CHANGED,j); }
In toc Item i havepublic function TocItem( parentItem:TocItem = null ) { _parent = parentItem; //ViewerContainer.addEventListener(AppEvent.LAYER_VISIBILITY_CHANGED, updateCB); AppEvent.addListener(AppEvent.LAYER_VISIBILITY_CHANGED,updateCB); } private function updateCB(event:AppEvent):void { if(this is TocLayerInfoItem) { var tli:TocLayerInfoItem = this as TocLayerInfoItem; if(tli.layerInfo.id == event.data){ setVisibleDirect(_visible ? false : true); } }
Try evt.stopPropagation();