Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: don't add Toolbar while creating new Draw Instance #956

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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