Class: Snap

ol/interaction/Snap~Snap


import Snap from 'ol/interaction/Snap';

Handles snapping of vector features while modifying or drawing them. The features can come from a module:ol/source/Vector~VectorSource or module:ol/Collection~Collection Any interaction object that allows the user to interact with the features using the mouse can benefit from the snapping, as long as it is added before.

The snap interaction modifies map browser event coordinate and pixel properties to force the snap to occur to any interaction that them.

Example:

import Snap from 'ol/interaction/Snap';

var snap = new Snap({
  source: source
});

new Snap(opt_options)

interaction/Snap.js, line 68
Name Type Description
options

Options.

Name Type Default Description
features module:ol/Collection~Collection.<module:ol/Feature~Feature>

Snap to these features. Either this option or source should be provided.

edge boolean true

Snap to edges.

vertex boolean true

Snap to vertices.

pixelTolerance number 10

Pixel tolerance for considering the pointer close enough to a segment or vertex for snapping.

source module:ol/source/Vector~VectorSource

Snap to features from this source. Either this option or features should be provided

Methods

addFeature(feature, opt_listen)

interaction/Snap.js, line 190

Add a feature to the collection of features that we may snap to.

Name Type Description
feature module:ol/Feature~Feature

Feature.

listen boolean

Whether to listen to the feature change or not Defaults to true.

removeFeature(feature, opt_unlisten)

interaction/Snap.js, line 293

Remove a feature from the collection of features that we may snap to.

Name Type Description
feature module:ol/Feature~Feature

Feature

unlisten boolean

Whether to unlisten to the feature change or not. Defaults to true.