Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I would like to programmatically draw a polygon on an ESRI map. I'm using this code to draw a polygon with the mouse but I'm really new to this technology and I'm a little bit lost ... Here is my MainWindow :

public partial class MainWindow : Window
{
    Draw _myDrawObject;
    private GraphicsLayer _graphicsLayer;

    public MainWindow()
    {
        InitializeComponent();
        _myDrawObject = new Draw(esriMap)
                           {
                               FillSymbol = LayoutRoot.Resources["RedFillSymbol"] as FillSymbol
                           };

        _myDrawObject.DrawComplete += MyDrawObjectDrawComplete;
    }

    private void EsriMapMouseClick(object sender, Map.MouseEventArgs e)
    {
        _myDrawObject.DrawMode = DrawMode.Polygon;
        _myDrawObject.IsEnabled = true;
    }

    private void MyDrawObjectDrawComplete(object sender, ESRI.ArcGIS.Client.DrawEventArgs args)
    {

        var graphic = new Graphic()
                              {
                                  Geometry = args.Geometry,
                                  Symbol = LayoutRoot.Resources["BlueFillSymbol"] as FillSymbol
                              };

        _graphicsLayer = esriMap.Layers["MyGraphicsLayer"] as GraphicsLayer;

        if (_graphicsLayer != null)
            _graphicsLayer.Graphics.Add(graphic);

    }

I already went to the ArcGIS help site (http://resources.arcgis.com/content/web-based-help) but i can't find the solution. Any ideas or tips ?

Feel free to ask me some questions if you want more details!

share
3  
The sample at help.arcgis.com/en/webapi/silverlight/samples/… seems to do exactly what you're asking. –  Brandon Copeland Nov 18 '11 at 15:39
    
Very helpfull comment! Big thanks Brandon! –  Gun Nov 21 '11 at 9:19
    
Brandon: make your comment and answer, then the answer can be upvoted and accepted. –  johanvdw Jul 9 '12 at 8:03

1 Answer 1

If you installed the WPF SDK in the normal location, you can go to this folder and find an interactive sample application:

C:\ArcGIS\WPF1.0\SDK\Samples\Sample Application\Sample Application.exe

There is a list of demo categories on the left, so expand the Editing group. And then inside that are two more groups: Edit Controls and Edit Tools.

Look at the Edit Tools - Auto Save example. There are tabs on the example so you can switch between Live Sample/XAML/Code Behind. Copy and paste into your own project, and you will have a working example. Then you can customize or edit as needed.

share

This site is currently not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .