Select to view content in your preferred language

Attribute Inspector View Popup

1551
13
Jump to solution
01-13-2012 06:46 AM
AnthoniLlau
Emerging Contributor
Hi all,

I'm a newbie to API for Flex with an issue when clicking on a feature layer. When clicking, I get an [object Object] result for the field I have selected. The code is below. Any guidance on what modifications are needed is greatly appreciated. I highlighted the code section where it is having the problem.

Thanks,

Tony

<?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="Attribute Inspector (edit)">
<!--
This application is "ViewOnly" and connects to a non-editable layer.

This application allows user to click on a feature (parcels)
and view a few attributes of that feature.

This is done by clicking a point on the map to select feature(s)
from the FeatureLayer.

The AttributeInspector then displays the selection in the InfoWindow
popup which is shown where user clicked the map.

Note that this sample displays the FeatureLayer in "selection" mode and
that the parcels are actually displayed using a dynamic layer pointing to
the matching map service.
-->

<fx:Script>
<![CDATA[
import com.esri.ags.events.FeatureLayerEvent;
import com.esri.ags.events.MapMouseEvent;
import com.esri.ags.geometry.MapPoint;

import mx.controls.Alert;
import mx.rpc.events.FaultEvent;

protected function map_mapClickHandler(event:MapMouseEvent):void
{
// set the selection query based on the click
queryMapClick.geometry = event.mapPoint;
myFeatureLayer.selectFeatures(queryMapClick); // default selectionMethod is FeatureLayer.SELECTION_NEW
myMap.infoWindow.hide();
}

protected function attrInsp_faultHandler(event:FaultEvent):void
{
Alert.show(event.fault.message, "Fault");
}

protected function myFeatureLayer_selectionCompleteHandler(event:FeatureLayerEvent):void
{
// only show infoWindow if a feature was found
if (event.featureLayer.numGraphics > 0)
{
myMap.infoWindow.label = "Zip Code " + event.featureLayer.selectedFeatures[0].attributes; myMap.infoWindow.show(queryMapClick.geometry as MapPoint);
}
else
{
Alert.show("Sorry found nothing here...");
}
}
]]>
</fx:Script>

<fx:Declarations>
<esri:Query id="queryMapClick"/>
</fx:Declarations>

<fx:Style>
@namespace s "library://ns.adobe.com/flex/spark";
@namespace esri "http://www.esri.com/2008/ags";

esri|InfoWindow
{
background-color: #0066FF; /* dark khaki */
border-color: #000000;
border-thickness: 3;
lower-left-radius: 20;
lower-right-radius: 20;
upper-left-radius: 20;
upper-right-radius: 0;
padding-bottom: 7;
padding-left: 7;
padding-right: 7;
padding-top: 4;
}
esri|InfoWindowLabel
{
color: #FFFFFF;
font-size: 15;
padding-left: 120;
}
s|BorderContainer
{
background-color: #F0E68C; /* light khaki */
corner-radius: 15;
content-background-color: #BDB76B;
padding-bottom: 5;
}
</fx:Style>

<s:layout>
<s:VerticalLayout/>
</s:layout>

<esri:Map id="myMap"
load="attrInsp.featureLayers = [myFeatureLayer]"
mapClick="map_mapClickHandler(event)"
openHandCursorVisible="false">
<!-- Extent for Dade County -->
<esri:extent>
<esri:Extent xmin="767247" ymin="346748" xmax="954385" ymax="609584">
<esri:SpatialReference wkid="2236"/>
</esri:Extent>
</esri:extent>
<esri:ArcGISDynamicMapServiceLayer url="http://dohswebchd1301/ArcGIS/rest/services/Test/Pool_Drownings_1_-_4_Years_2005_-_2010/MapServer"/>
<esri:FeatureLayer id="myFeatureLayer"
mode="selection"
outFields="[ZIP_INDICATORS.ZIP,Sheet1$.Total]"
selectionColor="0x000000"
selectionComplete="myFeatureLayer_selectionCompleteHandler(event)"
url="http://dohswebchd1301/ArcGIS/rest/services/Test/Pool_Drownings_1_-_4_Years_2005_-_2010/MapServer/0"/>
<esri:infoWindowContent>
<s:BorderContainer>
<esri:AttributeInspector id="attrInsp"/>
</s:BorderContainer>
</esri:infoWindowContent>
</esri:Map>

<s:Label text="The feature layer has {myFeatureLayer.selectedFeatures.length} selected feature(s)."/>

</s:Application>
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus
Tony,

   That makes perfect sense as you can not use a fields value if you do not tell the featurelayer to return results for that field.

Here is what you have to do to eliminate the zip from the attribute inspector results:

<esri:infoWindowContent>             <s:BorderContainer>                 <esri:AttributeInspector id="attrInsp"                                          formItemsOrder="fieldInspector"                                          featureLayers="{[myFeatureLayer]}">                     <esri:FieldInspector featureLayer="{myFeatureLayer}"                                          fieldName="parcels2.NAME"                                          label="Parcel Owner Name"/>                     <esri:FieldInspector featureLayer="{myFeatureLayer}"                                          fieldName="PPIN"                                          label="Parcel ID Number"/>                     <esri:FieldInspector featureLayer="{myFeatureLayer}"                                          visible="false"                                           fieldName="parcels2.ZIPCODE_1"                                          label="Zip Code"/>                 </esri:AttributeInspector>             </s:BorderContainer>         </esri:infoWindowContent>


Don't forget to click the top arrow (promote) and to click the Mark as answer check as shown below:

View solution in original post

0 Kudos
13 Replies
RobertScheitlin__GISP
MVP Emeritus
Anthoni,

   You are not specifying which attribute you want...

myMap.infoWindow.label = "Zip Code " + event.featureLayer.selectedFeatures[0].attributes["FieldName"];
0 Kudos
AnthoniLlau
Emerging Contributor
Anthoni,

   You are not specifying which attribute you want...

myMap.infoWindow.label = "Zip Code " + event.featureLayer.selectedFeatures[0].attributes["FieldName"];


Thanks for the quick response.

I tried as you suggested, but now it is giving me an "undefined" result.
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Anthoni,


   You did replace "Field Name" with your actual field name that you are trying to you right?
0 Kudos
AnthoniLlau
Emerging Contributor
Anthoni, 


You did replace "Field Name" with your actual field name that you are trying to you right?


Yes. I used the last field name of those shown below.

Fields:
ZIP_INDICATORS.FID (Type: esriFieldTypeOID, Alias: FID)
ZIP_INDICATORS.Shape (Type: esriFieldTypeGeometry, Alias: Shape)
ZIP_INDICATORS.AREA (Type: esriFieldTypeDouble, Alias: AREA)
ZIP_INDICATORS.PERIMETER (Type: esriFieldTypeDouble, Alias: PERIMETER)
ZIP_INDICATORS.ZIP (Type: esriFieldTypeDouble, Alias: ZIP)
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Anthoni,

  So your code looks like this than:

myMap.infoWindow.label = "Zip Code " + event.featureLayer.selectedFeatures[0].attributes["ZIP_INDICATORS.ZIP"];
0 Kudos
AnthoniLlau
Emerging Contributor
Anthoni,

  So your code looks like this than:

myMap.infoWindow.label = "Zip Code " + event.featureLayer.selectedFeatures[0].attributes["ZIP_INDICATORS.ZIP"];


Yes it does. Is it attempting to search for a default variable type (e.g. string)?
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Tony,

   I got this code to work perfectly using one of my joined map services:

<?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="Attribute Inspector (edit)">
    <!--
    This application is "ViewOnly" and connects to a non-editable layer.
    
    This application allows user to click on a feature (parcels)
    and view a few attributes of that feature.
    
    This is done by clicking a point on the map to select feature(s)
    from the FeatureLayer.
    
    The AttributeInspector then displays the selection in the InfoWindow
    popup which is shown where user clicked the map.
    
    Note that this sample displays the FeatureLayer in "selection" mode and
    that the parcels are actually displayed using a dynamic layer pointing to
    the matching map service.
    -->
    
    <fx:Script>
        <![CDATA[
            import com.esri.ags.events.FeatureLayerEvent;
            import com.esri.ags.events.MapMouseEvent;
            import com.esri.ags.geometry.MapPoint;
            
            import mx.controls.Alert;
            import mx.rpc.events.FaultEvent;
            
            protected function map_mapClickHandler(event:MapMouseEvent):void
            {
                // set the selection query based on the click
                queryMapClick.geometry = event.mapPoint;
                myFeatureLayer.selectFeatures(queryMapClick); // default selectionMethod is FeatureLayer.SELECTION_NEW
                myMap.infoWindow.hide();
            }
            
            protected function attrInsp_faultHandler(event:FaultEvent):void
            {
                Alert.show(event.fault.message, "Fault");
            }
            
            protected function myFeatureLayer_selectionCompleteHandler(event:FeatureLayerEvent):void
            {
                // only show infoWindow if a feature was found
                if (event.featureLayer.numGraphics > 0)
                {
                    myMap.infoWindow.label = "Zip Code " + event.featureLayer.selectedFeatures[0].attributes["parcels2.ZIPCODE_1"]; 
                    myMap.infoWindow.show(queryMapClick.geometry as MapPoint);
                }
                else
                {
                    Alert.show("Sorry found nothing here...");
                }
            }
        ]]>
    </fx:Script>
    
    <fx:Declarations>
        <esri:Query id="queryMapClick"/>
    </fx:Declarations>
    
    <fx:Style>
        @namespace s "library://ns.adobe.com/flex/spark";
        @namespace esri "http://www.esri.com/2008/ags";
        
        esri|InfoWindow
        {
            background-color: #0066FF; /* dark khaki */
            border-color: #000000;
            border-thickness: 3;
            lower-left-radius: 20;
            lower-right-radius: 20;
            upper-left-radius: 20;
            upper-right-radius: 0;
            padding-bottom: 7;
            padding-left: 7;
            padding-right: 7;
            padding-top: 4;
        }
        esri|InfoWindowLabel
        {
            color: #FFFFFF;
            font-size: 15;
            padding-left: 120;
        }
        s|BorderContainer
        {
            background-color: #F0E68C; /* light khaki */
            corner-radius: 15;
            content-background-color: #BDB76B;
            padding-bottom: 5;
        }
    </fx:Style>
    
    <s:layout>
        <s:VerticalLayout/>
    </s:layout>
    
    <esri:Map id="myMap"
              load="attrInsp.featureLayers = [myFeatureLayer]"
              mapClick="map_mapClickHandler(event)"
              openHandCursorVisible="false">
        <!-- Extent for Dade County -->
        <!--<esri:extent>
            <esri:Extent xmin="767247" ymin="346748" xmax="954385" ymax="609584">
                <esri:SpatialReference wkid="2236"/>
            </esri:Extent>
        </esri:extent>-->
        <esri:ArcGISDynamicMapServiceLayer url="http://gislap134/ArcGIS/rest/services/Join_Test/MapServer"/>
        <esri:FeatureLayer id="myFeatureLayer"
                           mode="selection"
                           outFields="[parcels2.NAME,PPIN,parcels2.ZIPCODE_1]"
                           selectionColor="0x000000"
                           selectionComplete="myFeatureLayer_selectionCompleteHandler(event)"
                           url="http://gislap134/ArcGIS/rest/services/Join_Test/MapServer/0"/>
        <esri:infoWindowContent>
            <s:BorderContainer>
                <esri:AttributeInspector id="attrInsp"/>
            </s:BorderContainer>
        </esri:infoWindowContent>
    </esri:Map>
    
    <s:Label text="The feature layer has {myFeatureLayer.selectedFeatures.length} selected feature(s)."/>
    
</s:Application>


You need to check your map service and see if the join took correctly. I am concerned with a field name like Sheet1$.Total sounds like you have joined an excel spreadsheet and that will be questionable is the ArcGIS SOC account will have access to that spreadsheet.
0 Kudos
AnthoniLlau
Emerging Contributor
Thanks Robert. I did join it with an excel spreadhseet.
I'll go back to fix this and give you an update. Thanks for all your help.

Tony
0 Kudos
AnthoniLlau
Emerging Contributor
Hi,

I removed the join it works much better but not perfect as of yet.
It displays the zip code only when I place that variable in the outfields. However, when doing so it repeats itself (both in the heading and again with the other field (drownings). If I don't place the variable in the outfields it still appears as undefined.

Here is the code I'm currently using. I highlighted the pertinent code in red.

Thanks,

Tony

<?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="Attribute Inspector (edit)" xmlns:mx="library://ns.adobe.com/flex/mx">

<fx:Script>
<![CDATA[
import com.esri.ags.events.FeatureLayerEvent;
import com.esri.ags.events.MapMouseEvent;
import com.esri.ags.geometry.MapPoint;

import mx.controls.Alert;
import mx.rpc.events.FaultEvent;

protected function map_mapClickHandler(event:MapMouseEvent):void
{
// set the selection query based on the click
queryMapClick.geometry = event.mapPoint;
myFeatureLayer.selectFeatures(queryMapClick); // default selectionMethod is FeatureLayer.SELECTION_NEW
myMap.infoWindow.hide();
}

protected function attrInsp_faultHandler(event:FaultEvent):void
{
Alert.show(event.fault.message, "Fault");
}

protected function myFeatureLayer_selectionCompleteHandler(event:FeatureLayerEvent):void
{
// only show infoWindow if a feature was found
if (event.featureLayer.numGraphics > 0)
{
myMap.infoWindow.label = "Zip Code: " + event.featureLayer.selectedFeatures[0].attributes.["ZIP"]; myMap.infoWindow.show(queryMapClick.geometry as MapPoint);
}
else
{
Alert.show("Sorry found nothing here...");
}
}
]]>
</fx:Script>

<fx:Declarations>
<esri:Query id="queryMapClick"/>
</fx:Declarations>

<fx:Style>
@namespace s "library://ns.adobe.com/flex/spark";
@namespace esri "http://www.esri.com/2008/ags";

esri|InfoWindow
{
background-color: #0066FF; /* blue */
border-color: #000000;
border-thickness: 2;
lower-left-radius: 10;
lower-right-radius: 10;
upper-left-radius: 10;
upper-right-radius: 0;
padding-bottom: 7;
padding-left: 7;
padding-right: 7;
padding-top: 4;
}
esri|InfoWindowLabel
{
color: #FFFFFF;
font-size: 15;
padding-left: 10;
}
s|BorderContainer
{
background-color: #F0E68C; /* light khaki */
corner-radius: 15;
content-background-color: #BDB76B;
padding-bottom: 5;
}
</fx:Style>

<s:layout>
<s:VerticalLayout/>
</s:layout>

<esri:Map id="myMap"
load="attrInsp.featureLayers = [myFeatureLayer]"
mapClick="map_mapClickHandler(event)"
openHandCursorVisible="false">
<!-- Extent for Dade County -->
<esri:extent>
<esri:Extent xmin="767247" ymin="346748" xmax="954385" ymax="609584">
<esri:SpatialReference wkid="2236"/>
</esri:Extent>
</esri:extent>
<esri:ArcGISDynamicMapServiceLayer url="http://dohswebchd1301/ArcGIS/rest/services/Test/Pool_Drownings1-4Years0510/MapServer"/>
<esri:FeatureLayer id="myFeatureLayer"
mode="selection"
outFields="[ZIP,Drownings]" selectionColor="0x000000"
selectionComplete="myFeatureLayer_selectionCompleteHandler(event)"
url="http://dohswebchd1301/ArcGIS/rest/services/Test/Pool_Drownings1-4Years0510/MapServer/1"/>
<esri:infoWindowContent>
<s:BorderContainer>
<esri:AttributeInspector id="attrInsp"/>
</s:BorderContainer>

</esri:infoWindowContent>
</esri:Map>

<s:Label text="The feature layer has {myFeatureLayer.selectedFeatures.length} selected feature(s)."/>

</s:Application>
0 Kudos