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

Duplicate event using custom toolbar #1027

Open
6 tasks done
adamleemiller opened this issue Aug 28, 2021 · 0 comments
Open
6 tasks done

Duplicate event using custom toolbar #1027

adamleemiller opened this issue Aug 28, 2021 · 0 comments

Comments

@adamleemiller
Copy link

adamleemiller commented Aug 28, 2021

  • I'm reporting a bug, not asking for help
  • I've looked at the documentation to make sure the behaviour is documented and expected
  • I'm sure this is a Leaflet Draw code issue, not an issue with my own code nor with the framework I'm using (Cordova, Ionic, Angular, React…)
  • I've searched through the issues to make sure it's not yet reported

How to reproduce

  • Leaflet version I'm using: 1.7.1
  • Leaflet Draw version I'm using: 1.0.4
  • Browser (with version) I'm using: Firefox 92.0b2 (64-bit)
  • OS/Platform (with version) I'm using: macOS 11.5

What behaviour I'm expecting and which behaviour I'm seeing

I have a custom toolbar that allows to drop a marker and draw a polygon. Once the marker is dropped or the polygon is placed, I add the object to the map and then I call another function to put some data into my database via an API request. At this point, if I create another marker and / or polygon, both the new object and the previously drawn object are both passed as event thus, creating duplications.

const draw = new this.$leaflet.Draw.Marker(this.map.object)

draw.enable()

this.map.object.on('draw:created', (event) => {
  event.layer.addTo(this.map.object)
  this.doCreateAnnotation(event)
})

Which then calls:

doCreateAnnotation (event) {
  console.log(event)
}

Which console logs to different objects when I expect only the newest one. I have tried using removeHooks() however when I do this, I get the following error:

Uncaught TypeError: can't access property "dispose", this._tooltip is null

Minimal example reproducing the issue

  • this example is as simple as possible
  • this example does not rely on any third party code

The example is not easy to reproduce since I am using a custom toolbar. If no one can help because I did not provide an example, I understand and you can close this. I assume this should be pretty simple but I have struggled for 2 hours trying to figure out how to reset everything. I even tried map.removeControl(draw) but I get an error that removeControl does not exist presumably because I am not using L.Control.Draw and instead I am using L.Draw? I am not sure why I cannot use L.Control.Draw but when I do it is also undefined.

Any help is appreciated. Thank you.

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

No branches or pull requests

1 participant