Sketch on map

View on GitHub

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.xamlSketchOnMap.xaml.cs
Use dark colors for code blocksCopy
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
<UserControl
    x:Class="ArcGIS.UWP.Samples.SketchOnMap.SketchOnMap"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:esriUI="using:Esri.ArcGISRuntime.UI.Controls">
    <Grid>
        <esriUI:MapView x:Name="MyMapView" />
        <CommandBar OverflowButtonVisibility="Collapsed">
            <AppBarButton AllowFocusOnInteraction="True">
                <AppBarButton.Content>
                    <TextBlock HorizontalAlignment="Center" Text="Draw/Edit" />
                </AppBarButton.Content>
                <AppBarButton.Flyout>
                    <Flyout x:Name="DrawToolsFlyout">
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="5" />
                                <RowDefinition Height="35" />
                                <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"
                                FontSize="12"
                                Text="Sketch shape:" />
                            <ComboBox
                                x:Name="SketchModeComboBox"
                                Grid.Row="1"
                                Grid.Column="1"
                                Margin="2"
                                HorizontalAlignment="Stretch"
                                VerticalAlignment="Center"
                                FontSize="12" />
                            <Button
                                Grid.Row="2"
                                Grid.Column="1"
                                Width="100"
                                Height="30"
                                Margin="2"
                                HorizontalAlignment="Center"
                                VerticalAlignment="Top"
                                Click="DrawButtonClick"
                                Content="Draw"
                                FontSize="12" />
                            <Button
                                x:Name="EditButton"
                                Grid.Row="3"
                                Grid.Column="1"
                                Width="100"
                                Height="30"
                                Margin="2"
                                HorizontalAlignment="Center"
                                VerticalAlignment="Top"
                                Click="EditButtonClick"
                                Content="Edit"
                                FontSize="12"
                                IsEnabled="False" />
                        </Grid>
                    </Flyout>
                </AppBarButton.Flyout>
            </AppBarButton>
            <AppBarButton Command="{Binding UndoCommand}">
                <AppBarButton.Content>
                    <TextBlock HorizontalAlignment="Center" Text="Undo" />
                </AppBarButton.Content>
            </AppBarButton>
            <AppBarButton Command="{Binding RedoCommand}">
                <AppBarButton.Content>
                    <TextBlock HorizontalAlignment="Center" Text="Redo" />
                </AppBarButton.Content>
            </AppBarButton>
            <AppBarButton Command="{Binding CompleteCommand}">
                <AppBarButton.Content>
                    <TextBlock HorizontalAlignment="Center" Text="Complete" />
                </AppBarButton.Content>
            </AppBarButton>
            <AppBarButton x:Name="ClearButton" Click="ClearButtonClick">
                <AppBarButton.Content>
                    <TextBlock HorizontalAlignment="Center" Text="Clear" />
                </AppBarButton.Content>
            </AppBarButton>
        </CommandBar>
    </Grid>
</UserControl>

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