View in MAUI WPF WinUI UWP View on GitHub

Use the Geometry Editor to edit a geometry and align it to existing geometries on a map.

Image of Snap geometry edits

Use case

A field worker can create new features by editing and snapping the vertices of a geometry to existing features on a map. In a water distribution network, service line features can be represented with the polyline geometry type. By snapping the vertices of a proposed service line to existing features in the network, an exact footprint can be identified to show the path of the service line and what features in the network it connects to. The feature layer containing the service lines can then be accurately modified to include the proposed line.

How to use the sample

To create a geometry, press the create button to choose the geometry type you want to create (i.e. points, multipoints, polyline, or polygon) and interactively tap and drag on the map view to create the geometry.

Snap settings can be configured by enabling and disabling snapping, feature snapping, geometry guides and snap sources.

To interactively snap a vertex to a feature or graphic, ensure that snapping is enabled for the relevant snap source and move the mouse pointer or drag a vertex to nearby an existing feature or graphic. When the pointer is close to that existing geoelement, the edit position will be adjusted to coincide with (or snap to), edges and vertices of its geometry. Click or release the touch pointer to place the vertex at the snapped location.

To edit a geometry, tap the geometry to be edited in the map to select it and then edit the geometry by tapping and dragging its vertices and snapping them to nearby features or graphics.

To undo changes made to the geometry, press the undo button.

To delete a geometry or a vertex, tap the geometry or vertex to select it and then press the delete button.

To save your edits, press the save button.

How it works

  1. Create a Map from the URL and connect it to the MapView.
  2. Set the map’s LoadSettings.FeatureTilingMode to EnabledWithFullResolutionWhenSupported.
  3. Create a GeometryEditor and connect it to the map view.
  4. Call SyncSourceSettings after the map’s operational layers are loaded and the geometry editor has connected to the map view.
  5. Set SnapSettings.IsEnabled and SnapSourceSettings.IsEnabled to true for the SnapSource of interest.
  6. Toggle geometry guides using SnapSettings.IsGeometryGuidesEnabled and feature snapping using SnapSettings.IsFeatureSnappingEnabled.
  7. Start the geometry editor with a GeometryType.

Relevant API

  • FeatureLayer
  • Geometry
  • GeometryEditor
  • GeometryEditorStyle
  • GraphicsOverlay
  • MapView
  • SnapSettings
  • SnapSource
  • SnapSourceSettings

About the data

The Naperville water distribution network is based on ArcGIS Solutions for Water Utilities and provides a realistic depiction of a theoretical stormwater network.

Additional information

Snapping is used to maintain data integrity between different sources of data when editing, so it is important that each SnapSource provides full resolution geometries to be valid for snapping. This means that some of the default optimizations used to improve the efficiency of data transfer and display of polygon and polyline layers based on feature services are not appropriate for use with snapping.

To snap to polygon and polyline layers, the recommended approach is to set the FeatureLayer’s feature tiling mode to FeatureTilingMode.EnabledWithFullResolutionWhenSupported and use the default ServiceFeatureTable feature request mode FeatureRequestMode.OnInteractionCache. Local data sources, such as geodatabases, always provide full resolution geometries. Point and multipoint feature layers are also always full resolution.

Snapping can be used during interactive edits that move existing vertices using the VertexTool or ReticleVertexTool. It is also supported for adding new vertices for input devices with a hover event (such as a mouse move without a mouse button press). Using the ReticleVertexTool to add and move vertices allows users of touch screen devices to clearly see the visual cues for snapping.

Geometry guides are enabled by default when snapping is enabled. These allow for snapping to a point coinciding with, parallel to, perpendicular to or extending an existing geometry.

On supported platforms haptic feedback on SnapState.SnappedToFeature and SnapState.SnappedToGeometryGuide is enabled by default when snapping is enabled. Custom haptic feedback can be configured by setting SnapSettings.IsHapticFeedbackEnabled to false and listening to GeometryEditor.SnapChanged events to provide specific feedback depending on the SnapState.

When using SubtypeFeatureLayer objects as snap sources instead of FeatureLayer, child SubtypeSublayer objects are included as snap sources in the parent SnapSourceSettings.ChildSnapSources collection in the same order as the SubtypeFeatureLayer.SubtypeSublayers collection.

Tags

edit, feature, geometry editor, graphics, layers, map, snapping

Sample Code

SnapGeometryEdits.xaml SnapGeometryEdits.xaml SnapGeometryEdits.xaml.cs
<UserControl x:Class="ArcGIS.WPF.Samples.SnapGeometryEdits.SnapGeometryEdits"
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">
<UserControl.Resources>
<DataTemplate x:Key="SnapSettingTemplate">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0"
Width="150"
Text="{Binding Path=Name}" />
<CheckBox Grid.Column="1" IsChecked="{Binding Path=IsEnabled}" />
</Grid>
</DataTemplate>
<Style x:Key="ButtonIconStyle" TargetType="Button">
<Style.Setters>
<Setter Property="FontFamily" Value="{StaticResource CalciteUIIconsMediumFontFamily}" />
<Setter Property="FontSize" Value="24" />
<Setter Property="Background" Value="White" />
<Setter Property="HorizontalAlignment" Value="Stretch" />
<Setter Property="Padding" Value="3" />
<Setter Property="Margin" Value="3" />
</Style.Setters>
<Style.Triggers>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Opacity" Value="0.8" />
</Trigger>
</Style.Triggers>
</Style>
<Style x:Key="ToggleButtonIconStyle" TargetType="ToggleButton">
<Style.Setters>
<Setter Property="FontFamily" Value="{StaticResource CalciteUIIconsMediumFontFamily}" />
<Setter Property="FontSize" Value="24" />
<Setter Property="Background" Value="White" />
<Setter Property="HorizontalAlignment" Value="Stretch" />
<Setter Property="Padding" Value="3" />
<Setter Property="Margin" Value="3" />
</Style.Setters>
<Style.Triggers>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Opacity" Value="0.8" />
</Trigger>
</Style.Triggers>
</Style>
</UserControl.Resources>
<Grid>
<esri:MapView x:Name="MyMapView" />
<Border x:Name="SnappingControls"
Margin="10"
HorizontalAlignment="Right"
VerticalAlignment="Top"
Background="White"
Visibility="Collapsed">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<ScrollViewer Grid.Row="0" Height="325">
<StackPanel Margin="10" Orientation="Vertical">
<TextBlock Padding="0,5"
FontSize="14"
FontWeight="Bold"
Text="Snap settings" />
<ListView>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0"
Width="150"
Text="Snapping enabled" />
<CheckBox Grid.Column="1" IsChecked="{Binding GeometryEditor.SnapSettings.IsEnabled, ElementName=MyMapView}" />
</Grid>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0"
Width="150"
Text="Geometry guides" />
<CheckBox Grid.Column="1"
IsChecked="{Binding GeometryEditor.SnapSettings.IsGeometryGuidesEnabled, ElementName=MyMapView}"
IsEnabled="{Binding GeometryEditor.SnapSettings.IsEnabled, ElementName=MyMapView}" />
</Grid>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0"
Width="150"
Text="Feature snapping" />
<CheckBox Grid.Column="1"
IsChecked="{Binding GeometryEditor.SnapSettings.IsFeatureSnappingEnabled, ElementName=MyMapView}"
IsEnabled="{Binding GeometryEditor.SnapSettings.IsEnabled, ElementName=MyMapView}" />
</Grid>
</ListView>
<Button Click="EnableAllSnapSettingsButton_Click" Content="Enable all" />
<TextBlock Padding="0,5"
FontSize="14"
FontWeight="Bold"
Text="Select snap sources" />
<TextBlock Text="Point layers:" />
<ListView x:Name="PointSnapSettingsList"
ItemTemplate="{StaticResource SnapSettingTemplate}" />
<Button Click="EnableAllPointSnapSourceButton_Click" Content="Enable all" />
<TextBlock Margin="0,10,0,0" Text="Polyline layers:" />
<ListView x:Name="PolylineSnapSettingsList"
ItemTemplate="{StaticResource SnapSettingTemplate}" />
<Button Click="EnableAllPolylineSnapSourceButton_Click" Content="Enable all" />
<TextBlock Margin="0,10,0,0" Text="Graphics overlays:" />
<ListView x:Name="GraphicsOverlaySnapSettingsList"
Width="200"
Height="30"
BorderThickness="0"
ItemTemplate="{StaticResource SnapSettingTemplate}" />
</StackPanel>
</ScrollViewer>
<StackPanel Grid.Row="1"
Margin="10"
Orientation="Vertical">
<TextBlock Padding="0,10,0,5"
FontSize="14"
FontWeight="Bold"
Text="Create and edit geometries" />
<CheckBox x:Name="ReticleVertexToolCheckBox"
Margin="5"
Checked="ReticleVertexToolCheckBox_CheckedChanged"
Content="Reticle vertex tool"
Unchecked="ReticleVertexToolCheckBox_CheckedChanged" />
<Grid Width="200">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100" />
<ColumnDefinition Width="100" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="auto" />
<RowDefinition Height="auto" />
<RowDefinition Height="auto" />
<RowDefinition Height="auto" />
</Grid.RowDefinitions>
<ToggleButton x:Name="PointButton"
Grid.Row="0"
Grid.Column="0"
Click="PointButton_Click"
Style="{StaticResource ToggleButtonIconStyle}"
ToolTipService.ToolTip="Point"
Content="{StaticResource CalciteUIIcons_Glyph_Point}" />
<ToggleButton x:Name="MultipointButton"
Grid.Row="0"
Grid.Column="1"
Click="MultipointButton_Click"
FontSize="20"
Style="{StaticResource ToggleButtonIconStyle}"
ToolTipService.ToolTip="Multipoint"
Content="&#xe9f9;&#xe9f9;" />
<ToggleButton x:Name="PolylineButton"
Grid.Row="1"
Grid.Column="0"
Click="PolylineButton_Click"
Style="{StaticResource ToggleButtonIconStyle}"
ToolTipService.ToolTip="Polyline / no shape fill"
Content="{StaticResource CalciteUIIcons_Glyph_Line}" />
<ToggleButton x:Name="PolygonButton"
Grid.Row="1"
Grid.Column="1"
Click="PolygonButton_Click"
Style="{StaticResource ToggleButtonIconStyle}"
ToolTipService.ToolTip="Polygon / shape fill"
Content="{StaticResource CalciteUIIcons_Glyph_PolygonVertices}" />
<Button Grid.Row="2"
Grid.Column="0"
HorizontalAlignment="Stretch"
Click="DeleteButton_Click"
IsEnabled="{Binding GeometryEditor.SelectedElement.CanDelete, ElementName=MyMapView, FallbackValue=False}"
Style="{StaticResource ButtonIconStyle}"
ToolTipService.ToolTip="Delete selected"
Content="{StaticResource CalciteUIIcons_Glyph_Erase}" />
<Button Grid.Row="2"
Grid.Column="1"
Click="UndoButton_Click"
IsEnabled="{Binding GeometryEditor.CanUndo, ElementName=MyMapView}"
Style="{StaticResource ButtonIconStyle}"
ToolTipService.ToolTip="Undo"
Content="{StaticResource CalciteUIIcons_Glyph_Undo}" />
<Button Grid.Row="3"
Grid.Column="0"
Click="DiscardButton_Click"
IsEnabled="{Binding GeometryEditor.IsStarted, ElementName=MyMapView}"
Style="{StaticResource ButtonIconStyle}"
ToolTipService.ToolTip="Discard edits"
Content="{StaticResource CalciteUIIcons_Glyph_CircleDisallowed}" />
<Button Grid.Row="3"
Grid.Column="1"
Click="SaveButton_Click"
IsEnabled="{Binding GeometryEditor.CanUndo, ElementName=MyMapView}"
Style="{StaticResource ButtonIconStyle}"
ToolTipService.ToolTip="Save edits"
Content="{StaticResource CalciteUIIcons_Glyph_CheckCircle}" />
</Grid>
</StackPanel>
</Grid>
</Border>
</Grid>
</UserControl>