Select to view content in your preferred language

Make a layer visible when a widget is clicked

678
1
07-26-2011 01:17 PM
ThomasDyer
Emerging Contributor
I would like to be able to make a layer visible when a user clicks on the query bookmark widget I found in the samples. Currently the widget works fine even if the layer is not turned on. So, all I need to do is check and see if the layer is currently visible and if it is not make it visible. It sounds easy, but I have not been able to find the right code yet. Any help is appreciated. Thanks.
Tags (2)
0 Kudos
1 Reply
DrewDowling
Frequent Contributor
maybe you can adopt this to help you. in the addLayer funtion you will need to add code to loop through MyDynamicMapService.visibleLayers and see if the layerID is present.

add this line to your existing code:

addLayer(getLayerInfoID(MyDynamicMapService.layerInfos,"MyLayerName"));

//Add these functions to your code

            private function addLayer(layerInfo:LayerInfo):void
            {
                                //add code here to loop through MyDynamicMapService.visibleLayers

                               //This line adds the layer
                                MyDynamicMapService.visibleLayers.addItem(layerInfo.id);
                }


            //given an array of layerinfos and a layername returns the layer ID
            private function getLayerInfoID(layerInfos:Array, layerName:String):LayerInfo
            {
                var info:LayerInfo;
                for (var i:int = 0; i < layerInfos.length; i++)
                {
                    if (layerInfos.name == layerName)
                    {
                        info = layerInfos
                    }
                }
                return info
            }
0 Kudos