Select to view content in your preferred language

Link Standalone Identify funtion to button

516
4
12-15-2010 10:18 AM
MikeJun
Emerging Contributor
Hi,

I just want to fire identify function, downloaded from sample code at http://resources.esri.com/help/9.3/arcgisserver/apis/flex/samples/index.html, from a button.

When I hook up this to button like <mx:Button toolTip="Identify" click="mapClickHandler(event)" /> I got error message like "1118: Implicit coercion of a value with static type flash.events:MouseEvent to a possibly unrelated type com.esri.ags.events:MapMouseEvent."

Any help appreciated!
Tags (2)
0 Kudos
4 Replies
RobertScheitlin__GISP
MVP Emeritus
Mike,

   You need to do something like this:

<mx:Button toolTip="Identify" click="{myMap.addEventListener(MapMouseEvent.MAP_CLICK, mapClickHandler)}" />
<esri:Map id="myMap"
              openHandCursorVisible="false">
0 Kudos
MikeJun
Emerging Contributor
Robert! Thank you for the quick response! It works great!

One thing after another! What I try to do is make a simple toolbar including zoom in, out, pan, next, full view with identify tool. When I put these zoom tools that I got from sample code and identify tool together, I can't scroll the attribute table after using one of these zoom tool. It just do pan function.

I think what I need is to clear any zoom tools funcation selected previous before firing up identify tool.



<?xml version="1.0" encoding="utf-8"?>
<mx:Application
    xmlns:mx="http://www.adobe.com/2006/mxml"
    xmlns:esri="http://www.esri.com/2008/ags"
    styleName="plain"
    >

    <mx:Script>
        <![CDATA[
         import com.esri.ags.controls.InfoWindow;
            import com.esri.ags.Graphic;
            import com.esri.ags.events.MapMouseEvent;
            import com.esri.ags.geometry.Geometry;
            import com.esri.ags.symbol.InfoSymbol;
            import com.esri.ags.tasks.IdentifyParameters;
            import com.esri.ags.tasks.IdentifyResult;

            import mx.controls.Alert;
            import mx.rpc.AsyncResponder;
           
            [Bindable]
            private var lastIdentifyResultGraphic:Graphic;

            private function mapClickHandler(event:MapMouseEvent):void
            {
                clickGraphicsLayer.clear();

                var identifyParams:IdentifyParameters = new IdentifyParameters();
                identifyParams.returnGeometry = true;
                identifyParams.tolerance = 3;
                identifyParams.width = mainMap.width;
                identifyParams.height = mainMap.height;
                identifyParams.geometry = event.mapPoint;
                identifyParams.mapExtent = mainMap.extent;
                identifyParams.spatialReference = mainMap.spatialReference;
               
                var clickGraphic:Graphic = new Graphic(event.mapPoint, clickPtSym);
                identifyTask.execute(identifyParams, new AsyncResponder(myResultFunction, myFaultFunction, clickGraphic));
                clickGraphicsLayer.add(clickGraphic);
            }

            private function myResultFunction(results:Array, clickGraphic:Graphic = null):void
            {
                if (results && results.length > 0)
                {
                    var result:IdentifyResult = results[0];
                    var resultGraphic:Graphic = result.feature;
                    switch (resultGraphic.geometry.type)
                    {
                        case Geometry.MAPPOINT:
                        {
                            resultGraphic.symbol = smsIdentify;
                            break;
                        }
                        case Geometry.POLYLINE:
                        {
                            resultGraphic.symbol = slsIdentify;
                            break;
                        }
                        case Geometry.POLYGON:
                        {
                            resultGraphic.symbol = sfsIdentify;
                            break;
                        }
                    }
                    lastIdentifyResultGraphic = resultGraphic;
                   
                    // update clickGraphic (from mouse click to returned feature)
                    clickGraphic.symbol = new InfoSymbol(); // use default renderer
                    clickGraphic.attributes = resultGraphic.attributes;
                }
            }
           
            private function myFaultFunction(error:Object, clickGraphic:Graphic = null):void
            {
                Alert.show(String(error), "Identify Error");
            }
        ]]>
    </mx:Script>

    <!-- start declarations -->
   
        <!-- Symbol for where the user clicked -->
       
        <esri:SimpleMarkerSymbol id="clickPtSym" style="x" color="0xFF0000" size="12"/>
       
        <!-- Symbol for Identify Result as Polyline -->
        <esri:SimpleLineSymbol id="slsIdentify" style="solid" color="0x00FF00" width="2" alpha="1"/>
   
        <!-- Symbol for Identify Result as Point -->
        <esri:SimpleMarkerSymbol id="smsIdentify" style="diamond" color="0x00FF00" size="15"/>
   
        <!-- Symbol for Identify Result as Polygon -->
        <esri:SimpleFillSymbol id="sfsIdentify"/>
   
        <!-- Identify Task -->
        <esri:IdentifyTask id="identifyTask"
            concurrency="last"
            url="http://cobgisags/ArcGIS/rest/services/BaseMap/MapServer"/>
           
           
<esri:Navigation id="navToolbar" map="{mainMap}"/>
<mx:VBox height="100%" width="100%" verticalGap="0" >
<mx:Canvas id="cvMain" horizontalScrollPolicy="off" verticalScrollPolicy="off"  height="100%" width="100%" borderThickness="1" cornerRadius="10" >
  
 
     <esri:Map id="mainMap" openHandCursorVisible="false">
      <esri:extent>
      <esri:Extent xmin="7335959" ymin="356193" xmax="8001213" ymax="979039">
                <esri:SpatialReference wkid="2913"/>
            </esri:Extent>
      </esri:extent>
     
           
  <esri:ArcGISTiledMapServiceLayer
            url="http://xxxags/ArcGIS/rest/services/BaseMap/MapServer"/>
            <esri:GraphicsLayer id="clickGraphicsLayer"/>
  </esri:Map> 
  

   <!-- TOP TOOL BAR  -->
<mx:HBox  id="topHBOX" horizontalAlign="center" width="100%" y="10">
  <mx:Canvas id="topbar" left="5" right="5" height="55" horizontalScrollPolicy="off" backgroundColor="#3477C0" borderStyle="solid" backgroundAlpha=".6" cornerRadius="20">
     <mx:filters>
               <mx:DropShadowFilter color="0x666666" angle="60" distance="4" />
           </mx:filters>
   <mx:HBox id="toolBarBox" horizontalGap="5" verticalAlign="middle" width="100%">
     <mx:Spacer width="10" />

     <mx:Button toolTip="Zoom In" click="navToolbar.activate(Navigation.ZOOM_IN)" id="ZoominBtn" styleName="main" icon="@Embed(source='images/zoomin.png')" height="50" width="50"/>                                       
     <mx:Button toolTip="Zoom Out" click="navToolbar.activate(Navigation.ZOOM_OUT)" id="ZoomoutBtn" styleName="main" icon="@Embed(source='images/zoomout1.png')" height="50" width="50"  />
     <mx:Button toolTip="Pan" click="navToolbar.activate(Navigation.PAN)" id="PanBtn" styleName="main" icon="@Embed(source='images/pan_hand.png')" height="50" width="50"  /> 
     <mx:Spacer width="5" />
  
     <mx:Image source="images/Break_gray.png" />
     <mx:Spacer width="5" />
  
     <mx:Button toolTip="Previous Extent" click="navToolbar.zoomToPrevExtent()" enabled="{!navToolbar.isFirstExtent}" icon="@Embed(source='images/zoomprevious.png')" height="50" width="50" />
     <mx:Button toolTip="Next Extent" click="navToolbar.zoomToNextExtent()" enabled="{!navToolbar.isLastExtent}" icon="@Embed(source='images/zoomnext.png')" height="50" width="50"  />
     <mx:Button toolTip="Full Extent" click="navToolbar.zoomToFullExtent()" icon="@Embed(source='images/zoomfull.png')" height="50" width="50"  />
    
     <mx:Image source="images/Break_gray.png" />
     <mx:Spacer width="5" />
    
    
     <mx:Button toolTip="Identify" click="{mainMap.addEventListener(MapMouseEvent.MAP_CLICK, mapClickHandler)}" icon="@Embed(source='images/identify.png')" height="50" width="50" />
    
     <mx:Spacer width="5" />
    
  
 
    </mx:HBox>   
  </mx:Canvas>
</mx:HBox> 
</mx:Canvas>
</mx:VBox>
     
</mx:Application>
0 Kudos
MikeJun
Emerging Contributor
I figured it out! Thanks!

private function mapClickHandler(event:MapMouseEvent):void
{

navToolbar.deactivate();
0 Kudos
raffia
by
Deactivated User
Mike,

   You need to do something like this:

<mx:Button toolTip="Identify" click="{myMap.addEventListener(MapMouseEvent.MAP_CLICK, mapClickHandler)}" />
<esri:Map id="myMap"
              openHandCursorVisible="false">


Thank you Robert for this reply as well, it helped me too.
0 Kudos