[Bindable] public var myCountyWindowRenderer:ClassFactory = new ClassFactory(MyCountyWindowRenderer);
private function onDG_ItemClick():void { mainMap.infoWindow.styleName = "myInfoWindow"; mainMap.infoWindow.closeButtonVisible=true; var obj:Object = this.selectedItem; var clickGraphic:Graphic = findGraphicByAttribute(obj); mainMap.infoWindow.content = myCountyWindowRenderer.newInstance(); mainMap.infoWindow.data = obj; mainMap.infoWindow.show( MapPoint(clickGraphic.geometry.extent.center) ); }
<?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.*" xmlns:esri="http://www.esri.com/2008/ags" > <fx:Declarations> <mx:NumberFormatter id="pctFormatter" precision="2" useNegativeSign="true" rounding="nearest" /> <mx:NumberFormatter id="wholeNumberFormatter" precision="0" useNegativeSign="true" rounding="nearest" /> </fx:Declarations> <supportClasses:InfoWindowLabel text="{data.NAME2}" width="150%" /> <s:Label id="lbl1_crop2002" text="Acres Treated: {wholeNumberFormatter.format(data.CROP_2002_ACRES_TREATED)}"/> <s:Label id="lbl2_crop2002" text="Sq. Miles Treated: {data.CROP_2002_SQMILES_TREATED}"/> <s:Label id="lbl3_crop2002" text="Percent Area Treated: {pctFormatter.format(data.CROP_2002_PCTAREATREATED)}%"/> <s:Label id="lbl4_crop2002" text="Percent Inc/Dec 2002-2007: {pctFormatter.format(data.CROP_PCT_INCDEC_2002_2007)}%"/> </mx:VBox>On the map, for the graphic's mouse click event, I then ended up checking to see what type of data I was displaying and setting the infoWindowRenderer for each graphic. Cludgy, but it works:
switch (category){ case "CROP": if (yearValue == "2002") { myGraphic.infoWindowRenderer = new ClassFactory(InfoWindow_crop2002); //var infoWindowRenderer:ClassFactory = new ClassFactory(InfoWindow_crop2002); }else { myGraphic.infoWindowRenderer = new ClassFactory(InfoWindow_crop2007); } break; case "PAST": if (yearValue == "2002") { myGraphic.infoWindowRenderer = new ClassFactory(InfoWindow_past2002); }else { myGraphic.infoWindowRenderer = new ClassFactory(InfoWindow_past2007); } break; case "SOIL": if (yearValue == "2002") { myGraphic.infoWindowRenderer = new ClassFactory(InfoWindow_soil2002); }else { myGraphic.infoWindowRenderer = new ClassFactory(InfoWindow_soil2007); } break; case "WEED": if (yearValue == "2002") { myGraphic.infoWindowRenderer = new ClassFactory(InfoWindow_weed2002); }else { myGraphic.infoWindowRenderer = new ClassFactory(InfoWindow_weed2007); } break; }
Solved! Go to Solution.
private function showInfoWindow(mapPoint:MapPoint, data:Object):void { var infoWindow:LabelDataRenderer; switch (data.CATEGORY) { case "CROP": infoWindow = new CropInfoWindow; break; case "SOIL": infoWindow = new SoilInfoWindow; break; case "WEED": infoWindow = new WeedInfoWindow; break; } infoWindow.data = data; myMap.infoWindowContent = infoWindow; myMap.infoWindow.show(mapPoint); }
override public function set data(value:Object):void { super.data = value; if (this.initialized) { //component is initialised. updateData(); } else { //need to wait for the component to initialise. //If it is not initialised, all the label controls etc will be null. this.removeEventListener(FlexEvent.INITIALIZE, init_completeHandler) this.addEventListener(FlexEvent.INITIALIZE, init_completeHandler); } } private function init_completeHandler(event:FlexEvent):void { //component is now initialised and the label control values can be set. updateData(); }
private function showInfoWindow(mapPoint:MapPoint, data:Object):void { var infoWindow:LabelDataRenderer; switch (data.CATEGORY) { case "CROP": infoWindow = new CropInfoWindow; break; case "SOIL": infoWindow = new SoilInfoWindow; break; case "WEED": infoWindow = new WeedInfoWindow; break; } infoWindow.data = data; myMap.infoWindowContent = infoWindow; myMap.infoWindow.show(mapPoint); }
override public function set data(value:Object):void { super.data = value; if (this.initialized) { //component is initialised. updateData(); } else { //need to wait for the component to initialise. //If it is not initialised, all the label controls etc will be null. this.removeEventListener(FlexEvent.INITIALIZE, init_completeHandler) this.addEventListener(FlexEvent.INITIALIZE, init_completeHandler); } } private function init_completeHandler(event:FlexEvent):void { //component is now initialised and the label control values can be set. updateData(); }