Skip to main content

Snapping Helper Mode

The Snapping Helper Mode enables alignment of features by "snapping" them to nearby elements on the map. This mode provides tools to control, activate, or deactivate snapping for layers or shapes during editing.

You can handle Snapping Helper Mode with the following methods:

map.gm.enableMode('helper', 'snapping');
map.gm.disableMode('helper', 'snapping');
map.gm.toggleMode('helper', 'snapping');
map.gm.isModeEnabled('helper', 'snapping');

Events for Snapping Helper Mode

The following events are available on a map instance:

EventParamsDescriptionOutput
gm:globalsnappingmodetoggledeventFired when Snapping Helper Mode is toggled.enabled, map

Example Usage

You can listen for specific Snapping Helper Mode events on the map instance like this:

map.on('gm:globalsnappingmodetoggled', (event) => {
console.log(event);
});

Behavior

Snapping works with the following shape types:

  • Markers
  • Circle markers
  • Text markers
  • Lines
  • Rectangles
  • Polygons
  • Circles
  • Guide lines

The snapping helper:

  1. Calculates distances to nearby vertices and lines
  2. Snaps to the closest point within tolerance
  3. Prioritizes vertex snapping over line snapping
  4. Uses a default tolerance of 18 pixels[1]

Configuration

// Enable snapping
map.gm.markerPointer.setSnapping(true);

// Disable snapping
map.gm.markerPointer.setSnapping(false);

// Pause snapping temporarily
map.gm.markerPointer.pauseSnapping();

// Resume snapping
map.gm.markerPointer.resumeSnapping();

Live Snapping Example