public function hideLayer(name:String,service:ArcGISDynamicMapServiceLayer):void
{
var Arr:Array = service.layerInfos;
for each (var layerInfo:LayerInfo in Arr){
var idIndex:int = service.visibleLayers.getItemIndex(layerInfo.id);
if(layerInfo.name == name)
service.visibleLayers.removeItemAt(idIndex);
}
}
It's right because if you want to hide a layer you must set the visibile = false to the item in the livemapwidget. you must use the TOC object and navigate the list of layer in the service. I've made so and it works.
SiteContainer.dispatchEvent(new AppEvent(AppEvent.PROGRAMATIC_LAYER_VISIBILITY_CHANGED, false, false, "Major Roads"));
private function tuc():void
{
for each(var layerID:Number in (map.layers[0] as ArcGISDynamicMapServiceLayer).visibleLayers)
{
SiteContainer.dispatchEvent(new AppEvent(AppEvent.LAYER_VISIBILITY_CHANGED, false, true, layerID));
}
}
public function TocItem( parentItem:TocItem = null )
{
_parent = parentItem;
SiteContainer.addEventListener(AppEvent.PROGRAMATIC_LAYER_VISIBILITY_CHANGED, updateCB);
}
private function updateCB(event:AppEvent):void
{
if(this is TocLayerInfoItem)
{
var tli:TocLayerInfoItem = this as TocLayerInfoItem;
if(tli.layerInfo.name == event.data){
setVisible(_visible ? false : true, true);
}
}
}/** * event added by me to listen for a layer being turn off or on in the map * event for when a layers visibility has changed programaticly */ public static const PROGRAMATIC_LAYER_VISIBILITY_CHANGED:String = "programicLayerVisibilityChanged";
private function test1(evt:Event):void
{
SiteContainer.dispatchEvent(new AppEvent(AppEvent.PROGRAMATIC_LAYER_VISIBILITY_CHANGED, false, false, "Major Roads"));
}
public function TocItem(parentItem:TocItem = null)
{
_parent = parentItem;
ViewerContainer.addEventListener(AppEvent.PROGRAMATIC_LAYER_VISIBILITY_CHANGED, updateCheckBox);
}
private function updateCheckBox(event:AppEvent):void
{
if(this is TocLayerInfoItem)
{
var tli:TocLayerInfoItem = this as TocLayerInfoItem;
if(tli.layerInfo.id == event.data){
setVisible(_visible ? false : true, true);
}
}
}private function updateMapSwitcher(newVisibility:Array):void
{
for each (var id:String in newVisibility)
{
// sends event to MapSwitcher widget to turn subLayer on
ViewerContainer.dispatchEvent(new AppEvent(AppEvent.PROGRAMATIC_LAYER_VISIBILITY_CHANGED, id));
}
}