diff --git a/CHANGES b/CHANGES index a6222f2b..00704bc4 100644 --- a/CHANGES +++ b/CHANGES @@ -28,13 +28,11 @@ CHANGELOG **Features** * Add ability to associate layers attributions from settings - * Add ``auto-include`` key for entries in ``PLUGINS`` setting, in order to implicity load plugins with ``leaflet_css`` and ``leaflet_js`` tags. - * Rewrote map initialization, into less flexible and obstruvise way. - * Use plugin system for Leaflet.MiniMap. +* Add ``loadevent`` parameter to ``leaflet_map`` tag. 0.6.0 (2013-08-08) diff --git a/README.rst b/README.rst index 162881fe..48c07903 100644 --- a/README.rst +++ b/README.rst @@ -226,6 +226,11 @@ Advanced usage Useful to put the javascript code in the header or footer instead of the body of the html document. If used, do not forget to create the div manually. +* ``loadevent``: One or more space-separated *window* events that trigger map initialization. + (Default: ``load``, i.e. all page resources loaded). + If empty values is provided, then map initialization is immediate. + And with a wrong value, the map is never initialized. :) + Projection ---------- diff --git a/leaflet/templates/leaflet/map_fragment.html b/leaflet/templates/leaflet/map_fragment.html index fdd7caeb..30ebbb1f 100644 --- a/leaflet/templates/leaflet/map_fragment.html +++ b/leaflet/templates/leaflet/map_fragment.html @@ -9,8 +9,10 @@ globals: {{ NO_GLOBALS|yesno:"false,true"}}, callback: {{ callback}}}; L.Map.djangoMap('{{ name }}', options); } - if (window.addEventListener) window.addEventListener("load", loadmap, false); - else if (window.jQuery) jQuery(window).on("load", loadmap); + var loadevents = {% autoescape off %}{{ loadevents }}{% endautoescape %}; + if (loadevents.length === 0) loadmap(); + else if (window.addEventListener) for (var i=0; i