Select to view content in your preferred language

Infowindow - change what is displayed based on current layer visibility

660
5
Jump to solution
03-16-2012 08:55 AM
TracySchloss
Frequent Contributor
I have written an external component that will check to see what layers are currently turned on and based on that, will show different results in in the infoWindow.

My infoWindowRenderer is:
<?xml version="1.0" encoding="utf-8"?> <mx:VBox xmlns:fx="http://ns.adobe.com/mxml/2009"      xmlns:s="library://ns.adobe.com/flex/spark"      xmlns:mx="library://ns.adobe.com/flex/mx"     xmlns:supportClasses="com.esri.ags.components.supportClasses.*"      initialize="initRenderer()">    <fx:Declarations>   <!-- Place non-visual elements (e.g., services, value objects) here -->  </fx:Declarations>    <fx:Script>   <![CDATA[    import com.esri.ags.Map;        import mx.core.FlexGlobals;        [Bindable]    public var mainMap:Map;        [Bindable]    public var houseVis:Boolean;        [Bindable]    public var senateVis:Boolean;        [Bindable]    public var congressVis:Boolean;        public function initRenderer(): void {     mainMap = FlexGlobals.topLevelApplication.mainMap;     houseVis = FlexGlobals.topLevelApplication.houseLayer.visible;     senateVis = FlexGlobals.topLevelApplication.senateLayer.visible;     congressVis = FlexGlobals.topLevelApplication.congressLayer.visible;          trace ("within MyDistrictWindowRenderer, mainMap is " + mainMap.id +     ", houseVis = " + houseVis + ", senateVis = " + senateVis + ", congressVis  = " + congressVis);    }   ]]>  </fx:Script>    <supportClasses:InfoWindowLabel text="Missouri Districts" styleName="balloonTitle" />  <s:Label includeInLayout="{houseVis != ''? true:false}"      visible="{houseVis != ''? true:false}"     text="House:  {data.HOUSE_DIST}" paddingTop="2"/>  <s:Label includeInLayout="{senateVis != ''? true:false}"      visible="{senateVis != ''? true:false}"     text="Senate:  {data.SEN_DIST}" paddingTop="2" />  <s:Label includeInLayout="{congressVis != ''? true:false}"      visible="{congressVis != ''? true:false}"     text="Congressional:  {data.CONG_DIST}" paddingTop="2" /> </mx:VBox>


I'm using a graphicslayer with event listeners to add the infoWindow (these are polygons).  I have a composite layer that I'm using for labeling that contains fields for house, senate and congressional districts (so I can return all 3 districts from a single click into a single infoWindow).   Whatever combination of layers I have turned on, the Renderer should recognize and set the visibility for each label based on the variable I have set for layer visibility.  This should make my infoWindowRenderer a lot more dynamic. 

Here is where I'm calling the infoWindow:
private function onMouseUp(event:MouseEvent):void {     var g:Graphic = Graphic(event.currentTarget);     mainMap.infoWindow.hide();     mainMap.infoWindow.data = g.attributes;     mainMap.infoWindow.closeButtonVisible=true;              mainMap.infoWindow.content = myInfoWindowRenderer.newInstance();      mainMap.infoWindow.show( MapPoint(g.geometry.extent.center) );     mainMap.infoWindow.styleName = "myInfoWindow";              g.checkForMouseListeners = false;    }

This works up to a point.  For example, if I have all 3 layers turned on, when I click I see all 3 district numbers listed.  When I turn off a layer (for example, house) and click in another part of the state, it shows me just the senate and congressional and the house is not included.  If I click back to my original area, it still remembers that original graphic (or event.currentTarget).  It will continue to remember what the visibility/renderer settings were for as many times as I care to click in that same area.

Is there a way to clear this out and somehow not have it remember that I've already clicked it once so it resets the infoWindowRenderer?
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
DasaPaddock
Esri Regular Contributor
Glad it's working 🙂

If you want to work around the error, use:

import mx.core.IDataRenderer;

.....

IDataRenderer(mainMap.infoWindow.content).data = g.attributes;

View solution in original post

0 Kudos
5 Replies
DasaPaddock
Esri Regular Contributor
The code looks OK. Does the trace come out fine every time?

Are you setting the infoWindowRenderer property of the GraphicsLayer? If you are, I'd try not setting it since your code is taking care of showing the InfoWindow.
0 Kudos
TracySchloss
Frequent Contributor
I am setting the infoWindow on the individual graphics of the graphicslayer.  When I tried taking that out of the for each loop, then my infoWindow only had a title and no data.

public function layerQueryResults(qryFeatures:FeatureSet, token:Object = null): void {                                                
    /* populate graphic layer with features returned from the querytask.  Using a graphiclayer instead of just calling
    the service allows you to add tool tips etc that aren't available otherwise */
    
    for each(var myGraphic : Graphic in qryFeatures.features) {  
     var houseVis:Boolean = houseLayer.visible;
     var senateVis:Boolean = senateLayer.visible;
     var congressVis:Boolean = congressLayer.visible;
    
      /* myGraphic.addEventListener(MouseEvent.ROLL_OVER, onMouseOver);
     myGraphic.addEventListener(MouseEvent.ROLL_OUT, onMouseOut);  */
     
     myGraphic.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
     myGraphic.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
     
     //myGraphic.infoWindowRenderer = new ClassFactory(MyDistrictWindowRenderer);     
     myGraphicsLayer.add( myGraphic );
     
    }   
   // myGraphicsLayer.graphicProvider = qryFeatures.features;  
    myGraphicsLayer.symbol = compositeSymbol;
    mainMap.addLayer(myGraphicsLayer);
    
   }
0 Kudos
DasaPaddock
Esri Regular Contributor
In your mouseUp function, try adding:

mainMap.infoWindow.content.data = g.attributes;
0 Kudos
TracySchloss
Frequent Contributor
That generates a coding error

Multiple markers at this line:
-1119: Access of possibly undefined property data through a reference with static type mx.core:UIComponent.
-infoWindow

For some strange reason, the problem I was seeing, where the original graphic that was clicked remembered what it's infoWindowRenderer was from the first click, is no longer a problem.  I hate to mark this thread as resolved, because the suggestions I'd applied earlier (and messed with for several hours!) didn't fix it at the time.  I haven't been in this code for days and today it's decided to work, even though I haven't made any other changes since?!?!?!

Apparently my code is intimidated by your superior knowledge.  :rolleyes:
0 Kudos
DasaPaddock
Esri Regular Contributor
Glad it's working 🙂

If you want to work around the error, use:

import mx.core.IDataRenderer;

.....

IDataRenderer(mainMap.infoWindow.content).data = g.attributes;
0 Kudos