Skip to content

Instantly share code, notes, and snippets.

@frague59
Created May 5, 2017 08:56
Show Gist options
  • Save frague59/63e41b77643e438cf20a017c09977d40 to your computer and use it in GitHub Desktop.
Save frague59/63e41b77643e438cf20a017c09977d40 to your computer and use it in GitHub Desktop.
Updates to use __PREFIX__ template variable.
<!-- wagtailleaflet/templates/leaflet/widget.html -->
{% load leaflet_tags %}
{% load static from staticfiles %}
<style type="text/css">{% block map_css %}
{% if map_width and map_height %}#{{ id_map }} { width: {{ map_width }}; height: {{ map_height }}; }{% endif %}
{% if not display_raw %}#{{ id }} { display: none; }{% endif %}
{% endblock map_css %}
</style>
<script type="text/javascript">
{% block vars %}
window.DEBUG_LEAFLET = true;
window.DEBUG_LEAFLET && console.debug('widget.html : id_map = ' + '{{ id_map }}');
window.LEAFLET_DATA = window.LEAFLET_DATA || {};
window.LEAFLET_DATA['{{ id_map }}'] = {};
window.LEAFLET_DATA['{{ id_map }}'].fieldid = '{{ id }}';
window.LEAFLET_DATA['{{ id_map }}'].modifiable = {{ modifiable|yesno:"true,false" }};
window.LEAFLET_DATA['{{ id_map }}'].geom_type = '{{ geom_type }}';
window.LEAFLET_DATA['{{ id_map }}'].srid = {{ map_srid }};
{% endblock vars %}
window.LEAFLET_FUNCTIONS = window.LEAFLET_FUNCTIONS || {};
window.LEAFLET_FUNCTIONS['{{ id_map }}'] = function(map, options) {
window.LEAFLET_DATA['{{ id_map }}'].store_class = {{ field_store_class }};
(new {{ geometry_field_class}}(window.LEAFLET_DATA['{{ id_map }}'])).addTo(map);
{% block callback %}{% endblock callback %}
};
{% if target_map %}
window.addEventListener('map:init', function (e) {
var target_map = e.detail.map;
target_map.on('map:loadfield', function (me) {
if (me.fieldid == 'id_{{ target_map }}') {
setTimeout(function () {
window.LEAFLET_FUNCTIONS['{{ id_map }}'](target_map, e.detail.options);
}, 0);
}
});
}, false);
{% endif %}
</script>
{% if not target_map %}
{% block map %}
{% leaflet_map id_map callback=id_map_callback loadevent=loadevent settings_overrides=settings_overrides %}
{% endblock map %}
{% endif %}
{% if display_raw %}<p> Geometry:</p>{% endif %}
<textarea id="{{ id }}" class="required" cols="150" rows="10" name="{{ name }}">{{ serialized }}</textarea>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment