shimon31, Not seeing all your code it is hard to say where you are going wrong. Here is some code to handle points, lines and polygons.add this import:import mx.events.ListEvent;
add these new functions:private function findGraphicByAttribute(attributes:Object):Graphic
{
for each( var graphic:Graphic in mqGraphicsLayer.graphicProvider)
{
if ( graphic.attributes === attributes)
{
return graphic;
}
}
return null;
}
private function onItemClick(event:ListEvent):void
{
var gra:Graphic = findGraphicByAttribute(event.itemRenderer.data);
var pt:MapPoint = null;
var sIcon:String="";
if (gra.geometry is MapPoint){
pt = gra.geometry as MapPoint;
if (map.scale > 5000)
map.scale = 5000;
map.centerAt(pt);
} else if (gra.geometry is Polygon) {
pt = new MapPoint();
pt.x = (gra.geometry.extent.xmax + gra.geometry.extent.xmin) / 2
pt.y = (gra.geometry.extent.ymax + gra.geometry.extent.ymin) / 2
sIcon = ICON_URL + "i_info.png";
map.extent = gra.geometry.extent;
} else if (gra.geometry is Polyline){
var polyline:Polyline = gra.geometry as Polyline;
pt = polyline.extent.center;
sIcon = ICON_URL + "i_info.png";
map.extent = gra.geometry.extent;
}
if (pt != null){
var sContent:String = "";
var obj:Object = gra.attributes
var fld:String;
var value:String;
for (fld in obj)
{
value = obj[fld].toString();
sContent = (sContent.length == 0)? fld + " = " + value + "<br/>" :
sContent + fld + " = " + value + "<br/>";
}
var infoData:Object =
{
icon : sIcon,
content: sContent,
point: pt,
link: ""
};
this.showInfoWindow(infoData);
}
}
Change the datagrid:<mx:DataGrid id="QBData" width="100%" height="100%" itemClick="onItemClick(event)" />