Skip to content

Commit b36f2df

Browse files
tfitzsimTrevor FitzsimmonsFalke-Design
authored
Prevent the creation of an Marker when dragging in draw mode (#1569)
* Prevent the creation of an additional Marker when dragging a Marker in "Create Marker" mode (#1568) - Replicate CircleMarker _layerIsDragging functionality in Marker * Test to ensure an additional Marker is not created when dragging a Marker in "Create Marker" mode (#1568) * Update cypress/e2e/marker.cy.js * Update cypress/e2e/marker.cy.js --------- Co-authored-by: Trevor Fitzsimmons <[email protected]> Co-authored-by: Florian Bischof <[email protected]>
1 parent bea55a6 commit b36f2df

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

cypress/e2e/marker.cy.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,4 +316,32 @@ describe('Draw Marker', () => {
316316
expect(layer._icon.src.endsWith('someIcon.png')).to.eql(true);
317317
});
318318
});
319+
320+
it('does not create additional marker while dragging in draw mode', () => {
321+
cy.toolbarButton('marker').click();
322+
323+
cy.get(mapSelector).click(150, 250);
324+
325+
cy.window().then(({ map }) => {
326+
expect(map.pm.getGeomanDrawLayers().length).to.eq(1);
327+
});
328+
329+
cy.get(mapSelector).trigger('mousedown', 150, 230, { which: 1 });
330+
cy.get(mapSelector).trigger('mousemove', 170, 290, { which: 1 });
331+
// Do not create a new marker while dragging
332+
cy.get(mapSelector).click(170, 290);
333+
cy.get(mapSelector).trigger('mouseup', 170, 290, { which: 1 });
334+
cy.get(mapSelector).trigger('mousemove', 190, 340, { which: 1 });
335+
336+
cy.window().then(({ map }) => {
337+
expect(map.pm.getGeomanDrawLayers().length).to.eq(1);
338+
});
339+
340+
// Create a new marker after dragging with clicking on the icon of a marker
341+
cy.get(mapSelector).click(170, 290);
342+
343+
cy.window().then(({ map }) => {
344+
expect(map.pm.getGeomanDrawLayers().length).to.eq(2);
345+
});
346+
});
319347
});

src/js/Draw/L.PM.Draw.Marker.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ Draw.Marker = Draw.extend({
66
this._map = map;
77
this._shape = 'Marker';
88
this.toolbarButtonName = 'drawMarker';
9+
// with _layerIsDragging we check if a marker is currently dragged and disable marker creation
10+
this._layerIsDragging = false;
911
},
1012
enable(options) {
1113
// TODO: Think about if these options could be passed globally for all
@@ -137,7 +139,7 @@ Draw.Marker = Draw.extend({
137139
this._fireChange(this._hintMarker.getLatLng(), 'Draw');
138140
},
139141
_createMarker(e) {
140-
if (!e.latlng) {
142+
if (!e.latlng || this._layerIsDragging) {
141143
return;
142144
}
143145

src/js/Edit/L.PM.Edit.Marker.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ Edit.Marker = Edit.extend({
3232

3333
this._enabled = true;
3434

35+
this._layer.on('pm:dragstart', this._onDragStart, this);
36+
this._layer.on('pm:dragend', this._onMarkerDragEnd, this);
37+
3538
this._fireEnable();
3639
},
3740
disable() {
@@ -89,6 +92,12 @@ Edit.Marker = Edit.extend({
8992
this._fireRemove(marker);
9093
this._fireRemove(this._map, marker);
9194
},
95+
_onDragStart() {
96+
this._map.pm.Draw.Marker._layerIsDragging = true;
97+
},
98+
_onMarkerDragEnd() {
99+
this._map.pm.Draw.Marker._layerIsDragging = false;
100+
},
92101
_onDragEnd() {
93102
this._fireEdit();
94103
this._layerEdited = true;

0 commit comments

Comments
 (0)