-
Notifications
You must be signed in to change notification settings - Fork 433
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
Additional Custom Control Methods #1295
Conversation
- adds `buttonExists(name: string)` to get the status of a button - adds `getCustomButtons()` that returns an object of all of the custom controls - ts definitions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please check my review.
If you want, it would be helpful to have following methods too:
- L.Controls:
disabled() {return !!this._button.disabled}
- L.Controls:
visible(){return !!this._map}
- L.Controls:
getButtonsOptions() {return this._button}
src/js/Toolbar/L.PM.Toolbar.js
Outdated
getCustomControls() { | ||
return Object.fromEntries( | ||
Object.entries(this.getButtons()).filter( | ||
([, v]) => v._button.tool === 'custom' | ||
) | ||
); | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let us make this more general:
getCustomControls() { | |
return Object.fromEntries( | |
Object.entries(this.getButtons()).filter( | |
([, v]) => v._button.tool === 'custom' | |
) | |
); | |
}, | |
getButtonsInBlock(name) { | |
const buttonsInBlock = {}; | |
if(name){ | |
for(const buttonName in map.pm.Toolbar.getButtons()){ | |
const button = map.pm.Toolbar.getButtons()[buttonName]; | |
// draw controls doesn't have a block | |
if(button._button.tool === name || (name === 'draw' && !button._button.tool)){ | |
buttonsInBlock[buttonName] = button; | |
} | |
} | |
} | |
return buttonsInBlock; | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And please add tests for the new methods
Apologies for the delay @Falke-Design, finally came back to this and fixed suggestions. |
Thank you for your contribution! |
Motivation is for React reasons, since an error is thrown if a button has already been mounted (when the component rerenders...), these checks are helpful to avoid issues.
buttonExists(name: string)
to get the status of a buttongetCustomButtons()
that returns an object of all of the custom controls