I'm trying to union or append graphics into one graphic. Can it be done? Or should I try a different way?I want to allow the user to draw a polygon on the screen and select the parcels that intersect the polygon. Then I want to take all the parcels and buffer them. Here's my code:/* Required with a DrawEnd event.*/
private function onDrawEnd(event:DrawEvent):void
{
var graphic:Graphic = event.graphic;
// adding graphic to the graphics layer
myGraphicsLayer.add(graphic);
var geometryPolygon:Polygon = graphic.geometry as Polygon;
myMap.centerAt(geometryPolygon.extent.center);
// select parcels contained or crossed by drawn polygon
findParcels(graphic);
}
private function findParcels(graphic:Graphic):void
{
// clear the graphics layer
myGraphicsLayer.clear();
// Create query to select parcels that intersect drawn shape
var parcelQuery : Query = new Query();
parcelQuery.returnGeometry = true;
parcelQuery.geometry = graphic.geometry;
parcelQuery.spatialRelationship = "esriSpatialRelIntersects";
parcelQuery.outSpatialReference = myMap.spatialReference;
parcelQueryTask.execute( parcelQuery, new AsyncResponder( onParcelResult, onParcelFault ));
function onParcelResult( featureSet : FeatureSet, token : Object = null ) : void
{
if (featureSet.features.length != 0)
{
var unionExtent : Extent;
var myFirstGraphic : Graphic = featureSet.features[0];
unionExtent = Polygon(myFirstGraphic.geometry).extent;
for each (var myGraphic : Graphic in featureSet.features)
{
myGraphic.symbol = (sfs);
myGraphicsLayer.add(myGraphic);
// THINK I NEED TO ADD SOMETHING HERE TO APPEND ALL GRAPHICS IN FEATURESET INTO ONE GRAPHIC THAT CAN BE USED BY BUFFER FUNCTION.
// Adds parcel number and address as tool tip
myGraphic.toolTip = "Parcel: " + myGraphic.attributes.PARCEL.toString()
+ "\nAddress: " + myGraphic.attributes.STRNO + " "
+ myGraphic.attributes.STRDIR + " "
+ myGraphic.attributes.STRNAME + " "
+ myGraphic.attributes.STRTYPE;
// Expand extent
unionExtent = unionExtent.union(Polygon(myGraphic.geometry).extent );
}
// Zoom map out a bit
myMap.extent = unionExtent.expand(6);
}
else
{
Alert.show("Error selecting parcels");
}
}
function onParcelFault( info : Object, token : Object = null ) : void
{
Alert.show( info.toString() );
}
}
private function bufferFeature():void
{
var bufferParameters:BufferParameters = new BufferParameters();
bufferParameters.features = [graphicParcels];
bufferParameters.distances = [ 500 ];
bufferParameters.unit = BufferParameters.UNIT_FOOT;
bufferParameters.bufferSpatialReference = new SpatialReference(32007);
myGeometryService.addEventListener(GeometryServiceEvent.BUFFER_COMPLETE, bufferCompleteHandler1);
myGeometryService.buffer(bufferParameters);
function bufferCompleteHandler1(event:GeometryServiceEvent):void
{
for each (var graphic:Graphic in event.graphics)
{
graphic.symbol = sfs;
graphic.toolTip = "Buffered Stuff";
myGraphicsLayer.add(graphic);
}
myGeometryService.removeEventListener(GeometryServiceEvent.BUFFER_COMPLETE, bufferCompleteHandler1);
}
}