Sketch on map

View inWPFWinUIUWPFormsiOSAndroid
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, freehand polygons, circles, ellipses, triangles, arrows and rectangles.

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
Use dark colors for code blocks
                                                                                                                                                                    
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
<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:esri="http://schemas.esri.com/arcgis/runtime/2013">
    <Grid>
        <esri:MapView x:Name="MyMapView" />
        <Grid Grid.Column="1"
              Margin="0,5,5,0"
              HorizontalAlignment="Right"
              VerticalAlignment="Top">
            <Grid.RowDefinitions>
                <RowDefinition Height="auto" />
                <RowDefinition Height="auto" />
                <RowDefinition Height="auto" />
                <RowDefinition Height="auto" />
                <RowDefinition Height="auto" />
                <RowDefinition Height="auto" />
                <RowDefinition Height="auto" />
                <RowDefinition Height="auto" />
                <RowDefinition Height="auto" />
                <RowDefinition Height="auto" />
                <RowDefinition Height="auto" />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="auto" />
                <ColumnDefinition Width="auto" />
            </Grid.ColumnDefinitions>
            <Button x:Name="EditButton"
                    Grid.Row="0"
                    Grid.Column="0"
                    Click="EditButtonClick"
                    ToolTip="Edit">
                <Image Source="resources/edit.png" />
            </Button>
            <Button x:Name="StopButton"
                    Grid.Row="0"
                    Grid.Column="1"
                    Command="{Binding CancelCommand}"
                    ToolTip="Cancel">
                <Image Source="resources/clear.png" />
            </Button>
            <Button x:Name="PointButton"
                    Grid.Row="2"
                    Grid.Column="0"
                    Margin="0,5,0,0"
                    Click="ShapeClick"
                    CommandParameter="Point"
                    ToolTip="Point">
                <Image Source="resources/point.png" />
            </Button>
            <Button x:Name="MultipointButton"
                    Grid.Row="2"
                    Grid.Column="1"
                    Margin="0,5,0,0"
                    Click="ShapeClick"
                    CommandParameter="Multipoint"
                    ToolTip="Multipoint">
                <Image Source="resources/multipoint.png" />
            </Button>
            <Button x:Name="PolylineButton"
                    Grid.Row="3"
                    Grid.Column="0"
                    Click="ShapeClick"
                    CommandParameter="Polyline"
                    ToolTip="Polyline">
                <Image Source="resources/polyline.png" />
            </Button>
            <Button x:Name="PolygonButton"
                    Grid.Row="3"
                    Grid.Column="1"
                    Click="ShapeClick"
                    CommandParameter="Polygon"
                    ToolTip="Polygon">
                <Image Source="resources/polygon.png" />
            </Button>
            <Button x:Name="FreehandPolylineButton"
                    Grid.Row="4"
                    Grid.Column="0"
                    Click="ShapeClick"
                    CommandParameter="FreehandLine"
                    ToolTip="Freehand Polyline">
                <Image Source="resources/freehand-polyline.png" />
            </Button>
            <Button x:Name="FreehandPolygonButton"
                    Grid.Row="4"
                    Grid.Column="1"
                    Click="ShapeClick"
                    CommandParameter="FreehandPolygon"
                    ToolTip="Freehand Polygon">
                <Image Source="resources/brush.png" />
            </Button>
            <Button x:Name="CircleButton"
                    Grid.Row="5"
                    Grid.Column="0"
                    Click="ShapeClick"
                    CommandParameter="Circle"
                    ToolTip="Circle">
                <Image Source="resources/circle.png" />
            </Button>
            <Button x:Name="EllipseButton"
                    Grid.Row="5"
                    Grid.Column="1"
                    Click="ShapeClick"
                    CommandParameter="Ellipse"
                    ToolTip="Ellipse">
                <Image Source="resources/ellipse.png" />
            </Button>
            <Button x:Name="TriangleButton"
                    Grid.Row="6"
                    Grid.Column="0"
                    Click="ShapeClick"
                    CommandParameter="Triangle"
                    ToolTip="Triangle">
                <Image Source="resources/triangle.png" />
            </Button>
            <Button x:Name="ArrowButton"
                    Grid.Row="6"
                    Grid.Column="1"
                    Click="ShapeClick"
                    CommandParameter="Arrow"
                    ToolTip="Arrow">
                <Image Source="resources/arrow.png" />
            </Button>
            <Button x:Name="RectangleButton"
                    Grid.Row="7"
                    Grid.Column="0"
                    Click="ShapeClick"
                    CommandParameter="Rectangle"
                    ToolTip="Rectangle">
                <Image Source="resources/rectangle.png" />
            </Button>
            <Button x:Name="UndoButton"
                    Grid.Row="8"
                    Grid.Column="0"
                    Margin="0,5,0,0"
                    Command="{Binding UndoCommand}"
                    ToolTip="Undo">
                <Image Source="resources/undo.png" />
            </Button>
            <Button x:Name="RedoButton"
                    Grid.Row="8"
                    Grid.Column="1"
                    Margin="0,5,0,0"
                    Command="{Binding RedoCommand}"
                    ToolTip="Redo">
                <Image Source="resources/redo.png" />
            </Button>
            <Button x:Name="SaveButton"
                    Grid.Row="9"
                    Grid.Column="0"
                    Command="{Binding CompleteCommand}"
                    ToolTip="Save">
                <Image Source="resources/save.png" />
            </Button>
            <Button x:Name="ClearButton"
                    Grid.Row="9"
                    Grid.Column="1"
                    Click="ClearButtonClick"
                    ToolTip="Clear">
                <Image Source="resources/trash-can-outline.png" />
            </Button>
        </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.