Skip to content

Commit

Permalink
Fix snapping when polyline has only one coordinate (#1526) (patch)
Browse files Browse the repository at this point in the history
  • Loading branch information
Falke-Design authored Nov 5, 2024
1 parent 772c47c commit 7a34d73
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
16 changes: 16 additions & 0 deletions cypress/integration/line.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,4 +358,20 @@ describe('Draw & Edit Line', () => {
cy.hasVertexMarkers(3);
cy.hasMiddleMarkers(2);
});

it('snapping doesn\'t throw an error when Polyline has only one coordinate' , () => {
cy.window().then(({ map, L }) => {
L.polyline([map.getCenter()]).addTo(map);
});

// activate line drawing
cy.toolbarButton('polyline')
.click()
.closest('.button-container')
.should('have.class', 'active');

// draw a line
cy.get(mapSelector)
.click(150, 250)
});
});
4 changes: 4 additions & 0 deletions src/js/Mixins/Snapping.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,10 @@ const SnapMixin = {
if (layer._parentCopy && layer._parentCopy === this._layer) {
return;
}
// if a polyline has only one coordinate
if (layer.getLatLngs?.().flat(5).length < 2) {
return;
}
// find the closest latlng, segment and the distance of this layer to the dragged marker latlng
const results = this._calcLayerDistances(latlng, layer);
results.distance = Math.floor(results.distance);
Expand Down

0 comments on commit 7a34d73

Please sign in to comment.