ArcGIS Pro 3.7 API Reference Guide
ArcGIS.Desktop.Mapping Namespace / Snapping Class / SetLayerSnapModes Method / SetLayerSnapModes(IDictionary<Layer,LayerSnapModes>,Boolean) Method
Dictionary of LayerSnapModes (by Layer) to set.
(Optional) Reset snapping (on) for layers not specified in the dictionary. Default is False.
Example

In This Topic
    SetLayerSnapModes(IDictionary<Layer,LayerSnapModes>,Boolean) Method
    In This Topic
    Sets the snap modes for a layer
    Syntax
    Public Overloads Shared Sub SetLayerSnapModes( _
       ByVal dictionary As IDictionary(Of Layer,LayerSnapModes), _
       Optional ByVal resetOtherLayers As Boolean _
    ) 
    public static void SetLayerSnapModes( 
       IDictionary<Layer,LayerSnapModes> dictionary,
       bool resetOtherLayers
    )

    Parameters

    dictionary
    Dictionary of LayerSnapModes (by Layer) to set.
    resetOtherLayers
    (Optional) Reset snapping (on) for layers not specified in the dictionary. Default is False.
    Remarks
    Provides the ability to set different snapmodes for different layers in one call.
    Example
    Configure Snapping - LayerSnapModes
    var featureLayerList = MapView.Active.Map.GetLayersAsFlattenedList().OfType<FeatureLayer>();
    // configure layer snap modes - must run on the MCT
    await QueuedTask.Run(() =>
    {
      // configure by layer
      foreach (var layer in featureLayerList)
      {
        // find the state of the snapModes for the layer
        var lsm = Snapping.GetLayerSnapModes(layer);
        bool vertexOn = lsm.Vertex;
        // or use 
        vertexOn = lsm.GetSnapMode(SnapMode.Vertex);
        bool edgeOn = lsm.Edge;
        // or use 
        edgeOn = lsm.GetSnapMode(SnapMode.Edge);
        bool endOn = lsm.End;
        // or use 
        endOn = lsm.GetSnapMode(SnapMode.End);
        // update a few snapModes 
        //   turn Vertex off
        lsm.SetSnapMode(SnapMode.Vertex, false);
        // intersections on
        lsm.SetSnapMode(SnapMode.Intersection, true);
        // and set back to the layer
        Snapping.SetLayerSnapModes(layer, lsm);
        // assign a single snap mode at once
        Snapping.SetLayerSnapModes(layer, SnapMode.Vertex, false);
        // turn ALL snapModes on
        Snapping.SetLayerSnapModes(layer, true);
        // turn ALL snapModes off
        Snapping.SetLayerSnapModes(layer, false);
      }
      // configure for a set of layers
      // set Vertex, edge, end on for a set of layers, other snapModes false
      var vee = new LayerSnapModes(false)
      {
        Vertex = true,
        Edge = true,
        End = true
      };
      Snapping.SetLayerSnapModes(featureLayerList, vee);
      // ensure intersection is on for a set of layers without changing any other snapModes
      // get the layer snapModes for the set of layers
      var dictLSM = Snapping.GetLayerSnapModes(featureLayerList);
      foreach (var layer in dictLSM.Keys)
      {
        var lsm = dictLSM[layer];
        lsm.Intersection = true;
      }
      Snapping.SetLayerSnapModes(dictLSM);
      // set all snapModes off for a list of layers
      Snapping.SetLayerSnapModes(featureLayerList, false);
    });
    Configure Snapping - Combined Example
    // interested in only snapping to the vertices of a specific layer of interest and not the vertices of other layers
    //  all other snapModes should be off.
    
    // snapping must be on
    Snapping.IsEnabled = true;
    
    // turn all application snapModes off
    Snapping.SetSnapModes(null);
    
    // set application snapMode vertex on 
    Snapping.SetSnapMode(SnapMode.Vertex, true);
    
    // ensure layer snapping is on
    await QueuedTask.Run(() =>
    {
      featureLayer.SetSnappable(true);
    });
    
    // set vertex snapping only
    var vertexOnly = new LayerSnapModes(false) { Vertex = true };
    
    // set vertex only for the specific layer, clearing all others
    var dict = new Dictionary<Layer, LayerSnapModes>();
    dict.Add(featureLayer, vertexOnly);
    Snapping.SetLayerSnapModes(dict, true);  // true = reset other layers
    Requirements

    Target Platforms: Windows 11 Home, Pro, Enterprise (64 bit)

    ArcGIS Pro version: 3.0 or higher.
    See Also