Snapping
While you draw or move something, the editor looks for a snap target near the pointer and shows it as a marker before you click. The point then lands exactly on the target, so new geometry connects to existing geometry instead of ending next to it.
What a point snaps to#
Within the snap radius, in this order of preference:
- a corner (an existing node),
- the middle of an edge,
- a quarter point of an edge (one quarter or three quarters along),
- anywhere on an edge (the foot of the perpendicular).
A closer target of a lower kind does not beat a corner: the order decides first, distance only
within one kind. Only the active layer's own geometry is searched this way — a click can still
land on another layer's boundary, but never by accident: only via an active Geofencing rule
naming that layer as its target (vectorstream Pro), or via editor.nachzeichnenVorlagen naming it as a tracing
template (below). Either way, the point itself stays free-standing on the active layer's own
partition; nothing ties it to the layer it was found on.
Each of the four kinds can be switched off on its own: editor.rastArten (default all four, in
the order above) — the same division as rastenAktiv, for every tool that asks through
ctx.rasten(...). A mode that restricts the kinds itself on a particular call keeps exactly that
restriction; this setting only fills in the default where a mode leaves the choice open. An empty
array means no snapping at all, same as rastenAktiv = false, just reversible one kind at a time.
Does not reach transform (drag, rotate, scale). That mode snaps a moved corner onto a
foreign corner, division point, or edge on its own, by calling the core's rastziel directly —
never through ctx.rasten(...) — so rastArten has no effect there; dragging always offers all
four kinds. rastenAktiv has no such gap: it works through the shared snap tolerance, which
transform also reads, so switching snapping off entirely still reaches it — only the four-way
split does not.
Not retroactive. Switching a kind off does not by itself erase an already-shown marker of
that kind: the active mode's last snap target is only recomputed on the next pointer move, like
every other ctx.rasten(...)-driven display.
The radius is given in screen pixels — new Editor(…, adapter, { tolerancePx }), default 8 —
and the adapter converts it to map units for the current zoom, so snapping feels the same at every
zoom level. editor.tolerancePixel() returns the value, for a UI that wants to use the same one.
Guide lines#
While drawing, imagined lines help to align a point:
- horizontal and vertical axes through the points already placed — those through the first and the last placed point are shown the whole time;
- the extension of existing edges;
- the right angle to the edge drawn last;
- the intersection of two guide lines, which counts like a corner.
A guide line pulls the point onto it but lets it slide along it. Guide lines are switched with
editor.hilfslinienAktiv (default on).
Tracing along existing boundaries#
If two consecutive clicks both snap onto existing boundaries, the polygon and line tools insert
the path along those boundaries between them, vertex by vertex, instead of a straight segment
(where no such path is found, the segment stays straight). When a polygon is closed, the closing
segment back to the first point is traced the same way. The preview shows the traced path before
you click. Backspace removes a traced section as a whole. Switched with editor.nachzeichnenAktiv (default on). For cut and difference, tracing only
happens while Shift is held.
editor.nachzeichnenVorlagen extends this across layers: a ReadonlyMap<EbenenId, readonly EbenenId[]> from a layer to the layer(s) it may additionally trace along, keyed by the layer
doing the tracing. A click that snaps onto a named template layer's own boundary traces the whole
path there too — the vertices in between are inserted as free points on the active layer, each
rounded onto its own grid. This is independent of Geofencing (above): no rule, no validation, no
undo entry of its own, and it creates no topology between the two layers — the traced points are
exactly as free-standing as a hand-placed point at the same spot. Not persisted: an application
that wants it to survive a reload sets it again after loading a document, the same as
rastenAktiv. A layer absent from the map, or one named but since removed, is silently passed
over — exactly as if nothing had been named.
Switching snapping off#
- Alt suspends snapping while it is held: the click lands exactly where the pointer is. This also stops the insert operation from merging the point with a nearby node.
editor.rastenAktiv = falseswitches snapping off until it is switched on again (default on).
import type { Adapter } from '@vectorstream/adapter';
import type { Partition } from '@vectorstream/core';
import { Editor } from '@vectorstream/editor';
export function createEditorWithSnapping(partition: Partition, adapter: Adapter): Editor {
// Snap radius in screen pixels (default 8); the adapter converts it for the current zoom.
const editor = new Editor(partition, adapter, { tolerancePx: 12 });
editor.rastenAktiv = true; // snapping at all (default on; Alt suspends it while held)
editor.hilfslinienAktiv = false; // no guide lines (alignment, extensions, right angle)
editor.nachzeichnenAktiv = true; // trace along existing boundaries between two snapped clicks
editor.rastArten = ['ecke', 'kante']; // only corners and edges — no midpoints or quarter points
return editor;
}
The test of this example clicks 9 by 5 pixels beside a parcel corner: with the radius of 12
pixels the new vertex lands on the corner; with rastenAktiv = false, or with Alt held, it does
not.
What does not snap#
- Lines are inserted exactly: the line tool snaps each click as described above, but the insert
itself uses no tolerance. Calling
insertLinewith a tolerance above zero throws aRangeError. - A click still never snaps to another layer by default — only the target layers of an active
Geofencing rule (vectorstream Pro; most kinds of rule, after the layer's own geometry) or an
explicitly named
nachzeichnenVorlagentemplate layer can be reached, and even then only as a snap target, never as real topology (see Layers). - Validation does not use the snap radius: it always checks with tolerance zero (see Validity and rejections).
API: Editor, EditorOptions.