Skip to content

Conversation

DedaDev
Copy link
Contributor

@DedaDev DedaDev commented Mar 29, 2025

This PR is addressing #1407 and this issue

Creating a custom control inside useEffect would throw the error 'Button with this name already exists'. This occurs because there was no option to remove the custom button from the toolbar when a component unmounts.

codesandbox

This is a crucial feature for the React app as it removes custom components from both the toolbar and the UI. Currently, we only have the removeControls function, which removes controls from the UI.

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.

Let us add in L.PM.Toolbar the new method deleteControl and make it only callable there. The custom control creation is called over map.pm.Toolbar too.

We don't need a option to delete all controls at once. The user can keep track of the custom controls by him self.

Please revert your changes and add the following code in Toolbar and adjust the type definition.

  deleteControl(name) {
    const btnName = this._btnNameMapping(name);
    if (this.buttons[btnName]) {
      this.buttons[btnName].remove();
      delete this.buttons[btnName];
    }
  }

@DedaDev DedaDev force-pushed the unmounting-cutstom-controlls branch from 20fe86a to 2fedd39 Compare April 26, 2025 03:03
@DedaDev
Copy link
Contributor Author

DedaDev commented Apr 26, 2025

The user can keep track of the custom controls by him self.

Yeah, that is actually a better approach.
Updated 👍

@Falke-Design Falke-Design merged commit 8952807 into geoman-io:develop Apr 27, 2025
1 check passed
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.

2 participants