In my application I have a combo box with a list of types of facilities. When the user picks one from the list a query is run that selects all facilities for that type and populates a datagrid. It then zooms to the extent of all facilities. When the user mouses over the datagrid the facility is highlighted with an infowindow.I have the following code which works perfectly with polygons. But the polygons are small and don't appear when zoomed out. So I want to add a pointmarker to the graphics layer for each polygon. When I add the point my code doesn't work...only the FIRST polygon added responds to the mouseover. I've tried adding the point graphic first but then nothing responds to the mouseover. Any help would be appreciated.
function onResult( featureSet : FeatureSet, token : Object = null ) : void
{
if (featureSet.features.length == 0)
{
Alert.show("No facilities found.");
}
else
{
// Clear previous selection
myGraphicsLayer.clear();
var selectedExtent : Extent;
var g1:Graphic = featureSet.features[0];
var pms:PictureMarkerSymbol = new PictureMarkerSymbol(PushPinIcon, 60, 60);
var pnt:MapPoint;
selectedExtent = Polygon(g1.geometry).extent;
for each (var g:Graphic in featureSet.features)
{
g.symbol = (sfs);
// Adds facility name and address as tool tip
g.toolTip = "Facility Name: " + g.attributes.FACILITY + "\nAddress: " + g.attributes.ADDRESS;
g.autoMoveToTop = true;
// Add graphic to graphics layer
myGraphicsLayer.add(g);
// Add listeners so mouse over the map will highlight parcel in datagrid
g.addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
g.addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
// update extent of selected facilities
selectedExtent = selectedExtent.union(Polygon(g.geometry).extent);
// EVERYTHING WORKS IF I COMMENT OUT THE FOLLOWING SECTION
// Add point marker
pnt = new MapPoint(g.geometry.extent.center.x, g.geometry.extent.center.y,
MainMap.spatialReference);
var myGraphicPic:Graphic = new Graphic(pnt);
myGraphicPic.symbol = pms;
myGraphicsLayer.add(myGraphicPic);
}
// Zoom to extent of all facilities
MainMap.extent = selectedExtent.expand(2);
}
}
// Highlight facility on map as user moves mouse over datagrid
private function onItemRollOver(event:ListEvent):void
{
var g:Graphic = findGraphicByAttribute(event.itemRenderer.data);
g.symbol = highlightSymbol;
// Move graphic to top so highlight symbol is visible
myGraphicsLayer.moveToTop(g);
// Info for pop-up
mapPoint = new MapPoint( g.geometry.extent.center.x, g.geometry.extent.center.y, MainMap.spatialReference );
myInfoWin.facility = event.itemRenderer.data["FACILITY"];
myInfoWin.address = event.itemRenderer.data["ADDRESS"];
MainMap.infoWindow.content = myInfoWin;
MainMap.infoWindow.labelVisible = false;
MainMap.infoWindow.closeButtonVisible = false;
MainMap.infoWindow.show(mapPoint);
// to zoom to select record in datagrid
//MainMap.extent = g.geometry.extent.expand(2);
}
// Find the graphic on the map for the row highlighted in datagrid
private function findGraphicByAttribute(attributes:Object):Graphic
{
for each (var graphic:Graphic in myGraphicsLayer.graphicProvider)
{
if (graphic.attributes["FACILITY"] == attributes["FACILITY"])
{
return graphic;
}
}
return null;
}