Select to view content in your preferred language

Saving a session and Bookmarks

679
2
08-25-2010 05:44 AM
FrankTrevino
Emerging Contributor
Hi,

Not sure if this is possible or not, but I thought I would ask the question.

I know the Bookmark widget saves the extent, but can it also or is there a way to also save what layers were clicked on, so when a user clicks on a saved Bookmark it, not only does it zoom to the extent, but will also turn on the layers there were saved when the Bookmark was added. I want to be able to save the session, so a user can just click on it (the Bookmark) without having to turn on and off certain layers again and again.

Thanks.
Frank
Tags (2)
0 Kudos
2 Replies
KevinThomas
Emerging Contributor
Hi Frank,

I was wondering if you found a solution?  I'm trying to do the same thing.

thanks,
Kevin
0 Kudos
MattiasEkström
Frequent Contributor
I haven't done this, but I do save visible layers when user close the appliaction and load them when the user opens it again. The code I use for saving och loading visible layers might help you.

Saving visible layers to SharedObjects:
settingsSO = SharedObject.getLocal("HlsbgSettings");
    var map:Map = ViewerContainer.getInstance().mapManager.map
    acVisLayers = new ArrayCollection();
    
    MapUtil.forEachMapLayer(map, function(layer:Layer):void {
     var layVisAc:ArrayCollection;
     if (layer is ArcGISDynamicMapServiceLayer) {
      layVisAc = ArcGISDynamicMapServiceLayer(layer).visibleLayers;
     } else if (layer is ArcIMSMapServiceLayer) {
      layVisAc = ArcIMSMapServiceLayer(layer).visibleLayers;
     } else if (layer is ArcGISTiledMapServiceLayer) {
      layVisAc = ArcGISTiledMapServiceLayer(layer).visibleLayers;
     }
     var lvisObj:Object = {
      name: layer.name,
      visible: layer.visible,
      visarray: layVisAc
     }
     acVisLayers.addItem(lvisObj);
    });
    
    settingsSO.data[VISLAYERS] = acVisLayers;
settingsSO.flush();


visible layers from SharedObjects:
settingsSO = SharedObject.getLocal("HlsbgSettings");
    if (settingsSO.size > 0) {
     var acVisLayers:ArrayCollection = settingsSO.data.vislayers as ArrayCollection;
     if (acVisLayers.length > 0){
      
      MapUtil.forEachMapLayer(map, function(layer:Layer):void {
       var cLayId:int = 0;
       for(var i:Number=0; i < acVisLayers.length -1;i++)
       {
        if(acVisLayers.name == layer.name)
        {
         cLayId = i;
         break;
        }
       }       
       if (layer is ArcGISDynamicMapServiceLayer) {
        layer.visible = acVisLayers[cLayId].visible;
        ArcGISDynamicMapServiceLayer(layer).visibleLayers = acVisLayers[cLayId].visarray;
       } else if (layer is ArcIMSMapServiceLayer) {
        layer.visible = acVisLayers[cLayId].visible;
        ArcIMSMapServiceLayer(layer).visibleLayers = acVisLayers[cLayId].visarray;
       } else if (layer is ArcGISTiledMapServiceLayer) {
        layer.visible = acVisLayers[cLayId].visible;
       }
      });
     }
    }
   }


(The code is actually from something Robert Scheitlin wrote for SFV 1.3 that I've modified just a little bit to work in my SFV 2.1)
0 Kudos