internal static async Task ConfigureSnappingAsync() { //General Snapping Snapping.IsEnabled = true; Snapping.SetSnapMode(SnapMode.Edge, true); Snapping.SetSnapMode(SnapMode.End, true); Snapping.SetSnapMode(SnapMode.Intersection, true); //Snapping on any line Feature Layers var flayers = MapView.Active.Map.GetLayersAsFlattenedList().OfType <FeatureLayer>().Where( l => l.ShapeType == esriGeometryType.esriGeometryPolyline).ToList(); if (flayers.Count() > 0) { //GetDefinition and SetDefinition must be called inside QueuedTask await QueuedTask.Run(() => { foreach (var fl in flayers) { var layerDef = fl.GetDefinition() as CIMGeoFeatureLayerBase; if (!layerDef.Snappable) { layerDef.Snappable = true; fl.SetDefinition(layerDef); } } }); } }
protected async void SetSnapping() { var myMap = MapView.Active.Map; //using ArcGIS.Desktop.Mapping //enable snapping Snapping.IsEnabled = true; //enable a snap mode, others are not changed. Snapping.SetSnapMode(SnapMode.Point, true); //set multiple snap modes exclusively. All others will be disabled. Snapping.SetSnapModes(SnapMode.Edge, SnapMode.Point); await QueuedTask.Run(() => { //set snapping options via get/set options var snapOptions = Snapping.GetOptions(myMap); snapOptions.SnapToSketchEnabled = true; snapOptions.XYTolerance = 100; Snapping.SetOptions(myMap, snapOptions); }); var myFeatureLayer = MapView.Active.GetSelectedLayers().First() as FeatureLayer; //read snapping availability for a layer var canSnap = myFeatureLayer.IsSnappable; //set snapping availability for a layer var featLayerDef = myFeatureLayer.GetDefinition() as ArcGIS.Core.CIM.CIMGeoFeatureLayerBase; featLayerDef.Snappable = true; myFeatureLayer.SetDefinition(featLayerDef); }