Sketch on map

View inAndroidFormsUWPWPFWinUIiOSView 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, 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.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
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage x:Class="ArcGISRuntime.Samples.SketchOnMap.SketchOnMap"
             xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:esriUI="clr-namespace:Esri.ArcGISRuntime.Xamarin.Forms;assembly=Esri.ArcGISRuntime.Xamarin.Forms">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition />
            <RowDefinition Height="70" />
        </Grid.RowDefinitions>
        <esriUI:MapView x:Name="MyMapView" Grid.Row="0" />
        <Grid x:Name="DrawToolsGrid"
              Grid.Row="0"
              BackgroundColor="White"
              HorizontalOptions="Center"
              IsVisible="False"
              VerticalOptions="Start"
              WidthRequest="280">
            <Grid.RowDefinitions>
                <RowDefinition Height="50" />
                <RowDefinition Height="40" />
                <RowDefinition />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition />
                <ColumnDefinition />
            </Grid.ColumnDefinitions>
            <Label Grid.Row="0"
                   Grid.Column="0"
                   HorizontalOptions="End"
                   Text="Sketch shape:"
                   VerticalOptions="Center" />
            <Picker x:Name="SketchModePicker"
                    Grid.Row="0"
                    Grid.Column="1"
                    HorizontalOptions="Fill"
                    VerticalOptions="CenterAndExpand" />
            <Button Grid.Row="1"
                    Grid.Column="1"
                    Clicked="StartSketch"
                    HeightRequest="35"
                    HorizontalOptions="Center"
                    Text="✍️"
                    VerticalOptions="Start"
                    WidthRequest="100" />
            <Button x:Name="EditButton"
                    Grid.Row="1"
                    Grid.Column="0"
                    Clicked="EditButtonClick"
                    HeightRequest="35"
                    HorizontalOptions="Center"
                    IsEnabled="False"
                    Text="⚒️"
                    VerticalOptions="Start"
                    WidthRequest="100" />
        </Grid>
        <Grid Grid.Row="1">
            <Grid.ColumnDefinitions>
                <ColumnDefinition />
                <ColumnDefinition />
                <ColumnDefinition />
                <ColumnDefinition />
                <ColumnDefinition />
            </Grid.ColumnDefinitions>
            <Button x:Name="DrawEditButton"
                    Grid.Column="0"
                    Clicked="ShowDrawTools"
                    Text="Sketch" />
            <Button x:Name="UndoButton"
                    Grid.Column="1"
                    Text="↩️" />
            <Button x:Name="RedoButton"
                    Grid.Column="2"
                    Text="↪️" />
            <Button x:Name="CompleteButton"
                    Grid.Column="3"
                    Text="✔️" />
            <Button x:Name="ClearButton"
                    Grid.Column="4"
                    Clicked="ClearButtonClick"
                    IsEnabled="False"
                    Text="🗑" />
        </Grid>
    </Grid>
</ContentPage>

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