Select to view content in your preferred language

Attribute Inspector View Popup

1553
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
13 Replies
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:
0 Kudos
AnthoniLlau
Emerging Contributor
It works!!

Thank you for all your help.
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Tony,

   Glad it worked for you. Just a quick note though, you should place the check as answered on the post in the thread that answered your question (you marked your own post as the answer).
0 Kudos
AnthoniLlau
Emerging Contributor
Sorry, newbie to these forums as well.

Just did as requested, hopefully it worked fine.

Thanks,
0 Kudos