Select to view content in your preferred language

Show disclaimer in popup window when layer is turned on

667
4
04-08-2010 12:54 PM
StuartBlumberg
Emerging Contributor
How would you show a disclaimer in a popup window when a specific layer is turned on? 
Thanks.
Tags (2)
0 Kudos
4 Replies
KenBuja
MVP Esteemed Contributor
The event listener FlexEvent.SHOW will fire when an object's visibility is set to True.

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" xmlns:esri="http://www.esri.com/2008/ags">
    
    <mx:Script>
        <![CDATA[
            import mx.controls.Alert;
            import mx.events.FlexEvent;
            
            private function loadHandler():void
            {
                dynamicMap.addEventListener(FlexEvent.SHOW, onShow)
            }
            
            private function onShow(e:Event):void
            {
                Alert.show("Visible")
            }
            
        ]]>
    </mx:Script>
    <mx:Canvas width="100%" height="100%">
        <esri:Map>
            <esri:ArcGISTiledMapServiceLayer url="http://server.arcgisonline.com/ArcGIS/rest/services/World_Physical_Map/MapServer"/>
            <esri:ArcGISDynamicMapServiceLayer id="dynamicMap" visible="{chkBox.selected}" load="loadHandler();" url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer"/>
        </esri:Map>
        <mx:CheckBox label="Layer visible" id="chkBox"/>
        
    </mx:Canvas>
</mx:Application>

0 Kudos
StuartBlumberg
Emerging Contributor
How would would I do this for a specific layer in the Sample Flex Viewer?  Thanks.
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Stuart,

   Add this to the AppEvent.as

/**
        * 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
        */
        public static const LAYER_VISIBILITY_CHANGED:String = "layerVisibilityChanged";


In the onLayerShow function and the onLayerHide functions of the TocMapLayerItem.as add
SiteContainer.dispatchEvent(new AppEvent(AppEvent.LAYER_VISIBILITY_CHANGED, false, false, layer.name));


In the onCheckBoxClick function and the onCheckBoxDoubleClick function of the TocItemRenderer.as add
SiteContainer.dispatchEvent(new AppEvent(AppEvent.LAYER_VISIBILITY_CHANGED, false, false, event));


in the MapManager or where ever you want to call the popup put this line in the init function.
SiteContainer.addEventListener(AppEvent.LAYER_VISIBILITY_CHANGED, yourPopupFunction);
0 Kudos
StuartBlumberg
Emerging Contributor
Robert,

I am getting the error:
1151: A conflict exists with definition LAYER_VISIBILITY_CHANGED in namespace internal.
for the following line in the AppEvent.as: public static const LAYER_VISIBILITY_CHANGED:String = "layerVisibilityChanged";

Another question:
for        SiteContainer.dispatchEvent(new AppEvent(AppEvent.LAYER_VISIBILITY_CHANGED, false, false, layer.name)); in place of layer.name do I need to put the name of the layer in the TOC?  For example, layer.Zoning.

Thanks.
0 Kudos