Add possibility to edit custom shapes#168
Open
lhapaipai wants to merge 11 commits into
Open
Conversation
0802d27 to
0161352
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
One feature I like in geoman is the great UX when editing circles.
I've seen in your pro version that there is a custom shape Draw mode https://geoman.io/docs/maplibre/draw-modes/draw-custom_shape
In this PR I propose four custom functions to be able to enhance the UX when editing custom shapes.
Context
Some shapes are defined parametrically — for example, a circle stores a center and a radius rather than raw polygon coordinates. When the user drags or rotates such a shape, geoman should update the parametric properties and regenerate the geometry, rather than blindly translating individual polygon vertices.
This PR introduces four optional hooks in
settingsthat allow you to plug this logic into geoman's edit modes.New options
Each hook receives the current feature data (and move information where relevant) and must return either the updated
GeoJsonShapeFeatureornullto fall back to geoman's default behaviour. This makes it easy to handle only the shapes you care about while leaving everything else untouched.Example — editable star shape
The repository includes a working example in
apps/dev/fixtures/customShape.tsthat demonstrates all four hooks for a rounded star polygon. The star is stored with three parametric properties (starCenter,starRadius,starAngle):customGetAllShapeSegments— places one vertex marker on each of the 5 tips of the star instead of on every polygon coordinate.customVertexUpdateHandler— when a tip is dragged, recomputesstarRadiusfrom the distance between the center and the new cursor position, then regenerates the star geometry.customDragHandler— translatesstarCenterby the drag offset and regenerates the geometry.customRotateHandler— updatesstarAngleby the rotation delta and regenerates the geometry.custom-shape.prepared.mp4