Leaflet controls: onAdd() -> "ready" event

المشرف العام

Administrator
طاقم الإدارة
I've got a custom control for Leaflet (0.7.3) that uses L.DomUtil.create to generate its own HTML in the onAdd() function. Most of its bootstrapping happens in onAdd(), but I need to do some final template things once the control is added to the DOM and rendered. Let's call these final steps myControl.engage().

Looking at the source for the Control class, it's clear that onAdd() gets called before the control is injected into the DOM. And the built-in initialize() constructor function gets called even before that.

Obviously it's easy enough to do this:

var myControl = L.control.myControl().addTo(map); myControl.engage(map); // finish initializing the control But is there some way I could build that into the control without requiring a manual call to engage()? Some kind of Control.ready event, or an onReady() function that I could leverage or create myself?



أكثر...
 
أعلى