schoolradius

how do i buffer on button click.

Discussion created by schoolradius on Apr 4, 2011
i was wondering if i could get some assistance here,currently im able to buffer in the map,but i want it to be done only upon clicking on a button,i tried putting the codes in the button itself but it dosent work,i appreciate if someone could reply to my post.

protected void BUTTON_TEST(object sender, RoutedEventArgs e)
{
GraphicsLayer graphicsLayer = MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer;
graphicsLayer.ClearGraphics();

e.MapPoint.SpatialReference = MyMap.SpatialReference;
Graphic graphic = new ESRI.ArcGIS.Client.Graphic()
{
Geometry = e.MapPoint,
Symbol = LayoutRoot.Resources["DefaultClickSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol
};
graphic.SetZIndex(1);
graphicsLayer.Graphics.Add(graphic);

GeometryService geometryService =
new GeometryService("http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer");
geometryService.BufferCompleted += GeometryService_BufferCompleted;
geometryService.Failed += GeometryService_Failed;

// If buffer spatial reference is GCS and unit is linear, geometry service will do geodesic buffering
BufferParameters bufferParams = new BufferParameters()
{
//Unit = LinearUnit.StatuteMile,
Unit = LinearUnit.Kilometer,
BufferSpatialReference = new SpatialReference(4326),
OutSpatialReference = MyMap.SpatialReference
};
bufferParams.Features.Add(graphic);
bufferParams.Distances.Add(500);

geometryService.BufferAsync(bufferParams);
}

void GeometryService_BufferCompleted(object sender, GraphicsEventArgs args)
{
IList<Graphic> results = args.Results;
GraphicsLayer graphicsLayer = MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer;

foreach (Graphic graphic in results)
{
graphic.Symbol = LayoutRoot.Resources["DefaultBufferSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol;
graphicsLayer.Graphics.Add(graphic);
}
}

private void GeometryService_Failed(object sender, TaskFailedEventArgs e)
{
MessageBox.Show("Geometry Service error: " + e.Error);
}

Outcomes