Select to view content in your preferred language

Using Identify Features under the samples of Find and Identify

1583
11
10-05-2010 07:43 AM
DidumAbraham
Deactivated User
Is it possible to change the content of the infoWindow of Identify Features to show a specific content?
Tags (2)
0 Kudos
11 Replies
KenBuja
MVP Esteemed Contributor
Use the content method of the InfoWindow to put other things in there. Take a look at this sample
0 Kudos
DidumAbraham
Deactivated User
The issue I'm having has to do with the line of clickGraphic.attributes = resultGraphic.attributes;
This basically displays all attributes on the InfoWindow, however, I'm after just two attributes and I have yet to be able to get it working with this identify features sample. Right now it's only showing empty infoWindow and I'm still working at it. Any help will be appreciated.


private function myResultFunction(results:Array, clickGraphic:Graphic=null):void {
if(results && results.length > 0){
for(var i:int=0; i<results.length; i++){
var result:IdentifyResult = results;
var resultGraphic:Graphic = result.feature;
if(resultGraphic.geometry && resultGraphic.geometry.type == Geometry.MAPPOINT){
resultGraphic.symbol = smsIdentify;
}
lastIdentifyResultGraphic = resultGraphic;

// update clickGraphic (from mouse click to returned feature)
clickGraphic.symbol = new InfoSymbol(); // use default renderer
//clickGraphic.attributes = resultGraphic.attributes;
function getHandler(event:GraphicEvent):void {
if(clickGraphic.attributes == resultGraphic.attributes){
event.graphic.addEventListener(MouseEvent.CLICK, onMouseClick);
}
}
}
}
}

private function onMouseClick(event:MouseEvent):void {
const clickGraphic:Graphic = event.target as Graphic;
if(clickGraphic) {
myTextArea.htmlText = "<b>URL: </b><a href='" + clickGraphic.attributes.PATH + "'>" + clickGraphic.attributes.PATH + "</a>";
myMap.infoWindow.label = "TITLE [" + clickGraphic.attributes.NAME + "]";
myMap.infoWindow.closeButtonVisible = true;
myMap.infoWindow.show(myMap.toMapFromStage(event.stageX, event.stageY));
}
}
0 Kudos
KenBuja
MVP Esteemed Contributor
I've taken the Identify Features sample and modified it so that it only shows some of the attributes of the feature that's selected.

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
               xmlns:s="library://ns.adobe.com/flex/spark"
               xmlns:esri="http://www.esri.com/2008/ags"
               pageTitle="Identify Features on the Map">
    <!--
    This sample shows how to identify features with a MapClick and the Identify task.
    
    The IdentifyParameters designate which layers are being identified.
    Identify operations can potentially return a lot of information
    depending on the number of layers being identified and a given tolerance.
    The tolerance is the number of pixels a feature is allowed to lie away
    from the clicked point in order to be counted as a result.
    
    In this sample, when user clicks the map, an "Identify" task is executed.
    
    When the task finishes executing, the executeCompleteHandler function loops
    through the features in the IdentifyResult and adds them to the map.
    -->
    <fx:Script>
        <![CDATA[
            import com.esri.ags.Graphic;
            import com.esri.ags.events.MapMouseEvent;
            import com.esri.ags.geometry.Geometry;
            import com.esri.ags.geometry.MapPoint;
            import com.esri.ags.symbols.InfoSymbol;
            import com.esri.ags.tasks.supportClasses.IdentifyParameters;
            import com.esri.ags.tasks.supportClasses.IdentifyResult;
            
            import mx.controls.Alert;
            import mx.rpc.AsyncResponder;
            
            import spark.components.TextArea;
            
            [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 = myMap.width;
                identifyParams.height = myMap.height;
                identifyParams.geometry = event.mapPoint;
                identifyParams.mapExtent = myMap.extent;
                identifyParams.spatialReference = myMap.spatialReference;
                
                var clickGraphic:Graphic = new Graphic(event.mapPoint, clickPtSym);
                clickGraphicsLayer.add(clickGraphic);
                
                identifyTask.execute(identifyParams, new AsyncResponder(myResultFunction, myFaultFunction, 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;
                    var textArea:TextArea = new TextArea();
                    var infoWindowText:String;
                    var mapPoint:MapPoint = MapPoint(clickGraphic.geometry);
                    var point:Point = myMap.toScreen(mapPoint); 
                    var label:String;
                    
                    switch (resultGraphic.geometry.type)
                    {
                        case Geometry.MAPPOINT:
                        {
                            label = "City Layer"
                            infoWindowText = "City: " + resultGraphic.attributes.CITY_NAME + "\nState: " + resultGraphic.attributes.STATE_NAME;
                            resultGraphic.symbol = smsIdentify;
                            break;
                        }
                        case Geometry.POLYLINE:
                        {
                            label = "River Layer"
                            infoWindowText = resultGraphic.attributes.NAME;
                            resultGraphic.symbol = slsIdentify;
                            break;
                        }
                        case Geometry.POLYGON:
                        {
                            label = "State Layer"
                            infoWindowText = resultGraphic.attributes.STATE_NAME;
                            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;
                    textArea.text = infoWindowText;
                    myMap.infoWindow.content = textArea;
                    myMap.infoWindow.label = label;
                    myMap.infoWindow.show(myMap.toMap(point));
                }
            }
            
            private function myFaultFunction(error:Object, clickGraphic:Graphic = null):void
            {
                Alert.show(String(error), "Identify Error");
            }
        ]]>
    </fx:Script>
    
    <fx:Declarations>
        <!-- Symbol for where the user clicked -->
        <esri:SimpleMarkerSymbol id="clickPtSym"
                                 color="0xFF0000"
                                 size="12"
                                 style="x"/>
        
        <!-- Symbol for Identify Result as Polyline -->
        <esri:SimpleLineSymbol id="slsIdentify"
                               width="2"
                               alpha="1"
                               color="0x00FF00"
                               style="solid"/>
        
        <!-- Symbol for Identify Result as Point -->
        <esri:SimpleMarkerSymbol id="smsIdentify"
                                 color="0x00FF00"
                                 size="15"
                                 style="diamond"/>
        
        <!-- Symbol for Identify Result as Polygon -->
        <esri:SimpleFillSymbol id="sfsIdentify"/>
        
        <!-- Identify Task -->
        <esri:IdentifyTask id="identifyTask"
                           concurrency="last"
                           url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StatesCitiesRivers_USA/MapServer"/>
    </fx:Declarations>
    
    <esri:Map id="myMap"
              mapClick="mapClickHandler(event)"
              openHandCursorVisible="false">
        <esri:extent>
            <esri:WebMercatorExtent minlon="-120" minlat="30" maxlon="-100" maxlat="50"/>
        </esri:extent>
        <esri:ArcGISTiledMapServiceLayer url="http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer"/>
        <esri:GraphicsLayer graphicProvider="{lastIdentifyResultGraphic}"/>
        <esri:GraphicsLayer id="clickGraphicsLayer"/>
    </esri:Map>
    
</s:Application>
0 Kudos
DidumAbraham
Deactivated User
Thank you!
0 Kudos
MayJeff
Deactivated User
Is there possible to add a simple hyperlink inside the text area?  For example, (http//:www.esri.com).

Thank you.

May
0 Kudos
JasonLevine
Deactivated User
Is there a way to change the color of the textArea box to match the color of the infoWindow behind it?

Thanks,
Jason
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Jason,

   Sure just add this:
//add under this line var textArea:TextArea = new TextArea();
textArea.setStyle("contentBackgroundColor","#999999");
0 Kudos
JasonLevine
Deactivated User
Thanks Robert, that worked perfectly.

However, when I select some text, right click and select copy, nothing gets copied.  It will copy the text when I select it and hit ctrl+c, just not when I use the context menu. 

The only thing I've specified is:
textArea.editable = false;

so that the user cannot change anything in the text box.

Is there a way to enable the context menu actions?  Not even "select all" will work.

Thanks,
Jason
0 Kudos
JasonLevine
Deactivated User
Never mind,
I got it working.
0 Kudos