Skip to content

Commit ec4dad1

Browse files
authored
Fix vertex dragging with markerlimit (#1579)
1 parent 8952807 commit ec4dad1

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

cypress/e2e/globalmodes.cy.js

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,71 @@ describe('Modes', () => {
2424
cy.hasTotalVertexMarkers(20);
2525
});
2626

27+
it('dragging without changing the marker with limits markers works', () => {
28+
let layer;
29+
let markerHtml;
30+
31+
cy.window().then(({ map, L }) => {
32+
const geojson = {
33+
type: 'Feature',
34+
properties: {},
35+
geometry: {
36+
type: 'Polygon',
37+
coordinates: [
38+
[
39+
[72.799745, 19.030517],
40+
[72.804465, 19.029097],
41+
[72.803628, 19.030984],
42+
[72.802792, 19.03287],
43+
[72.807512, 19.03218],
44+
[72.803564, 19.034858],
45+
[72.801504, 19.035345],
46+
[72.799745, 19.030517],
47+
],
48+
],
49+
},
50+
};
51+
// eslint-disable-next-line prefer-destructuring
52+
layer = L.geoJSON(geojson).addTo(map).getLayers()[0];
53+
map.fitBounds(layer.getBounds());
54+
55+
map.pm.setGlobalOptions({
56+
limitMarkersToCount: 1,
57+
allowSelfIntersection: false,
58+
});
59+
60+
layer.on('pm:markerdragstart', (e) => {
61+
markerHtml = e.markerEvent.target._icon;
62+
});
63+
});
64+
65+
cy.toolbarButton('edit').click();
66+
67+
// make the marker visible
68+
cy.get(mapSelector).trigger('mousemove', 500, 120, { which: 1 });
69+
70+
cy.get(mapSelector)
71+
.trigger('mousedown', 495, 125, { which: 1 })
72+
.trigger('mousemove', 500, 307, { which: 1 });
73+
74+
// let the animation to show the new marker finish
75+
cy.wait(100);
76+
77+
cy.get('.leaflet-marker-icon').should((p) => {
78+
expect(p[0]).to.equal(markerHtml);
79+
});
80+
81+
// end dragging
82+
cy.get(mapSelector).trigger('mouseup', 500, 307, { which: 1 });
83+
84+
// make other marker visible
85+
cy.get(mapSelector).trigger('mousemove', 310, 330, { which: 1 });
86+
87+
cy.get('.leaflet-marker-icon').should((p) => {
88+
expect(p[0]).to.not.equal(markerHtml);
89+
});
90+
});
91+
2792
it('properly changes markers on vertex removal', () => {
2893
cy.drawShape('PolygonPart1');
2994

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,7 @@ Edit.Line = Edit.extend({
665665
},
666666
_onMarkerDragStart(e) {
667667
const marker = e.target;
668+
this._preventRenderingMarkers(true);
668669

669670
// When intersection is true while calling enable(), the cachedColor is already set
670671
if (!this.cachedColor) {
@@ -775,6 +776,7 @@ Edit.Line = Edit.extend({
775776
},
776777
_onMarkerDragEnd(e) {
777778
const marker = e.target;
779+
this._preventRenderingMarkers(false);
778780

779781
if (!this._vertexValidationDragEnd(marker)) {
780782
return;

0 commit comments

Comments
 (0)