Skip to content

Commit

Permalink
Show HintMarker at the last position if continueDrawing is enabled (#…
Browse files Browse the repository at this point in the history
…1536) (minor)

* Show HintMarkers at the last position (continueDrawing)

* Add tests
  • Loading branch information
Falke-Design authored Nov 24, 2024
1 parent b55fd6d commit abe8408
Show file tree
Hide file tree
Showing 12 changed files with 68 additions and 1 deletion.
6 changes: 6 additions & 0 deletions cypress/e2e/circle.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@ describe('Draw Circle', () => {
// draw with continueDrawing: true the second circle
cy.get(mapSelector).click(300, 200).click(350, 250);

cy.window().then(({ map }) => {
const latlng = map.pm.Draw.Circle._hintMarker.getLatLng();
const pxLatLng = map.containerPointToLatLng([350, 250]);
expect(pxLatLng).to.deep.equal(latlng);
});

// additional click because cypress lose the focus on the window ... wtf ...
cy.get(mapSelector).click();
cy.toolbarButton('edit').click();
Expand Down
6 changes: 6 additions & 0 deletions cypress/e2e/circlemarker.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,12 @@ describe('Draw Circle Marker', () => {
// draw with continueDrawing: ture the second circle
cy.get(mapSelector).click(300, 200).click(350, 250);

cy.window().then(({ map }) => {
const latlng = map.pm.Draw.CircleMarker._hintMarker.getLatLng();
const pxLatLng = map.containerPointToLatLng([350, 250]);
expect(pxLatLng).to.deep.equal(latlng);
});

// additional click because cypress lose the focus on the window ... wtf ...
cy.get(mapSelector).click();

Expand Down
6 changes: 6 additions & 0 deletions cypress/e2e/line.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,12 @@ describe('Draw & Edit Line', () => {

cy.get(mapSelector).click(200, 200).click(250, 250).click(250, 250);

cy.window().then(({ map }) => {
const latlng = map.pm.Draw.Line._hintMarker.getLatLng();
const pxLatLng = map.containerPointToLatLng([250, 250]);
expect(pxLatLng).to.deep.equal(latlng);
});

cy.toolbarButton('edit').click();
cy.hasVertexMarkers(5);
});
Expand Down
6 changes: 6 additions & 0 deletions cypress/e2e/polygon.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,12 @@ describe('Draw & Edit Poly', () => {
.click(250, 300)
.click(230, 230);

cy.window().then(({ map }) => {
const latlng = map.pm.Draw.Polygon._hintMarker.getLatLng();
const pxLatLng = map.containerPointToLatLng([230, 230]);
expect(pxLatLng).to.deep.equal(latlng);
});

cy.toolbarButton('edit').click();
cy.hasVertexMarkers(6);
});
Expand Down
6 changes: 6 additions & 0 deletions cypress/e2e/rectangle.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,12 @@ describe('Draw Rectangle', () => {

cy.get(mapSelector).click(230, 230).click(350, 350);

cy.window().then(({ map }) => {
const latlng = map.pm.Draw.Rectangle._hintMarker.getLatLng();
const pxLatLng = map.containerPointToLatLng([350, 350]);
expect(pxLatLng).to.deep.equal(latlng);
});

cy.toolbarButton('edit').click();
cy.hasVertexMarkers(8);
});
Expand Down
14 changes: 14 additions & 0 deletions cypress/e2e/text.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,20 @@ describe('Text Layer', () => {
const textLayer = map.pm.getGeomanDrawLayers()[1];
textArea = textLayer.pm.getElement();
cy.get(textArea).type('Geoman!');

const textMap = map.pm.Draw.Text._hintMarker._map;
expect(textMap).to.eq(null);
});

cy.get(mapSelector)
.trigger('mousemove', 200, 150, { which: 1 });

cy.window().then(({ map }) => {
const textMap = map.pm.Draw.Text._hintMarker._map;
expect(textMap).to.eq(map);
const latlng = map.pm.Draw.Text._hintMarker.getLatLng();
const pxLatLng = map.containerPointToLatLng([200, 150]);
expect(pxLatLng).to.deep.equal(latlng);
});

cy.get(mapSelector).click(290, 150);
Expand Down
3 changes: 3 additions & 0 deletions src/js/Draw/L.PM.Draw.CircleMarker.js
Original file line number Diff line number Diff line change
Expand Up @@ -408,10 +408,13 @@ Draw.CircleMarker = Draw.extend({
// fire the pm:create event and pass shape and layer
this._fireCreate(circleLayer);

const hintMarkerLatLng = this._hintMarker.getLatLng();

// disable drawing
this.disable();
if (this.options.continueDrawing) {
this.enable();
this._hintMarker.setLatLng(hintMarkerLatLng);
}
},
_getNewDestinationOfHintMarker() {
Expand Down
3 changes: 3 additions & 0 deletions src/js/Draw/L.PM.Draw.Cut.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,13 @@ Draw.Cut = Draw.Polygon.extend({
});
this._editedLayers = [];

const hintMarkerLatLng = this._hintMarker.getLatLng();

// disable drawing
this.disable();
if (this.options.continueDrawing) {
this.enable();
this._hintMarker.setLatLng(hintMarkerLatLng);
}
},
cut(layer) {
Expand Down
3 changes: 3 additions & 0 deletions src/js/Draw/L.PM.Draw.Line.js
Original file line number Diff line number Diff line change
Expand Up @@ -377,10 +377,13 @@ Draw.Line = Draw.extend({
this._cleanupSnapping();
}

const hintMarkerLatLng = this._hintMarker.getLatLng();

// disable drawing
this.disable();
if (this.options.continueDrawing) {
this.enable();
this._hintMarker.setLatLng(hintMarkerLatLng);
}
},
_createMarker(latlng) {
Expand Down
3 changes: 3 additions & 0 deletions src/js/Draw/L.PM.Draw.Polygon.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,13 @@ Draw.Polygon = Draw.Line.extend({
this._otherSnapLayers.splice(this._tempSnapLayerIndex, 1);
delete this._tempSnapLayerIndex;

const hintMarkerLatLng = this._hintMarker.getLatLng();

// disable drawing
this.disable();
if (this.options.continueDrawing) {
this.enable();
this._hintMarker.setLatLng(hintMarkerLatLng);
}
},
});
3 changes: 3 additions & 0 deletions src/js/Draw/L.PM.Draw.Rectangle.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,10 +304,13 @@ Draw.Rectangle = Draw.extend({
// fire the pm:create event and pass shape and layer
this._fireCreate(rectangleLayer);

const hintMarkerLatLng = this._hintMarker.getLatLng();

// disable drawing
this.disable();
if (this.options.continueDrawing) {
this.enable();
this._hintMarker.setLatLng(hintMarkerLatLng);
}
},
setStyle() {
Expand Down
10 changes: 9 additions & 1 deletion src/js/Draw/L.PM.Draw.Text.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ Draw.Text = Draw.extend({
// remove event listener to sync hint marker
this._map.off('mousemove', this._syncHintMarker, this);

this._map.off('mousemove', this._showHintMarker, this);

// toggle the draw button of the Toolbar in case drawing mode got disabled without the button
this._map.pm.Toolbar.toggleButton(this.toolbarButtonName, false);

Expand Down Expand Up @@ -181,10 +183,16 @@ Draw.Text = Draw.extend({
// disable drawing
this.disable();
if (this.options.continueDrawing) {
this.enable();
// the user is still typing some text, so we re-enable the layer after moving the mouse
this._map.once('mousemove', this._showHintMarkerAfterMoving, this);
}
},

_showHintMarkerAfterMoving(e) {
this.enable();
this._hintMarker.setLatLng(e.latlng);
},

_createTextArea() {
const textArea = document.createElement('textarea');
textArea.readOnly = true;
Expand Down

0 comments on commit abe8408

Please sign in to comment.