Leaflet / Leaflet.draw

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

L.Draw.Feature.addInitHook(...) stopped working in 0.4.13 #857

Open richardhinkamp opened 6 years ago

richardhinkamp commented 6 years ago

How to reproduce

Found out about this because I'm using leaflet-snap which add an initHook here: https://github.com/makinacorpus/Leaflet.Snap/blob/5597677fe16744219c480afe7c7e7fce78cc71fd/leaflet.snap.js#L659

In #772 the events mixin was changed for leaflet 1.2+ to use L.Evented.prototype instead of L.Mixin.Events. But it was also moved from the prototype declaration to the init function. So an added init hook (L.Draw.Feature.addInitHook(function() {});) is done before the initialize function and added to the _initHooks props. In the initialize function it includes the L.Evented.prototype or L.Mixin.Events mixin which includes a property _initHooks (empty array) and so override the current added init hooks.

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

The init hook should be called, but isn't.

Minimal example reproducing the issue

With leaflet-draw 0.4.12 the init hook is called: https://jsfiddle.net/mvp7hgou/44/ With leaflet-draw 0.4.13 the init hook is not called: https://jsfiddle.net/mvp7hgou/45/

I guess L.Toolbar has the same problem.

rodriguesrl commented 4 years ago

Any update on this? I really need to use the snap plugin with leaflet draw.

diamondskrt commented 2 years ago

Any update on this? I really need to use the pin plugin with leaflet draw.

MiirzaBaig commented 9 months ago

Has it been resolved or yet to be resolved?