Skip to content

Commit e2d43de

Browse files
authored
keeps alt-coordinate after editing a vertex (#1578)
1 parent b36f2df commit e2d43de

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

cypress/e2e/polygon.cy.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1465,4 +1465,46 @@ describe('Draw & Edit Poly', () => {
14651465
expect(layer.getLatLngs()[0][0].lng).to.eq(-0.15037536621093753);
14661466
});
14671467
});
1468+
1469+
it('keeps alt coordinate after editing a vertex', () => {
1470+
let polygon;
1471+
1472+
cy.window().then(({ map, L }) => {
1473+
polygon = L.polygon([
1474+
[
1475+
[20.53507732696281, 71.98242187500001, 111],
1476+
[19.87005983797396, 71.97143554687501, 222],
1477+
[19.782211275967995, 73.35021972656251, 333],
1478+
[20.55565240377338, 73.48754882812501, 444],
1479+
[20.53507732696281, 71.98242187500001, 111],
1480+
],
1481+
]);
1482+
polygon.addTo(map);
1483+
map.fitBounds(polygon.getBounds(), { animate: false });
1484+
1485+
expect(
1486+
polygon
1487+
.getLatLngs()
1488+
.flat()
1489+
.map((a) => a.alt)
1490+
.join(',')
1491+
).to.equal('111,222,333,444');
1492+
});
1493+
1494+
cy.toolbarButton('edit').click();
1495+
1496+
cy.get(mapSelector).trigger('mousedown', 225, 105, { which: 1 });
1497+
cy.get(mapSelector).trigger('mousemove', 225, 150, { which: 1 });
1498+
cy.get(mapSelector).trigger('mouseup', 225, 150, { which: 1 });
1499+
1500+
cy.window().then(() => {
1501+
expect(
1502+
polygon
1503+
.getLatLngs()
1504+
.flat()
1505+
.map((a) => a.alt)
1506+
.join(',')
1507+
).to.equal('111,222,333,444');
1508+
});
1509+
});
14681510
});

src/js/Edit/L.PM.Edit.Line.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,8 @@ Edit.Line = Edit.extend({
604604

605605
// update coord
606606
const parent = indexPath.length > 1 ? get(coords, parentPath) : coords;
607+
// Can be removed after https://github.com/Leaflet/Leaflet/issues/9689 is fixed
608+
latlng.alt = parent[index].alt;
607609
parent.splice(index, 1, latlng);
608610

609611
// set new coords on layer
@@ -782,7 +784,8 @@ Edit.Line = Edit.extend({
782784

783785
// if self intersection is not allowed but this edit caused a self intersection,
784786
// reset and cancel; do not fire events
785-
let intersection = !this.options.allowSelfIntersection && this.hasSelfIntersection();
787+
let intersection =
788+
!this.options.allowSelfIntersection && this.hasSelfIntersection();
786789
if (
787790
intersection &&
788791
this.options.allowSelfIntersectionEdit &&

0 commit comments

Comments
 (0)