Add vertex-snap mode: Shift+Option+drag snaps to vertices with highlights#1007
Add vertex-snap mode: Shift+Option+drag snaps to vertices with highlights#1007chriswhong wants to merge 5 commits into
Conversation
0f5c94f to
0b474cc
Compare
There was a problem hiding this comment.
This works with existing polygons, but does not work when creating a new polygon. ie: creating a new Polygon adjacent to an existing one, does not have the ability to vertex snap, (although snapping to edges does work). I think this should behaviour should be the same whether you are working on an existing feature or creating a new feature.
typeof dragTargetRef.current === 'string' was always false because RawId is Opaque<number, 'RawId'>. The draggingVertex check never passed, so highlights never appeared on keydown. Fix mirrors the move handler: use !Array.isArray to distinguish a single-vertex drag (RawId) from a multi-feature drag (string[]). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Fix line.ts snapping to exclude the feature being drawn (missing excludeFeatureId) - Add vertex-snap visual feedback (highlight circles) during drawing for both line and polygon modes - Alt+Shift during drawing now snaps to vertices only (matching edit mode behavior) instead of conflicting with direction locking - Update mode hints to document Option+Shift vertex snapping and only show snap hint for features with vertices Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
c21809e to
b0ae9b5
Compare
- Snap first vertex of new lines and polygons when Alt is held - Show vertex snap highlights before first click in line/polygon draw modes - Add full snap support (Alt/Alt+Shift) when drawing points Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
|
Snapping is now working when drawing new linestrings and polygons, and I also made sure that it also works when when drawing the initial vertex of a linestring or polygon, or when drawing a point. |
AndrewSepic
left a comment
There was a problem hiding this comment.
Thanks for the fix! Looking good. Left a small comment to make sure the change was intentional.
|
|
||
| // Immediately show/hide vertex-snap highlights when modifier keys change, | ||
| // without waiting for the next mousemove event. | ||
| useEffect(() => { |
There was a problem hiding this comment.
With the most recent commits, the vertexes are shown on a geometry when you press option, not when you press option+shift. I don't know if that's a bad thing, but it's worth sharing. Maybe a bit strange that you are showing vertexes when you aren't snapping to them..
Summary
Improves snapping by providing a modifier key for snapping to vertices only, not edges. Highlights vertices on nearby features.
More on the use case: I often need to hand-draw a polygon adjacent to an existing polygon, and want them to share vertices. Snapping is very helpful here, but depending on zoom the current snapping feature sometimes gets you close but not quite on the adjacent feature's vertex. There are also situations where many vertices make a smooth curve and it may not be clear where the vertices are, so showing them in a subtle way is helpful for knowing what needs to be added to a new polygon.
Implementation
EphemeralEditingStateVertexSnaptype instate/jotai.tscarries vertex positions to the render layergetSnappingCoordinatesinutils.tsaccepts averticesOnlyflag — when true, snaps to the nearest coordinate vertex using turfdistance()rather thannearestPointOnLine()getNearbyVerticesinutils.tsqueries a wider 80px search box and collects all vertices from every nearby featureScatterplotLayerinpmap/index.tsrenders the amber highlight circles when ephemeral state is'vertex-snap'uphandler)Test plan
🤖 Generated with Claude Code