makinacorpus/django-leaflet — pull request #45 by demiurg (2013-11-14 22:59:12+00:00)
Title: expose Leaflet.draw control after its initialized

I do it in most straightforward way I could see.
Save L.GeometryField into geodjango widget variable as geodjango_geometry.geometry_field
Save Leaflet.draw instance as L.GeometryField._drawControl

Because 'map:init' event is triggered before the the draw control is saved, the most straightfarward way to do stuff that depends on draw control or other callback things, seems to me to generate 'map:aftercallback' custom event.

So, use case is this:
```
$(window).on("map:aftercallback", function (e) {
var detail = e.originalEvent ?
e.originalEvent.detail : e.detail;
var drawControl = geodjango_geometry.geometry_field._drawControl;
drawControl.setDrawingOptions({
polygon: {
allowIntersection: false,
showArea: true
},
rectangle: {
repeatMode: false
}
});
});
```
I am not sure if this is the best way, but it gets the job done for me, and it might help someone else.