Skip to content

[55]: Added snapping of drawing to other camps and fireroads#77

Draft
CarlWiren90 wants to merge 11 commits into
theborderland:mainfrom
CarlWiren90:55-snapping
Draft

[55]: Added snapping of drawing to other camps and fireroads#77
CarlWiren90 wants to merge 11 commits into
theborderland:mainfrom
CarlWiren90:55-snapping

Conversation

@CarlWiren90
Copy link
Copy Markdown

@CarlWiren90 CarlWiren90 commented May 25, 2026

This pull request introduces a comprehensive snapping feature for shape editing in the map editor, allowing points to snap to nearby targets (such as fireroads and other entities) within a configurable 2-meter distance. It also updates the user guide, improves internal handling of snap targets, and ensures fireroads are available as snap targets. The most important changes are grouped below:

Snapping Functionality and Configuration:

  • Added a new setting SNAP_DISTANCE_METERS (set to 2 meters) in SETTINGS.ts to control the snapping radius for editing shapes.
  • Implemented a utility function metersToSnapPixels in src/utils/snapDistance.ts to convert the snap distance from meters to screen pixels, ensuring consistent snapping behavior regardless of zoom level.
  • Updated the editor logic in src/editor/editor.ts to enable snapping when editing shapes, with options to snap to vertices and segments, and to exclude the entity being edited from snap targets.

User Experience and Documentation:

  • Updated the user guide (public/drawers/guide-usage.html) to explain the new snapping behavior and how to disable it by holding ALT while drawing.

Snap Target Management:

  • Modified src/entities/entity.ts so that new entities and buffer layers are not ignored as snap targets by default, while buffer layers explicitly set snapIgnore: true.
  • Syncs snap targets when switching edit modes (not on delete). Delete removes the entity directly to avoid Geoman re-init leaving a ghost outline.

Fireroads and GeoJSON Layers as Snap Targets:

  • Enhanced src/loaders/loadGeoJsonFeatureCollections.ts and src/loaders/loadBaseLayers.ts to allow GeoJSON layers (specifically fireroads) to be exposed as snap targets using a new snapTarget option.

@CarlWiren90 CarlWiren90 changed the title [55]: Added snapping snapping [55]: Added snapping of crawing to other camps and fireroads May 25, 2026
@bobinush
Copy link
Copy Markdown
Collaborator

bobinush commented May 26, 2026

  1. After clicking Draw but before putting down the first vertex I get this error in console when I move the mouse around.
Uncaught TypeError: Cannot read properties of undefined (reading 'lng')
    at NewClass.snapdragFn (editor.ts:829:52)
  1. After placing the last vertex I get this error
Uncaught (in promise) TypeError: Cannot read properties of undefined (reading '0')
    at _getTotalAreaOfOverlappingEntities (isBufferOverlappingRecursive.ts:72:56)
    at isBufferOverlappingRecursive.ts:134:30
    at NewClass.eachLayer (LayerGroup.js:122:11)
    at _getTotalAreaOfOverlappingEntities (isBufferOverlappingRecursive.ts:78:16)
    at isBufferOverlappingRecursive.ts:134:30
    at NewClass.eachLayer (LayerGroup.js:122:11)
    at _getTotalAreaOfOverlappingEntities (isBufferOverlappingRecursive.ts:78:16)
    at Rule._callback (isBufferOverlappingRecursive.ts:27:21)
    at Rule.checkRule (index.ts:42:29)
    at MapEntity.checkAllRules (entity.ts:145:18)

I think this error causes something with saving not to fully work and when I try to delete the camp I get the delete bug you mentioned before.

  1. Similar to point 3. After drawing a camp and if I click another camp I get follow up errors.
  2. If I draw a camp and snap a vertex to another camp, sometimes the rule isOverlapping triggered. This should not happen so I think we need to adjust the rule a bit.
    (click on the camp and see the message "Your area is overlapping someone elses, plz fix <3")

@CarlWiren90
Copy link
Copy Markdown
Author

  1. After clicking Draw but before putting down the first vertex I get this error in console when I move the mouse around.
Uncaught TypeError: Cannot read properties of undefined (reading 'lng')
    at NewClass.snapdragFn (editor.ts:829:52)
  1. After placing the last vertex I get this error
Uncaught (in promise) TypeError: Cannot read properties of undefined (reading '0')
    at _getTotalAreaOfOverlappingEntities (isBufferOverlappingRecursive.ts:72:56)
    at isBufferOverlappingRecursive.ts:134:30
    at NewClass.eachLayer (LayerGroup.js:122:11)
    at _getTotalAreaOfOverlappingEntities (isBufferOverlappingRecursive.ts:78:16)
    at isBufferOverlappingRecursive.ts:134:30
    at NewClass.eachLayer (LayerGroup.js:122:11)
    at _getTotalAreaOfOverlappingEntities (isBufferOverlappingRecursive.ts:78:16)
    at Rule._callback (isBufferOverlappingRecursive.ts:27:21)
    at Rule.checkRule (index.ts:42:29)
    at MapEntity.checkAllRules (entity.ts:145:18)

I think this error causes something with saving not to fully work and when I try to delete the camp I get the delete bug you mentioned before.

  1. Similar to point 3. After drawing a camp and if I click another camp I get follow up errors.
  2. If I draw a camp and snap a vertex to another camp, sometimes the rule isOverlapping triggered. This should not happen so I think we need to adjust the rule a bit.
    (click on the camp and see the message "Your area is overlapping someone elses, plz fix <3")

Thanks for the checkup on these. I'll adress all of them and get back to you! I'll also adjust the rule to prevent a snap from reaching an overlap!

@CarlWiren90
Copy link
Copy Markdown
Author

@bobinush Hey! Fancy pulling down the latest changes and trying out the behaviour?

Adressed the above issues where the first errors were caused by trying to access variables before initiation. To improve the snapping and overlapping towards both camps and fireroads there's added a small nudging to secure a small space to avoid overlaps. One can possibly still overlap a camp with the snapping, but it's harder to do so.

@CarlWiren90 CarlWiren90 changed the title [55]: Added snapping of crawing to other camps and fireroads [55]: Added snapping of drawing to other camps and fireroads May 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants