Select to view content in your preferred language

Display XY at Banner in FLEX Viewer (2)

1037
4
07-09-2010 07:30 AM
ZahidChaudhry
Deactivated User
I want to display my mouse Coordinates on the banner (using classic banner) but some how i can get this one to work and here is what i am doing.
in classic controller widget i add an event listner and then i add the function something like this
[HTML]
private function initMap(event:AppEvent):void
            {
                map = event.data as Map;
                map.addEventListener(MouseEvent.CLICK, mcHandler);
              
            }
            private function mcHandler(evt:MouseEvent):void{
                Alert.show("HI");
            }
[/HTML]
Tags (2)
0 Kudos
4 Replies
RobertScheitlin__GISP
MVP Emeritus
Zahid,

   Here is my 2.0 banner.mxml
<?xml version="1.0" encoding="utf-8"?>
<!--
     ////////////////////////////////////////////////////////////////////////////////
     //
     // Copyright (c) 2010 ESRI
     //
     // All rights reserved under the copyright laws of the United States.
     // You may freely redistribute and use this software, with or
     // without modification, provided you include the original copyright
     // and use restrictions.  See use restrictions in the file:
     // <install location>/License.txt
     //
     ////////////////////////////////////////////////////////////////////////////////
-->
<mx:Canvas  xmlns:mx    ="http://www.adobe.com/2006/mxml"
   xmlns:s  ="library://ns.adobe.com/flex/spark"
   xmlns:flash ="flash.filters.*"
            minWidth    ="550"
            minHeight   ="70" 
   creationComplete="Init()">

    <mx:Script>
  <![CDATA[
   import com.esri.ags.Map;
   import com.esri.ags.SpatialReference;
   import com.esri.ags.geometry.MapPoint;
   import com.esri.viewer.AppEvent;
   import com.esri.viewer.ViewerContainer;
   
   import flash.filters.GlowFilter;
   
   import mx.resources.ResourceBundle;
   
   import widgets.ClassicController.ClassicControllerWidget;
   
   private var _map:Map;
   
   private var _logo:String;
   
   private var _Width:Number;
   
   /**
    * The logo that is used to brand the application at the controller area.
    * 
    * @param value the relative URL points to the logo image file.
    */
   public function set logo(value:String):void
   {
    _logo = value;
    if (value != "")
    {
     imgLogo.visible = true;
     imgLogo.includeInLayout = true;
    }
    else
    {
     imgLogo.visible = false;
     imgLogo.includeInLayout = false;
    }
   }
   
   //init
   private function Init():void
   {
    _map = ViewerContainer.getInstance().mapManager.map;
    _map.addEventListener(MouseEvent.MOUSE_MOVE,mouseMoveHandler);
   }
   
   private function mouseMoveHandler(event:MouseEvent):void
   {
    const mapPoint:MapPoint = _map.toMapFromStage(event.stageX, event.stageY);
    mapXY = "X: "+ mapPoint.x.toFixed(4) + ", Y: " + mapPoint.y.toFixed(4);
   }
   
   /**
    * @private
    */
   [Bindable]
   public function get logo():String
   {
    return _logo;
   }
   
   /**
    * The title displayed in the banner.
    */
   [Bindable]
   public var title:String;
   
   /**
    * The maps XY coordinates in the banner.
    */
   [Bindable]
   public var mapXY:String = "                          ";
   
   /**
    * The subtitle displayed in the banner.
    */ 
   [Bindable]
   public var subtitle:String;
   
   /**
    * The current/activated tool status displayed in the banner.
    */  
   [Bindable]
   public var status:String;
   
   /**
    * Displayed the maps xy coordinates on the banner.
    */  
   [Bindable]
   public var DisplayXY:Boolean=true;   
   
   private function nlsString(nlsToken:String):String
   {
    return resourceManager.getString('ControllerStrings', nlsToken);
   }
   
   public function logoClick():void
   {
    var controler:ClassicControllerWidget;
    if (vBox.visible){
     setStyle("backgroundAlpha", 0.0);
     vBox.visible = false;
     _Width = this.width;
     this.minWidth = 65;
     this.width = 65;
     this.verticalScrollPolicy = "off";
     this.horizontalScrollPolicy = "off"
     controler = parent.parent as ClassicControllerWidget;
     controler.menuContainer.visible = false;
     BorderCont.styleName = "ClassicBannerCanvasHidden";
    } else {
     setStyle("backgroundAlpha", 0.6);
     this.minWidth = 500;
     this .width = _Width;
     this.verticalScrollPolicy = "auto";
     this.horizontalScrollPolicy = "auto"
     vBox.visible = true;
     controler = parent.parent as ClassicControllerWidget;
     controler.menuContainer.visible = true;
     BorderCont.styleName = "ClassicBannerCanvas";
    }
   }
  ]]>
    </mx:Script>

 <mx:Metadata>
  [ResourceBundle("ControllerStrings")]
 </mx:Metadata> 

    <s:BorderContainer id="BorderCont" width="100%" height="70" styleName="ClassicBannerCanvas" >
        <s:layout>
            <s:VerticalLayout gap="0" />
        </s:layout>
  <s:HGroup width="100%" gap="0" verticalAlign="middle">
   <mx:Spacer width="10" />
   <mx:Image id="imgLogo" 
      source="{logo}" 
      maintainAspectRatio="true" 
      maxHeight="50" 
      maxWidth="70" 
      horizontalAlign="left" 
      verticalAlign="top" 
      visible="false" 
      includeInLayout="false"
      click="logoClick()" toolTip="Click Here to Hide/Show Banner">
    <mx:filters>
     <flash:DropShadowFilter color="#000000" distance="5" alpha="1" blurX="5" blurY="5"/>
    </mx:filters>
   </mx:Image>
   <mx:Spacer width="5" />
   <mx:VBox id="vBox" verticalGap="0" horizontalAlign="left" width="100%" >
    <mx:HBox width="100%" verticalAlign="top">
     <mx:Label styleName="ClassicBannerTitle" text="{title}"/>
     <mx:VBox verticalGap="1" horizontalAlign="right" width="100%" >
      <mx:HBox width="100%" horizontalAlign="right">
       <mx:Label styleName="ClassicBannerStatus" text="{mapXY}"/>
      </mx:HBox>
     </mx:VBox>
    </mx:HBox>
    <mx:HRule styleName="ClassicBannerRule" width="100%" />
    <mx:HBox width="100%" verticalAlign="top">
     <mx:Label styleName="ClassicBannerSubtitle" text="{subtitle}"/>
     <mx:HBox width="100%" horizontalAlign="right">
      <mx:Label styleName="ClassicBannerStatus" text="{nlsString('current_action') + status}"/>
     </mx:HBox>
    </mx:HBox>
   </mx:VBox>
   <mx:Spacer width="10" />
  </s:HGroup>
  <mx:Spacer height="15"/>
    </s:BorderContainer>
</mx:Canvas>
0 Kudos
ZahidChaudhry
Deactivated User
Thank You Robert - One more time
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Shaning,

    Now a days you have to carefully read the threads and see if they are talking about the Sample Flex Viewer (which your mod to my code was made for) or as Zahid is asking about the ArcGIS Viewer for Flex 2.0 Beta.
0 Kudos