Select to view content in your preferred language

Buffer around a point with button

1248
5
04-03-2011 07:03 PM
SchoolRadius
Emerging Contributor
Hi, I'm trying to create a buffer around a school and i only want the buffer to come out when i click a button from the pop up menu of the school, I already have the pop up menu and the map, what i need is to know how to capture the x,y coordinates of the school and how to subsequently draw a buffer around the school. Any ideas?
0 Kudos
5 Replies
DominiqueBroux
Esri Frequent Contributor

i need is to know how to capture the x,y coordinates of the school

If you have a popup menu of the school, it probably means that the school is a graphic. You can get the x and y  of a graphic by using the geometry:
     x = (graphic.Geometry as MapPoint).X;
     y = (graphic.Geometry as MapPoint).Y;


how to subsequently draw a buffer around the school

You can add a graphic having a Polygon geometry initialized to a circle around the school (circle to approximate by a polyline around the school).
0 Kudos
SchoolRadius
Emerging Contributor
Thanks for the pointers Dominque but i still do not really understand it fully, these are my codes for the button, there are errors when I key it in, any ideas where I went wrong or what am I missing?

protected void Buffer2Button(object sender, RoutedEventArgs e)
        {
            x = (graphic.Geometry as MapPoint).X;
            y = (graphic.Geometry as MapPoint).Y;
            GraphicsLayer graphicsLayer = MyMap.Layers["MyGraphicsLayer_Buffer"] as GraphicsLayer;
            graphicsLayer.ClearGraphics();

            e.MapPoint.SpatialReference = MyMap.SpatialReference;
            Graphic graphic = new ESRI.ArcGIS.Client.Graphic()
            {
                Geometry = e.MapPoint,
                Symbol = LayoutRoot.Resources["DefaultBufferSymbol"] 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;


          BufferParameters bufferParams = new BufferParameters()
          {
              Unit = LinearUnit.Kilometer,
              BufferSpatialReference = new SpatialReference(4326),
              OutSpatialReference = MyMap.SpatialReference
          };
          bufferParams.Features.Add(graphic);
          bufferParams.Distances.Add(2);

          geometryService.BufferAsync(bufferParams);
      }
0 Kudos
SchoolRadius
Emerging Contributor
Also when I enter this into my codes, I keep getting an error that says "the name graphic does not exist in the current context"

string axisX = (graphic.Geometry as MapPoint).X;
string axisY = (graphic.Geometry as MapPoint).Y;
0 Kudos
DominiqueBroux
Esri Frequent Contributor
I was supposing that you were using a GraphicsLayer or FeatureLayer to display your school.

Is it the case?

If it's the case, the graphic variable have to be initialized with the graphic of your school (either by an user interaction such as a click or by code filtering the graphics of your graphicslayer by attribute).
0 Kudos
SchoolRadius
Emerging Contributor
I am using a graphicLayer for my school and it is initialized with a button but how do I carry on and draw a buffer?

p.s. sorry I'm quite lost, I'm new to this
0 Kudos