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

Conversation

TurtIeSocks
Copy link
Contributor

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.

  • 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

- 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
Copy link
Collaborator

@Falke-Design Falke-Design left a 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}

Comment on lines 569 to 575
getCustomControls() {
return Object.fromEntries(
Object.entries(this.getButtons()).filter(
([, v]) => v._button.tool === 'custom'
)
);
},
Copy link
Collaborator

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:

Suggested change
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;
}

src/js/Toolbar/L.PM.Toolbar.js Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
Copy link
Collaborator

@Falke-Design Falke-Design left a 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

@TurtIeSocks
Copy link
Contributor Author

Apologies for the delay @Falke-Design, finally came back to this and fixed suggestions.

src/js/Toolbar/L.PM.Toolbar.js Outdated Show resolved Hide resolved
src/js/Toolbar/L.PM.Toolbar.js Show resolved Hide resolved
@Falke-Design Falke-Design merged commit 6e47f00 into geoman-io:develop Feb 27, 2024
1 check passed
@Falke-Design
Copy link
Collaborator

Thank you for your contribution!

@Falke-Design Falke-Design added this to the 2.17.0 milestone Feb 27, 2024
@TurtIeSocks TurtIeSocks deleted the extra-custom-control-methods branch February 27, 2024 22:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants