Select to view content in your preferred language

AttributeInspector in an InfoWindow

1474
6
08-10-2010 12:14 PM
KathleenBrenkert
Regular Contributor
I've been using the following code to set my infoWindow label to an attribute returned from my feature service.  This works great until I have more then 1 selected feature.  How do I get it to use the selected feature that is currently shown in the attribute inspector, and how do I get it to update after clicking the next or pervious buttons?  I have attempted to call the activeFeatureIndex of my attributeInspector, but I can't seem to get a value.

myMap.infoWindow.label="File "+ event.featureLayer.selectedFeatures[0].attributes.FileNo;

Thanks!
Tags (2)
0 Kudos
6 Replies
SarthakDatt
Frequent Contributor
Hey Kathleen,

You could watch for change on activeFeature property on the attribute inspector and whenever that is changed(moving through the attribute inspector), you could use the attributes of the current activeFeature.

Something like:

private var changeWatcher:ChangeWatcher;

// on lets say application intialize, do the following:

changeWatcher = ChangeWatcher.watch(attributeInspector, "activeFeature", attributeInspector_activeFeatureChangeHandler);   //attributeInspector is the AttributeInspector Object

private function attributeInspector_activeFeatureChangeHandler(event:Event=null):void
{
    myMap.infoWindow.label="File "+ attributeInspector.activeFeature.attributes.FileNo;
}


Hope that helps.
0 Kudos
KathleenBrenkert
Regular Contributor
I stuck this in and it doesn't seem to pick up the change.  It also looks to me that the activeFeature property loads after my infowindow has popped up- makes sense, but I can't see how to set my label to the correct feature to start.  It will load the selectedFeatures[0].attribute(etc), but this doesn't usually match the first record in my attribute Inspector.

private var changeWatcher:ChangeWatcher;
private function application1_initializeHandler(event:FlexEvent):void
{
    changeWatcher=ChangeWatcher.watch(attrInsp,"activeFeature", attrInsp_activeFeatureChangeHandler);
}
private function attrInsp_activeFeatureChangeHandler(event:Event=null):void
{
    myMap.infoWindow.label="File "+ attrInsp.activeFeature.attributes.FileNo;
}


I've currently created a work around so if my selection set is >1, it hides my attribute driven labels and shows their fieldInspectors.  Its not as pretty as if my selection set is =1, but it works.
0 Kudos
KathleenBrenkert
Regular Contributor
I discovered I can add my custom labels to the skin.  I just put what I needed above the form using the format below.  Solved my problem.
<s:Label text="{hostComponent.activeFeature.attributes.FieldNameHere}"/>
0 Kudos
KathleenBrenkert
Regular Contributor
If I use the above method for a date field I get the UTC number as a string instead of a date object.  I have searched the internet for ways to convert this 13 digit string back to a date but have had no luck.  A coded domain gives me the same headache-I get the code.  I could use some suggestions.
0 Kudos
DasaPaddock
Esri Regular Contributor
To convert a number to a Date, you just need to pass it to the Date's constructor like this:
   
var myDate:Date = new Date(value);
0 Kudos
KathleenBrenkert
Regular Contributor
I had tried to cast the activeFeature attribute directly to myDate and got errors.  Once I added another date variable inside the function it worked.  Probably a rookie mistake...

[Bindable]
   public var myDate:Date;
   protected function FireDetails_clickHandler():void
   {
    var selFireDate:Date=new Date(hostComponent.activeFeature.attributes.FInspect);
    myDate=selFireDate;
    currentState="fire";
   }
0 Kudos