View in MAUI WPF WinUI 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. Tap 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
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage x:Class="ArcGIS.Samples.SnapGeometryEdits.SnapGeometryEdits"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:esriUI="clr-namespace:Esri.ArcGISRuntime.Maui;assembly=Esri.ArcGISRuntime.Maui"
xmlns:local="clr-namespace:ArcGIS.Samples.SnapGeometryEdits">
<ContentPage.Resources>
<DataTemplate x:Key="SnapSettingTemplate" x:DataType="local:SnapSourceSettingsVM">
<Grid ColumnSpacing="3">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Label Grid.Column="0"
Text="{Binding Path=Name}"
VerticalOptions="Center"
WidthRequest="160" />
<Switch Grid.Column="1"
HorizontalOptions="End"
IsToggled="{Binding Path=IsEnabled, Mode=TwoWay}"
VerticalOptions="Center" />
</Grid>
</DataTemplate>
<Style x:Key="IconStyle" TargetType="Button">
<Style.Setters>
<Setter Property="FontFamily" Value="CalciteUIIconsMediumFontFamily" />
<Setter Property="FontSize" Value="24" />
</Style.Setters>
</Style>
</ContentPage.Resources>
<Grid>
<esriUI:MapView x:Name="MyMapView" />
<Grid x:Name="CreateEditGeometriesPanel"
Margin="10"
ColumnDefinitions="110,110"
ColumnSpacing="5"
HorizontalOptions="End"
IsVisible="False"
RowDefinitions="auto,auto,auto,auto,auto,auto"
RowSpacing="5"
VerticalOptions="Start">
<Button x:Name="ShowSnapSettingsButton"
Grid.Row="0"
Grid.ColumnSpan="2"
Clicked="ShowSnapSettingsButton_Clicked"
Text="Show snap settings" />
<Border Grid.Row="1"
Grid.ColumnSpan="2"
BackgroundColor="{AppThemeBinding Dark=#3C3C3C,
Light=White}"
HeightRequest="40">
<Border.StrokeShape>
<RoundRectangle CornerRadius="5" />
</Border.StrokeShape>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Label Grid.Column="0"
Margin="10,0"
Text="Reticle vertex tool"
VerticalOptions="Center" />
<Switch x:Name="ReticleVertexToolSwitch"
Grid.Column="1"
HorizontalOptions="End"
Toggled="ReticleVertexToolSwitch_Toggled"
VerticalOptions="Center" />
</Grid>
</Border>
<Button x:Name="PointButton"
Grid.Row="2"
Grid.Column="0"
Clicked="PointButton_Click"
Style="{StaticResource IconStyle}"
Text="{StaticResource CalciteUIIcons_Glyph_Point}"
ToolTipProperties.Text="Point" />
<Button x:Name="MultipointButton"
Grid.Row="2"
Grid.Column="1"
Clicked="MultipointButton_Click"
FontFamily="CalciteUIIconsSmallFontFamily"
FontSize="16"
Style="{StaticResource IconStyle}"
Text="&#xe9f9; &#xe9f9;"
ToolTipProperties.Text="Multipoint" />
<Button x:Name="PolylineButton"
Grid.Row="3"
Grid.Column="0"
Clicked="PolylineButton_Click"
Style="{StaticResource IconStyle}"
Text="{StaticResource CalciteUIIcons_Glyph_Line}"
ToolTipProperties.Text="Polyline / no shape fill" />
<Button x:Name="PolygonButton"
Grid.Row="3"
Grid.Column="1"
Clicked="PolygonButton_Click"
Style="{StaticResource IconStyle}"
Text="{StaticResource CalciteUIIcons_Glyph_PolygonVertices}"
ToolTipProperties.Text="Polygon / shape fill" />
<Button Grid.Row="4"
Grid.Column="0"
Clicked="DeleteButton_Click"
IsEnabled="{Binding GeometryEditor.SelectedElement.CanDelete, Source={x:Reference MyMapView}, FallbackValue=False, x:DataType=esriUI:MapView}"
Style="{StaticResource IconStyle}"
Text="{StaticResource CalciteUIIcons_Glyph_Erase}"
ToolTipProperties.Text="Delete selected" />
<Button Grid.Row="4"
Grid.Column="1"
Clicked="UndoButton_Click"
IsEnabled="{Binding GeometryEditor.CanUndo, Source={x:Reference MyMapView}, x:DataType=esriUI:MapView}"
Style="{StaticResource IconStyle}"
Text="{StaticResource CalciteUIIcons_Glyph_Undo}"
ToolTipProperties.Text="Undo" />
<Button Grid.Row="5"
Grid.Column="0"
Clicked="DiscardButton_Click"
IsEnabled="{Binding GeometryEditor.IsStarted, Source={x:Reference MyMapView}, x:DataType=esriUI:MapView}"
Style="{StaticResource IconStyle}"
Text="{StaticResource CalciteUIIcons_Glyph_CircleDisallowed}"
ToolTipProperties.Text="Discard edits" />
<Button Grid.Row="5"
Grid.Column="1"
Clicked="SaveButton_Click"
IsEnabled="{Binding GeometryEditor.CanUndo, Source={x:Reference MyMapView}, x:DataType=esriUI:MapView}"
Style="{StaticResource IconStyle}"
Text="{StaticResource CalciteUIIcons_Glyph_CheckCircle}"
ToolTipProperties.Text="Save edits" />
</Grid>
<Grid x:Name="SnappingSettingsPopup"
Grid.ColumnSpan="2"
Padding="10"
Background="#AA333333"
IsVisible="False">
<Border x:Name="SnapSettingsContainer"
Margin="10"
Background="{AppThemeBinding Dark=Black,
Light=White}"
HorizontalOptions="Center"
MaximumHeightRequest="450"
MaximumWidthRequest="300"
StrokeShape="RoundRectangle 10"
VerticalOptions="Center">
<ScrollView>
<VerticalStackLayout Margin="10">
<Grid ColumnDefinitions="auto,*">
<Label Padding="0,5"
FontAttributes="Bold"
FontSize="14"
Text="Snap settings" />
<Button Grid.Column="1"
Margin="20,0"
Clicked="EnableAllSnapSettingsButton_Click"
HorizontalOptions="End"
Text="Enable all"
VerticalOptions="Center" />
</Grid>
<VerticalStackLayout HeightRequest="130">
<Grid ColumnSpacing="3">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Label Grid.Column="0"
Text="Snapping"
VerticalOptions="Center"
WidthRequest="160" />
<Switch Grid.Column="1"
HorizontalOptions="End"
IsToggled="{Binding GeometryEditor.SnapSettings.IsEnabled, Source={x:Reference MyMapView}, x:DataType=esriUI:MapView}"
VerticalOptions="Center" />
</Grid>
<Grid ColumnSpacing="3">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Label Grid.Column="0"
Text="Geometry guides"
VerticalOptions="Center"
WidthRequest="160" />
<Switch Grid.Column="1"
HorizontalOptions="End"
IsEnabled="{Binding GeometryEditor.SnapSettings.IsEnabled, Source={x:Reference MyMapView}, x:DataType=esriUI:MapView}"
IsToggled="{Binding GeometryEditor.SnapSettings.IsGeometryGuidesEnabled, Source={x:Reference MyMapView}, x:DataType=esriUI:MapView}"
VerticalOptions="Center" />
</Grid>
<Grid ColumnSpacing="3">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Label Grid.Column="0"
Text="Feature snapping"
VerticalOptions="Center"
WidthRequest="160" />
<Switch Grid.Column="1"
HorizontalOptions="End"
IsEnabled="{Binding GeometryEditor.SnapSettings.IsEnabled, Source={x:Reference MyMapView}, x:DataType=esriUI:MapView}"
IsToggled="{Binding GeometryEditor.SnapSettings.IsFeatureSnappingEnabled, Source={x:Reference MyMapView}, x:DataType=esriUI:MapView}"
VerticalOptions="Center" />
</Grid>
</VerticalStackLayout>
<BoxView Margin="0,0,0,5"
HeightRequest="1"
Color="White" />
<Label Padding="0,5"
FontAttributes="Bold"
FontSize="14"
Text="Snap sources" />
<Grid ColumnDefinitions="auto,*">
<Label Grid.Column="0"
Text="Point layers:"
VerticalOptions="Center" />
<Button Grid.Column="1"
Margin="20,0"
Clicked="EnableAllPointSnapSourceButton_Click"
HorizontalOptions="End"
Text="Enable all"
VerticalOptions="Center" />
</Grid>
<CollectionView x:Name="PointSnapSettingsList"
HeightRequest="150"
ItemTemplate="{StaticResource SnapSettingTemplate}"
WidthRequest="250" />
<Grid Margin="0,10,0,0" ColumnDefinitions="0.5*,auto">
<Label Grid.Column="0"
Text="Polyline layers:"
VerticalOptions="Center" />
<Button Grid.Column="1"
Margin="20,0"
Clicked="EnableAllPolylineSnapSourceButton_Click"
HorizontalOptions="End"
Text="Enable all"
VerticalOptions="Center" />
</Grid>
<CollectionView x:Name="PolylineSnapSettingsList"
HeightRequest="90"
ItemTemplate="{StaticResource SnapSettingTemplate}"
WidthRequest="250" />
<Grid Margin="0,10,0,0">
<Label Text="Graphics overlays:" VerticalOptions="Center" />
</Grid>
<CollectionView x:Name="GraphicsOverlaySnapSettingsList"
HeightRequest="60"
ItemTemplate="{StaticResource SnapSettingTemplate}"
WidthRequest="250" />
</VerticalStackLayout>
</ScrollView>
</Border>
</Grid>
</Grid>
</ContentPage>