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

after hiding and showing the component multiple times it will execute onDrawCreate multiple times #30

Open
johhansantana opened this issue May 31, 2019 · 2 comments

Comments

@johhansantana
Copy link

I'm trying to hide the controls until the user presses a button to add points to the map.

At first just doing:

{mapIsEditable &&
<DrawControl
  ref={drawControl}
  controls={{
    point: true,
    polygon: true,
    trash: true
  }}
  onDrawCreate={({ features }) => {
    console.log('FEATURES: ', features)
  }
  ...
/>;
}

seemed to work well until I try to toggle the controls multiple times, then the onDrawCreate gets executed the same amount of times I toggled the component.

I've tried using:

<DrawControl
  ref={drawControl}
  controls={{
    point: props.mapIsEditable,
    polygon: props.mapIsEditable,
    trash: props.mapIsEditable
  }}
  ...
/>;

But this way the controls never show up when I toggle the prop.

Is there a way to toggle these or fix this error?

@Azerothian
Copy link

Azerothian commented Jun 9, 2020

https://gist.github.com/Azerothian/be9d75f569a89ecd7e5ba5f25a1cb0f4

This works

@amaury1093
Copy link
Owner

@Azerothian that's a good idea! Do you want to create a PR with your modifications?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants