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

Additional Custom Control Methods #1295

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions cypress/integration/toolbar.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,11 @@ describe('Testing the Toolbar', () => {
expect(testresult).to.equal('clickButton clicked');
cy.get(container).should('not.have.class', 'active');
});
expect(map.pm.Toolbar.getButton('clickButton')).to.not.equal(undefined);
expect(map.pm.Toolbar.controlExists('clickButton')).to.equal(true);
expect(
'clickButton' in map.pm.Toolbar.getButtonsInBlock('custom')
).to.equal(true);
});
});

Expand Down
12 changes: 12 additions & 0 deletions leaflet-geoman.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,18 @@ declare module 'leaflet' {
position: L.ControlPosition
): void;

/** Returns all of the active buttons */
getButtons(): Record<string, L.Control>

/** Returns the full button object or undefined if the name does not exist */
getButton(name: string): L.Control | undefined;

/** Checks whether a button has been mounted */
controlExists(name: string): boolean;

/** Returns all of the custom, active buttons */
getButtonsInBlock(name: string): Record<string, L.Control>

/** Returns a Object with the positions for all blocks */
getBlockPositions(): BlockPositions;

Expand Down
23 changes: 22 additions & 1 deletion src/js/Toolbar/L.PM.Toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,28 @@ const Toolbar = L.Class.extend({
this.changeControlOrder();
return control;
},

controlExists(name) {
return Boolean(this.getButton(name));
},
getButton(name) {
return this.getButtons()[name];
},
getButtonsInBlock(name) {
const buttonsInBlock = {};
if (name) {
for (const buttonName in this.getButtons()) {
const button = this.getButtons()[buttonName];
Falke-Design marked this conversation as resolved.
Show resolved Hide resolved
// draw controls doesn't have a block
if (
button._button.tool === name ||
(name === 'draw' && !button._button.tool)
) {
buttonsInBlock[buttonName] = button;
}
}
}
return buttonsInBlock;
},
changeControlOrder(order = []) {
const shapeMapping = this._shapeMapping();

Expand Down