Skip to content

Commit

Permalink
Don't add toolbar to map when its updated and controls should be hidd…
Browse files Browse the repository at this point in the history
…en (#956) (patch)
  • Loading branch information
Falke-Design committed Oct 8, 2021
1 parent 7245bad commit 40c537a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
15 changes: 14 additions & 1 deletion cypress/integration/toolbar.spec.js
Expand Up @@ -194,7 +194,7 @@ describe('Testing the Toolbar', () => {
.parent('.leaflet-top.leaflet-left')
.should('exist');

cy.window().then(({ map, L }) => {
cy.window().then(({ map }) => {
let testresult = '';

// Click button -> toggle disabled
Expand Down Expand Up @@ -293,6 +293,19 @@ describe('Testing the Toolbar', () => {
});
});

it('Add new draw instance and keep Toolbar hidden', () => {
cy.window().then(({ map }) => {
map.pm.removeControls();
});
cy.get('.leaflet-pm-toolbar').should('not.exist');

cy.window().then(({ map }) => {
map.pm.Toolbar.copyDrawControl('Polygon', {name: 'PolygonCopy'});
});

cy.get('.leaflet-pm-toolbar').should('not.exist');
});

it('Custom Controls - Custom order', () => {
cy.window().then(({ map }) => {
map.pm.Toolbar.changeControlOrder(['Rectangle']);
Expand Down
11 changes: 10 additions & 1 deletion src/js/Toolbar/L.PM.Toolbar.js
Expand Up @@ -99,9 +99,9 @@ const Toolbar = L.Class.extend({

this.applyIconStyle();

this.isVisible = true;
// now show the specified buttons
this._showHideButtons();
this.isVisible = true;
},
applyIconStyle() {
const buttons = this.getButtons();
Expand Down Expand Up @@ -395,9 +395,17 @@ const Toolbar = L.Class.extend({
},

_showHideButtons() {

// if Toolbar is not visible, we don't need to update button positions
if(!this.isVisible){
return;
}

// remove all buttons, that's because the Toolbar can be added again with
// different options so it's basically a reset and add again
this.removeControls();
// we need to set isVisible = true again, because removeControls() set it to false
this.isVisible = true;

const buttons = this.getButtons();
let ignoreBtns = [];
Expand Down Expand Up @@ -441,6 +449,7 @@ const Toolbar = L.Class.extend({
buttons[btn].addTo(this.map);
}
}

},
_getBtnPosition(block) {
return this.options.positions && this.options.positions[block]
Expand Down

0 comments on commit 40c537a

Please sign in to comment.