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:
Event | Params | Description | Output |
---|---|---|---|
gm:globalsnappingmodetoggled | event | Fired 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:
- Calculates distances to nearby vertices and lines
- Snaps to the closest point within tolerance
- Prioritizes vertex snapping over line snapping
- 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();