Hi,
I am trying to add some functionality to the TOC widget so that users can save which layers they have turned on and reload those settings later. I have had some success but have come up against a problem that I think others have experienced, but I cannot find an answer on the forum and the posts I've seen are quite old.
I seem to be able to save the layer visibility. However, when I come to load this back in I am struggling with group layers.
For example, if I save the layers below:
Attachment 29970
It reloads like this:
Attachment 29971
The "pointsInAGroup" features within "aGroup" are actually visible in the map but this is not reflected in the TOC.
Is it possible to force the checkboxes to update correctly?
My two functions that save/load the layer visibility are:
I am trying to add some functionality to the TOC widget so that users can save which layers they have turned on and reload those settings later. I have had some success but have come up against a problem that I think others have experienced, but I cannot find an answer on the forum and the posts I've seen are quite old.
I seem to be able to save the layer visibility. However, when I come to load this back in I am struggling with group layers.
For example, if I save the layers below:
Attachment 29970
It reloads like this:
Attachment 29971
The "pointsInAGroup" features within "aGroup" are actually visible in the map but this is not reflected in the TOC.
Is it possible to force the checkboxes to update correctly?
My two functions that save/load the layer visibility are:
Code:
private function saveLayers():void
{
visLayersSO = SharedObject.getLocal("SavedPrefs");
visLayers = new ArrayCollection();
MapUtil.forEachMapLayer(map, function(layer:Layer):void
{
var visLayersList:IList;
if (layer is ArcGISDynamicMapServiceLayer)
{
visLayersList = ArcGISDynamicMapServiceLayer(layer).visibleLayers
var visLayersObj:Object =
{
name: layer.name,
visible: layer.visible,
vislist: visLayersList
}
visLayers.addItem(visLayersObj);
}
});
visLayersSO.data[VISLAYERS] = visLayers;
visLayersSO.flush();
if (visLayersSO.size > 0)
{
Alert.show("Your layers have been saved.")
}
}
private function loadLayers():void
{
visLayersSO = SharedObject.getLocal("SavedPrefs");
if (visLayersSO.size > 0)
{
var visLayers:ArrayCollection = visLayersSO.data[VISLAYERS];
MapUtil.forEachMapLayer(map, function(layer:Layer):void
{
var LayId:int = 0;
for(var i:int=0; i<visLayers.length;i++)
{
if(visLayers[i].name == layer.name)
{
LayId = i;
break;
}
}
if (layer is ArcGISDynamicMapServiceLayer)
{
layer.visible = visLayers[LayId].visible;
ArcGISDynamicMapServiceLayer(layer).visibleLayers = visLayers[LayId].vislist;
}
});
}
}