diff --git a/cypress/e2e/circle.cy.js b/cypress/e2e/circle.cy.js index 06e71191..d2be9b1b 100644 --- a/cypress/e2e/circle.cy.js +++ b/cypress/e2e/circle.cy.js @@ -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(); diff --git a/cypress/e2e/circlemarker.cy.js b/cypress/e2e/circlemarker.cy.js index 81bfee5c..782ea28a 100644 --- a/cypress/e2e/circlemarker.cy.js +++ b/cypress/e2e/circlemarker.cy.js @@ -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(); diff --git a/cypress/e2e/line.cy.js b/cypress/e2e/line.cy.js index a6240397..1ec74670 100644 --- a/cypress/e2e/line.cy.js +++ b/cypress/e2e/line.cy.js @@ -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); }); diff --git a/cypress/e2e/polygon.cy.js b/cypress/e2e/polygon.cy.js index d6c89a6f..9ee4694b 100644 --- a/cypress/e2e/polygon.cy.js +++ b/cypress/e2e/polygon.cy.js @@ -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); }); diff --git a/cypress/e2e/rectangle.cy.js b/cypress/e2e/rectangle.cy.js index a237de4d..62cbed73 100644 --- a/cypress/e2e/rectangle.cy.js +++ b/cypress/e2e/rectangle.cy.js @@ -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); }); diff --git a/cypress/e2e/text.cy.js b/cypress/e2e/text.cy.js index 16525499..3e81e7a2 100644 --- a/cypress/e2e/text.cy.js +++ b/cypress/e2e/text.cy.js @@ -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); diff --git a/src/js/Draw/L.PM.Draw.CircleMarker.js b/src/js/Draw/L.PM.Draw.CircleMarker.js index 6491a8bb..6f1e2237 100644 --- a/src/js/Draw/L.PM.Draw.CircleMarker.js +++ b/src/js/Draw/L.PM.Draw.CircleMarker.js @@ -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() { diff --git a/src/js/Draw/L.PM.Draw.Cut.js b/src/js/Draw/L.PM.Draw.Cut.js index 5d3e4118..be2e0df3 100644 --- a/src/js/Draw/L.PM.Draw.Cut.js +++ b/src/js/Draw/L.PM.Draw.Cut.js @@ -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) { diff --git a/src/js/Draw/L.PM.Draw.Line.js b/src/js/Draw/L.PM.Draw.Line.js index 02439788..58b222f1 100644 --- a/src/js/Draw/L.PM.Draw.Line.js +++ b/src/js/Draw/L.PM.Draw.Line.js @@ -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) { diff --git a/src/js/Draw/L.PM.Draw.Polygon.js b/src/js/Draw/L.PM.Draw.Polygon.js index f42c1458..57394dfd 100644 --- a/src/js/Draw/L.PM.Draw.Polygon.js +++ b/src/js/Draw/L.PM.Draw.Polygon.js @@ -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); } }, }); diff --git a/src/js/Draw/L.PM.Draw.Rectangle.js b/src/js/Draw/L.PM.Draw.Rectangle.js index fd78d132..39be6706 100644 --- a/src/js/Draw/L.PM.Draw.Rectangle.js +++ b/src/js/Draw/L.PM.Draw.Rectangle.js @@ -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() { diff --git a/src/js/Draw/L.PM.Draw.Text.js b/src/js/Draw/L.PM.Draw.Text.js index b9b831c1..c141c367 100644 --- a/src/js/Draw/L.PM.Draw.Text.js +++ b/src/js/Draw/L.PM.Draw.Text.js @@ -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); @@ -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;