Sketch on map

View inWPFUWPFormsiOSAndroid
View on GitHub
Sample viewer app

Use the Sketch Editor to edit or sketch a new point, line, or polygon geometry on to a map.

Image of sketch on map

Use case

A field worker could annotate features of interest on a map (via the GUI) such as location of dwellings (marked as points), geological features (polylines), or areas of glaciation (polygons).

How to use the sample

Choose which geometry type to sketch from one of the available buttons. Choose from points, multipoints, polylines, polygons, freehand polylines, and freehand polygons.

Use the control panel to cancel the sketch, undo or redo changes made to the sketch and to save the sketch to the graphics overlay. There is also the option to select a saved graphic and edit its geometry using the Sketch Editor. The graphics overlay can be cleared using the clear all button.

How it works

  1. Use SketchEditor.StartAsync() to start sketching. If editing an existing graphic's geometry, use SketchEditor.StartAsync(graphic.Geometry).
  2. Use the UndoCommand and RedoCommand to undo and redo edits in the sketch.
  3. Use a CompleteCommand to finish the sketch and get the Geometry result. Use the CancelCommand to cancel the sketch.
  4. Create a Graphic for the geometry and add it to the GraphicsOverlay in the map view.

Relevant API

  • Geometry
  • Graphic
  • GraphicsOverlay
  • MapView
  • SketchCreationMode
  • SketchEditor

Tags

draw, edit

Sample Code

SketchOnMap.xamlSketchOnMap.xaml.cs
                                                                                         
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<UserControl x:Class="ArcGISRuntime.WPF.Samples.SketchOnMap.SketchOnMap"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:esri="http://schemas.esri.com/arcgis/runtime/2013"
             mc:Ignorable="d"
             d:DesignHeight="500" d:DesignWidth="600">
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="300"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
        <esri:MapView x:Name="MyMapView"
                      Grid.Column="1"/>
        <Grid Grid.Column="0">
            <Grid.RowDefinitions>
                <RowDefinition Height="50"/>
                <RowDefinition Height="35"/>
                <RowDefinition Height="35"/>
                <RowDefinition Height="35"/>
                <RowDefinition Height="20"/>
                <RowDefinition Height="35"/>
                <RowDefinition Height="35"/>
                <RowDefinition Height="20"/>
                <RowDefinition Height="35"/>
                <RowDefinition Height="35"/>
                <RowDefinition/>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition/>
                <ColumnDefinition/>
            </Grid.ColumnDefinitions>
            <TextBlock Grid.Row="1" Grid.Column="0"
                       HorizontalAlignment="Right" VerticalAlignment="Center"
                       Text="Sketch shape:"/>
            <ComboBox x:Name="SketchModeComboBox"
                      Grid.Row="1" Grid.Column="1"
                      HorizontalAlignment="Stretch" VerticalAlignment="Center"
                      Margin="5"/>
            <Button Grid.Row="2" Grid.Column="1"
                    Content="Draw"
                    Margin="5"
                    Width="100" Height="25"
                    HorizontalAlignment="Center" VerticalAlignment="Top"
                    Click="DrawButtonClick"/>
            <Button x:Name="EditButton"
                    Grid.Row="3" Grid.Column="1"
                    Content="Edit"
                    Margin="5"
                    Width="100" Height="25"
                    HorizontalAlignment="Center" VerticalAlignment="Top"
                    IsEnabled="False"
                    Click="EditButtonClick"/>
            <StackPanel Orientation="Horizontal"
                        HorizontalAlignment="Center" VerticalAlignment="Top"
                        Grid.Row="5" Grid.Column="1">
                <Button Content="Undo"
                        Margin="5"
                        Width="50" Height="25"
                        Command="{Binding UndoCommand}"/>
                <Button Content="Redo"
                        Margin="5"
                        Width="50" Height="25"
                        Command="{Binding RedoCommand}"/>
            </StackPanel>
            <Button Grid.Row="6" Grid.Column="1"
                    Content="Complete"
                    Margin="5"
                    Width="100" Height="25"
                    HorizontalAlignment="Center" VerticalAlignment="Top"
                    Command="{Binding CompleteCommand}"/>
            <Button Grid.Row="8" Grid.Column="1"
                    Content="Cancel"
                    Margin="5"
                    Width="100" Height="25"
                    HorizontalAlignment="Center" VerticalAlignment="Top"
                    Command="{Binding CancelCommand}"/>
            <Button x:Name="ClearButton"
                    Grid.Row="9" Grid.Column="1"
                    Content="Clear"
                    Margin="5"
                    Width="100" Height="25"
                    IsEnabled="False"
                    HorizontalAlignment="Center" VerticalAlignment="Top"
                    Click="ClearButtonClick"/>
        </Grid>
    </Grid>
</UserControl>

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.