Hide Table of Contents
esri/dijit/util
esri/layer/pixelFilters
esri/process
esri/support
esri/workers
Class: SnappingManager

dojo.require("esri.SnappingManager");

Description

(Added at v2.3)
The SnappingManager is used to add snapping capability to the Editor, Measurement Widget, Draw toolbar and Edit toolbar.

Samples

Search for samples that use this class.

Constructors

NameSummary
new esri.SnappingManager(options?)Create a new SnappingManager object.

Methods

NameReturn typeSummary
destroy()NoneDestroy the SnappingManager object.
getSnappingPoint(screenPoint)DeferredReturns a deferred object, which can be added to a callback to find the snap point.
setLayerInfos(layerInfos)NoneAn array of layerInfo objects used to specify the target snapping layers.
Constructor Details

new esri.SnappingManager(options?)

Create a new SnappingManager object. It is not required to create a SnappingManager object to enable snapping for the Editor, Measurement or Draw and Edit Toolbars. To enable snapping, call the map's enableSnapping method. Create a new snapping manager object if the default options need to be modified.
Parameters:
<Object> options Optional Optional parameters. See options list.
options properties:
<Boolean> alwaysSnap Optional When true, snapping is always enabled. When false users press the snapKey to enable snapping. Default value is false.
<Object[]> layerInfos Optional See the object specifications table below for the structure of the layerInfos object.
<Map> map Required Reference to the map. Required parameter.
<dojo/keys> snapKey Optional When alwaysSnap is set to false use this option to define the key users press to enable snapping. The default value is the dojo.copyKey. The dojo.copyKey is a virtual key that maps to CTRL on Windows and the Command key on mac.
<SimpleMarkerSymbol> snapPointSymbol Optional Define a symbol for the snapping location. The default symbol is a simple marker symbol with the following properties: size:15px, color:cyan, style:STYLE_CROSS.
<Number> tolerance Optional Specify the radius of the snapping circle in pixels. The default value is 15 pixels.
Object Specifications:
<layerInfo>
<Layer> layer Required Reference to a feature or graphics layer that will be a target snapping layer. The default option is to set all feature and graphics layers in the map to be target snapping layers.
<Boolean> snapToEdge Required Default is true. When true snapping to edges will be enabled for layers with polyline or polygon geometry.
<Boolean> snapToPoint Required Default is true. When true snapping to points will be enabled for layers with point geometry.
<Boolean> snapToVertex Required Default is true. When true snapping to vertices will be enabled for layers with polyline or polygon geometry.
Method Details

destroy()

Destroy the SnappingManager object. All related objects will be set to null.
Sample:

snappingManager.destroy();

getSnappingPoint(screenPoint)

Returns a deferred object, which can be added to a callback to find the snap point.
Return type: Deferred
Parameters:
<Point> screenPoint Required The input screen point for which to find the snapping location.
Sample:

var deferred = snappingManager.getSnappingPoint(evt.screenPoint);

deferred.then(function(value){

  if(value !== undefined){

    var snapPoint = value;

  }

},

function(error){

  console.log('failure');

});

setLayerInfos(layerInfos)

An array of layerInfo objects used to specify the target snapping layers.
Parameters:
<Object[]> layerInfos Required An array of layerInfo objects that define the snapping target layers. All values are optional. If no snapping options are set the default values will be used. See the object specifications table below for the structure of the layerInfos object.
Object Specifications:
<layerInfo>
<Boolean> layer Required Reference to a feature or graphics layer that will be a target snapping layer. The default option is to set all feature and graphics layers in the map to be target snapping layers.
<Boolean> snapToEdge Required Default is true. When true snapping to edges will be enabled for layers with polyline or polygon geometry.
<Boolean> snapToPoint Required Default is true. When true snapping to points will be enabled for layers with point geometry.
<Boolean> snapToVertex Required Default is true. When true snapping to vertices will be enabled for layers with polyline or polygon geometry.
Sample:

var layerInfos = [

  {layer:results[0].layer}

];

snappingManager.setLayerInfos(layerInfos);

Show Modal