Leaflet / Leaflet.draw

Vector drawing and editing plugin for Leaflet
https://leaflet.github.io/Leaflet.draw/docs/leaflet-draw-latest.html
MIT License
1.98k stars 994 forks source link

Cannot read property 'updateContent' of undefined #822

Closed joshkopecek closed 6 years ago

joshkopecek commented 6 years ago

How to reproduce

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

Should be able to manually edit shapes (I control the editing behaviour so users can only edit one shape at a time), but get this updateContent error

Minimal example reproducing the issue

This jsfiddle reproduces the problem faithfully. Check the console log for the error - it's due to line 35 in this file. The problem here is that _editTooltip hasn't been set up because noone clicked the pencil 'edit' button in the toolbar, since the edit state is triggered manually. A simple if (this._map.hasOwnProperty('_editTooltip')) {… here would fix this, but I don't know if you want to cater for this eventuality?

joshkopecek commented 6 years ago

FYI I made a temporary fix by adding this hack to the setup

map._editTooltip = {
    updateContent: foo => null
}
ddproxy commented 6 years ago

@joshkopecek Thank you for this issue, as you've pointed out - it's not a normal process to trigger editing a geometry programatically. However, this is a valid bug. 1.0.1 has been release to check for the tooltip before attempting to modify it. Let me know if that resolves the issue :)

joshkopecek commented 6 years ago

@ddproxy I've been using this for a while - it's very useful functionality for me to be able to enable/disable editing on individual shapes.

Huge thanks for the commit. Much appreciated, I can take my ugly hack out now :-)

The examples for edit handlers makes use of this this functionality, although that example shows a Uncaught TypeError: Cannot read property 'className' of undefined

ddproxy commented 6 years ago

I also enable/disable editing programmatically. I ended up maintaining this package because I got a bit too close to the source. While it's not complete, there's a fancy rewrite using Leaflet.Editable over in the 2.0.0-fork branch that is aiming at being more friendly for plugins (and this type of use).