From ebbd8490694a8f8a8c0395145eaa58733fbc0847 Mon Sep 17 00:00:00 2001 From: Florian Bischof Date: Wed, 22 Nov 2023 20:55:15 +0100 Subject: [PATCH 1/2] fter disabling & enabling of button, while a mode is active, don't call disable on the draw layer. And added that disable is not throwing an error if hintMarker is not set --- cypress/integration/toolbar.spec.js | 20 ++++++++++++++++++++ src/js/Draw/L.PM.Draw.Text.js | 2 +- src/js/Toolbar/L.Controls.js | 7 +++---- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/cypress/integration/toolbar.spec.js b/cypress/integration/toolbar.spec.js index 482c1e32..d6489bb8 100644 --- a/cypress/integration/toolbar.spec.js +++ b/cypress/integration/toolbar.spec.js @@ -500,4 +500,24 @@ describe('Testing the Toolbar', () => { expect(eventFired).to.equal('drawPolygon'); }); }); + + it("After disabling & enabling of button, while a mode is active, don't call disable on the draw layer", (done) => { + let eventFired = ''; + + cy.toolbarButton('edit').click(); + + cy.window().then(({ map }) => { + map.on('pm:drawend', ({ shape }) => { + eventFired = shape; + }); + map.pm.Toolbar.setButtonDisabled('drawText', true); + map.pm.Toolbar.setButtonDisabled('drawText', false); + }); + cy.toolbarButton('text').click(); + + cy.window().then(() => { + expect(eventFired).to.equal(''); + done(); + }); + }); }); diff --git a/src/js/Draw/L.PM.Draw.Text.js b/src/js/Draw/L.PM.Draw.Text.js index d1f93311..b9b831c1 100644 --- a/src/js/Draw/L.PM.Draw.Text.js +++ b/src/js/Draw/L.PM.Draw.Text.js @@ -74,7 +74,7 @@ Draw.Text = Draw.extend({ this._map.off('click', this._createMarker, this); // remove hint marker - this._hintMarker.remove(); + this._hintMarker?.remove(); this._map.getContainer().classList.remove('geoman-draw-cursor'); diff --git a/src/js/Toolbar/L.Controls.js b/src/js/Toolbar/L.Controls.js index 4f0d11c0..41d415b6 100644 --- a/src/js/Toolbar/L.Controls.js +++ b/src/js/Toolbar/L.Controls.js @@ -239,6 +239,9 @@ const PMButton = L.Control.extend({ }, _onBtnClick() { + if (this._button.disabled) { + return; + } if (this._button.disableOtherButtons) { this._map.pm.Toolbar.triggerClickOnToggledButtons(this); } @@ -270,13 +273,9 @@ const PMButton = L.Control.extend({ if (this._button.disabled) { L.DomUtil.addClass(button, className); button.setAttribute('aria-disabled', 'true'); - L.DomEvent.off(button, 'click', this._triggerClick, this); - L.DomEvent.off(button, 'click', this._onBtnClick, this); } else { L.DomUtil.removeClass(button, className); button.setAttribute('aria-disabled', 'false'); - L.DomEvent.on(button, 'click', this._triggerClick, this); - L.DomEvent.on(button, 'click', this._onBtnClick, this); } }, }); From 5de3106cc38fa0e72561debb8d8b0d61de3ed6b6 Mon Sep 17 00:00:00 2001 From: Florian Bischof Date: Sun, 4 Feb 2024 17:00:39 +0100 Subject: [PATCH 2/2] Fix test name --- cypress/integration/toolbar.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cypress/integration/toolbar.spec.js b/cypress/integration/toolbar.spec.js index d6489bb8..eb7bf228 100644 --- a/cypress/integration/toolbar.spec.js +++ b/cypress/integration/toolbar.spec.js @@ -501,7 +501,7 @@ describe('Testing the Toolbar', () => { }); }); - it("After disabling & enabling of button, while a mode is active, don't call disable on the draw layer", (done) => { + it("After disabling & enabling of a button, while a mode is active, don't call disable on the draw layer", (done) => { let eventFired = ''; cy.toolbarButton('edit').click();