Click or drag to resize

SketchCreationMode Enumeration

Determines the type of geometry and how it will be created by the SketchEditor.

Namespace:  Esri.ArcGISRuntime.UI
Assembly:  Esri.ArcGISRuntime (in Esri.ArcGISRuntime.dll) Version: 100.8.0.0
Syntax
public enum SketchCreationMode
Members
  Member nameValueDescription
Point0 Sketches a MapPoint using AddCommand or tap.
Polyline1 Sketches a Polyline using a series of AddCommand or tap to add vertices.
Polygon2 Sketches a Polygon using a series of AddCommand or tap to add vertices.
Arrow3 Sketches a Polygon in a arrow shape by dragging from initial touch point and letting go to desired size.
Circle4 Sketches a Polygon in an circular shape by dragging from initial touch point and letting go to desired size.
Ellipse5 Sketches a Polygon in an elliptical shape by dragging from initial touch point and letting go to desired size.
Rectangle6 Sketches a Polygon in a screen-aligned rectangle shape by dragging from initial touch point and letting go to desired size.
Triangle7 Sketches a Polygon in an equilateral triangle shape by dragging from initial touch point and letting go to desired size.
FreehandLine8 Sketches a freehand Polyline by dragging from initial touch point and letting go when done.
FreehandPolygon9 Sketches a freehand Polygon by dragging from initial touch point and letting go when done.
Multipoint10 Sketches a Multipoint using a series of AddCommand or tap to add vertices.
Examples

WPF

Example Name: SketchOnMap

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

Code example screen shot.

C#
// Copyright 2017 Esri.
// 
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
// You may obtain a copy of the License at: http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an 
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific 
// language governing permissions and limitations under the License.

using Esri.ArcGISRuntime.Data;
using Esri.ArcGISRuntime.Geometry;
using Esri.ArcGISRuntime.Mapping;
using Esri.ArcGISRuntime.Symbology;
using Esri.ArcGISRuntime.UI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using System.Drawing;
using Point = System.Windows.Point;

namespace ArcGISRuntime.WPF.Samples.SketchOnMap
{
    [ArcGISRuntime.Samples.Shared.Attributes.Sample(
        "Sketch graphics on the map",
        "GraphicsOverlay",
        "This sample demonstrates how to interactively sketch and edit graphics in the map view and display them in a graphics overlay. You can sketch a variety of geometry types and undo or redo operations.",
        "1. Click the 'Sketch' button.\n2. Choose a sketch type from the drop down list.\n3. While sketching, you can undo/redo operations.\n4. Click 'Done' to finish the sketch.\n5. Click 'Edit', then click a graphic to start editing.\n6. Make edits then click 'Done' or 'Cancel' to finish editing.")]
    public partial class SketchOnMap
    {
        // Graphics overlay to host sketch graphics
        private GraphicsOverlay _sketchOverlay;

        public SketchOnMap()
        {
            InitializeComponent();

            // Call a function to set up the map and sketch editor
            Initialize();
        }

        private void Initialize()
        {
            // Create a light gray canvas map
            Map myMap = new Map(Basemap.CreateLightGrayCanvas());

            // Create graphics overlay to display sketch geometry
            _sketchOverlay = new GraphicsOverlay();
            MyMapView.GraphicsOverlays.Add(_sketchOverlay);

            // Assign the map to the MapView
            MyMapView.Map = myMap;

            // Fill the combo box with choices for the sketch modes (shapes)
            SketchModeComboBox.ItemsSource = System.Enum.GetValues(typeof(SketchCreationMode));
            SketchModeComboBox.SelectedIndex = 0;

            // Set the sketch editor as the page's data context
            DataContext = MyMapView.SketchEditor;
        }

        #region Graphic and symbol helpers
        private Graphic CreateGraphic(Esri.ArcGISRuntime.Geometry.Geometry geometry)
        {
            // Create a graphic to display the specified geometry
            Symbol symbol = null;
            switch (geometry.GeometryType)
            {
                // Symbolize with a fill symbol
                case GeometryType.Envelope:
                case GeometryType.Polygon:
                    {
                        symbol = new SimpleFillSymbol()
                        {
                            Color = Color.Red,
                            Style = SimpleFillSymbolStyle.Solid
                        };
                        break;
                    }
                // Symbolize with a line symbol
                case GeometryType.Polyline:
                    {
                        symbol = new SimpleLineSymbol()
                        {
                            Color = Color.Red,
                            Style = SimpleLineSymbolStyle.Solid,
                            Width = 5d
                        };
                        break;
                    }
                // Symbolize with a marker symbol
                case GeometryType.Point:
                case GeometryType.Multipoint:
                    {

                        symbol = new SimpleMarkerSymbol()
                        {
                            Color = Color.Red,
                            Style = SimpleMarkerSymbolStyle.Circle,
                            Size = 15d
                        };
                        break;
                    }
            }

            // pass back a new graphic with the appropriate symbol
            return new Graphic(geometry, symbol);
        }

        private async Task<Graphic> GetGraphicAsync()
        {
            // Wait for the user to click a location on the map
            Geometry mapPoint = await MyMapView.SketchEditor.StartAsync(SketchCreationMode.Point, false);

            // Convert the map point to a screen point
            Point screenCoordinate = MyMapView.LocationToScreen((MapPoint)mapPoint);

            // Identify graphics in the graphics overlay using the point
            IReadOnlyList<IdentifyGraphicsOverlayResult> results = await MyMapView.IdentifyGraphicsOverlaysAsync(screenCoordinate, 2, false);

            // If results were found, get the first graphic
            Graphic graphic = null;
            IdentifyGraphicsOverlayResult idResult = results.FirstOrDefault();
            if (idResult != null && idResult.Graphics.Count > 0)
            { 
                graphic = idResult.Graphics.FirstOrDefault();
            }

            // Return the graphic (or null if none were found)
            return graphic;
        }
        #endregion

        private async void DrawButtonClick(object sender, RoutedEventArgs e)
        {
            try
            {
                // Let the user draw on the map view using the chosen sketch mode
                SketchCreationMode creationMode = (SketchCreationMode)SketchModeComboBox.SelectedItem;
                Esri.ArcGISRuntime.Geometry.Geometry geometry = await MyMapView.SketchEditor.StartAsync(creationMode, true);

                // Create and add a graphic from the geometry the user drew
                Graphic graphic = CreateGraphic(geometry);
                _sketchOverlay.Graphics.Add(graphic);

                // Enable/disable the clear and edit buttons according to whether or not graphics exist in the overlay
                ClearButton.IsEnabled = _sketchOverlay.Graphics.Count > 0;
                EditButton.IsEnabled = _sketchOverlay.Graphics.Count > 0;
            }
            catch (TaskCanceledException)
            {
                // Ignore ... let the user cancel drawing
            }
            catch (Exception ex)
            {
                // Report exceptions
                MessageBox.Show("Error drawing graphic shape: " + ex.Message);
            }
        }

        private void ClearButtonClick(object sender, RoutedEventArgs e)
        {
            // Remove all graphics from the graphics overlay
            _sketchOverlay.Graphics.Clear();

            // Disable buttons that require graphics
            ClearButton.IsEnabled = false;
            EditButton.IsEnabled = false;
        }

        private async void EditButtonClick(object sender, RoutedEventArgs e)
        {
            try
            {
                // Allow the user to select a graphic
                Graphic editGraphic = await GetGraphicAsync();
                if (editGraphic == null) { return; }

                // Let the user make changes to the graphic's geometry, await the result (updated geometry)
                Esri.ArcGISRuntime.Geometry.Geometry newGeometry = await MyMapView.SketchEditor.StartAsync(editGraphic.Geometry);

                // Display the updated geometry in the graphic
                editGraphic.Geometry = newGeometry;
            }
            catch (TaskCanceledException)
            {
                // Ignore ... let the user cancel editing
            }
            catch (Exception ex)
            {
                // Report exceptions
                MessageBox.Show("Error editing shape: " + ex.Message);
            }
        }
    }
}
XAML
<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>
See Also
Additional Examples
Hyperlink to ExampleDescription
CreateAndSaveKmlFileConstruct a KML document and save it as a KMZ file.
FindServiceAreaFind the service area within a network from a given point.
GeodatabaseTransactionsUse transactions to manage how changes are committed to a geodatabase.
SketchOnMapUse the Sketch Editor to edit or sketch a new point, line, or polygon geometry on to a map.