I created a button to select a graphic(points) with polygon extent. What I'd like to do is when it selects points, its attributes are populated in datagrid and highlight corresponding graphic when mouse over on an each item in datagrid.
I got it to work except highlight corresponding graphic from datagrid.
private function doQuery():void { queryTask.execute(query, new AsyncResponder(onResult, onFault)); function onResult(featureSet : FeatureSet, token:Object = null):void { for each(var graphic:Graphic in featureSet.features) { myGraphicsLayer.add(graphic); } } function onFault(info:Object, token:Object = null) : void { Alert.show(info.toString()); } } private function drawEndHandler(event:DrawEvent):void {
var extent:Extent = event.graphic.geometry as Extent; var graphic:Graphic; var results:ArrayCollection = new ArrayCollection; for (var i:Number = 0 ; i < myGraphicsLayer.numChildren ; i++) { graphic = myGraphicsLayer.getChildAt(i) as Graphic; //if point is contained within extent, highlight it and add for display in results list if (extent.contains(MapPoint(graphic.geometry))) { graphic.symbol = highlightedSymbol; results.addItem({CITY_NAME: graphic.attributes.CITY_NAME, STATE_NAME:graphic.attributes.STATE_NAME});
} //else if point was previously highlighted, reset its symbology else if (graphic.symbol == highlightedSymbol) { graphic.symbol = defaultSymbol; } } labelPoints.text = "# of points in extent = " + results.length; dg.visible = true; dg.dataProvider = results;
} //Sync map and datagrid interaction private var highlightedGraphic:Graphic;
private function onItemRollOver(event:ListEvent):void { if (highlightedGraphic) { highlightedGraphic.symbol = resultsSymbol; } highlightedGraphic = findGraphicByAttribute(event.itemRenderer.data) highlightedGraphic.symbol = highlightedSymbol; } private function onItemRollOut(event:ListEvent) : void { findGraphicByAttribute(event.itemRenderer.data).symbol = resultsSymbol; }
public function findGraphicByAttribute(attributes:Object):Graphic { for each( var graphic:Graphic in myGraphicsLayer.graphicProvider) { if (graphic.attributes === attributes) { return graphic; } } return null; }