Select to view content in your preferred language

Layer List Widget, is it possible to only allow one selected layer at a time?

3606
9
Jump to solution
01-19-2012 08:41 AM
MartynSmith
Emerging Contributor
I have transparencies set on my operational layers, and it can quickly become confusing when the user has multiple layers turned on.  Is it possible to only allow one selected layer?

Thanks
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus
Martyn,

  Sure just change this :

    private function onLayerShow(event:FlexEvent):void     {         //Turn all other ops layers off before we switch this one on         var opLayers:Array = ViewerContainer.getInstance().configData.opLayers;         for (var i:int = 0; i < opLayers.length; i++){             if(layer.id != opLayers.label)                 if(opLayers.label != "your point layer")                     ViewerContainer.getInstance().mapManager.map.getLayer(opLayers.label).visible = false;         }         setVisible(layer.visible, true);     }

View solution in original post

0 Kudos
9 Replies
RobertScheitlin__GISP
MVP Emeritus
Martyn,

   Sure here is the code for that, you are responsible for ensuring that initally only one Op layer is visible:

This change goes in the src/com/esri/viewer/components/toc/tocClasses/TocMapLayerItem.as

    private function onLayerShow(event:FlexEvent):void
    {
        //Turn all other ops layers off before we switch this one on
        var opLayers:Array = ViewerContainer.getInstance().configData.opLayers;
        for (var i:int = 0; i < opLayers.length; i++){
            if(layer.id != opLayers.label)
                ViewerContainer.getInstance().mapManager.map.getLayer(opLayers.label).visible = false;
        }
        setVisible(layer.visible, true);
    }


Don't forget to click the top arrow (promote) and to click the Mark as answer check as shown below:
0 Kudos
MartynSmith
Emerging Contributor
wow! perfect.  cheers again Robert
0 Kudos
MartynSmith
Emerging Contributor
Hmm.. is there any way to exclude a single layer from this new function?  I have one point layer I've excluded from the LayerList widget that I need to be always on (despite the only one layer function you just created), and sitting on top of all other layers.  I can add it to my basements, but then when I change visible layers with LayerListWidget, it goes below the newly activated layer
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Martyn,

  Sure just change this :

    private function onLayerShow(event:FlexEvent):void     {         //Turn all other ops layers off before we switch this one on         var opLayers:Array = ViewerContainer.getInstance().configData.opLayers;         for (var i:int = 0; i < opLayers.length; i++){             if(layer.id != opLayers.label)                 if(opLayers.label != "your point layer")                     ViewerContainer.getInstance().mapManager.map.getLayer(opLayers.label).visible = false;         }         setVisible(layer.visible, true);     }
0 Kudos
MartynSmith
Emerging Contributor
cheers!

Thanks again
0 Kudos
BrunoPereira1
Deactivated User
Martyn,

  Sure just change this :

    private function onLayerShow(event:FlexEvent):void
    {
        //Turn all other ops layers off before we switch this one on
        var opLayers:Array = ViewerContainer.getInstance().configData.opLayers;
        for (var i:int = 0; i < opLayers.length; i++){
            if(layer.id != opLayers.label)
                if(opLayers.label != "your point layer")
                    ViewerContainer.getInstance().mapManager.map.getLayer(opLayers.label).visible = false;
        }
        setVisible(layer.visible, true);
    }




Hi Robert,


I have a configData.opLayers inside a widget, but when I change on map the visibilities of this layers, my configData.opLayers continues with old value, how I update this values?

I think this values are inside the ViewerContainer with my widget, and this values is setted whem widget initialize, after this, does not initilize again, has some way to remove from container this widget?

Thanks;
0 Kudos
RaoBase
Deactivated User
I would like to switch on one layer at a time in a group layer. Is this feasible with the layer list widget.
Works fine on Map Switcher.
0 Kudos
omega_cancer
Frequent Contributor
Thanks Robert it helped. 🙂
0 Kudos
EricStarn2
Emerging Contributor
Martyn,

   Sure here is the code for that, you are responsible for ensuring that initally only one Op layer is visible:

This change goes in the src/com/esri/viewer/components/toc/tocClasses/TocMapLayerItem.as

    private function onLayerShow(event:FlexEvent):void
    {
        //Turn all other ops layers off before we switch this one on
        var opLayers:Array = ViewerContainer.getInstance().configData.opLayers;
        for (var i:int = 0; i < opLayers.length; i++){
            if(layer.id != opLayers.label)
                ViewerContainer.getInstance().mapManager.map.getLayer(opLayers.label).visible = false;
        }
        setVisible(layer.visible, true);
    }


Don't forget to click the top arrow (promote) and to click the Mark as answer check as shown below:



Hello,
I am jumping in on this because I want to do this also and have a few questions.

I am using a layer list widget to display all of my operational layers and would like them all to be able to be turned on at once except a group layer I have. Then I only want to be able to turn on one sublayer at a time.

I this possible and if so, how?

Eric
0 Kudos