diff --git a/leaflet/forms/widgets.py b/leaflet/forms/widgets.py index 084fb18f..40f9bdc3 100644 --- a/leaflet/forms/widgets.py +++ b/leaflet/forms/widgets.py @@ -50,6 +50,7 @@ def render(self, name, value, attrs=None): attrs.update(id_map=map_id + '_map', id_map_callback=map_id + '_map_callback', modifiable=self.modifiable, + target_map=attrs.get('target_map', getattr(self, 'target_map', None)), geometry_field_class=attrs.get('geometry_field_class', 'L.GeometryField'), field_store_class=attrs.get('field_store_class', 'L.FieldStore')) return super(LeafletWidget, self).render(name, value, attrs) diff --git a/leaflet/static/leaflet/leaflet.extras.js b/leaflet/static/leaflet/leaflet.extras.js index 90af4d12..4398da77 100644 --- a/leaflet/static/leaflet/leaflet.extras.js +++ b/leaflet/static/leaflet/leaflet.extras.js @@ -196,7 +196,7 @@ L.Map.djangoMap = function (id, options) { /* * Trigger custom map:init Event */ - triggerEvent(window, 'map:init', {map: map, options: options}); + triggerEvent(window, 'map:init', {id: id, map: map, options: options}); /* * Run callback if specified diff --git a/leaflet/templates/leaflet/widget.html b/leaflet/templates/leaflet/widget.html index e40b48ad..bf0944c5 100644 --- a/leaflet/templates/leaflet/widget.html +++ b/leaflet/templates/leaflet/widget.html @@ -20,11 +20,25 @@ (new {{ geometry_field_class}}({{ module }})).addTo(map); {% block callback %}{% endblock callback %} }; + + {% if target_map %} + window.addEventListener('map:init', function (e) { + e.detail.map.on('map:loadfield', function (me) { + if (me.fieldid == 'id_{{ target_map }}') { + setTimeout(function () { + {{ id_map_callback }}(e.detail.map, e.detail.options); + }, 0); + } + }); + }, false); + {% endif %} +{% if not target_map %} {% block map %} {% leaflet_map id_map callback=id_map_callback %} {% endblock map %} +{% endif %} {% if display_raw %}

Geometry:

{% endif %}