B
B
Borodat Inzhenerovich2020-04-09 17:26:41
JavaScript
Borodat Inzhenerovich, 2020-04-09 17:26:41

How to dynamically render leaflet popup content passed to template from Django view?

Good day to all! The question is:

There is a leaflet map with a pop-up marker on it. By clicking on the marker in the popup, the content that is transferred to this template from django view is displayed. Content is model fields that are updated periodically. It is necessary to make it so that the user, by clicking on the marker, sees a popup, the content of which changes in accordance with the changes in the model.

That is, I need a way that will force the html inside the popup to be updated at a given interval.

An example structure is this:

Django view:

def mapTomsk(request):
    data = TEMP.objects.get(name='NAME').SOMETHING

    return render_to_response('myApp/map.html', {'data': data})


In map.html template:

<div id="map" style="width: 100%; height: 100%; position: absolute"></div>
           <script>
                DG.then(function() {
                    var map = DG.map('map', {
                        center: [XX.XX, XX.XX],
                        zoom: 13
                    });
                    
                    myIcon = DG.icon({
                        iconUrl: "{% static 'myapp/icon.svg' %}",
                        iconSize: [20, 20]
                    });
                    
                    DG.marker([XX.XX, XX>XX], {
                        icon: myIcon
                    }).bindPopup('<div id="toRefresh"> {{ data }}</div>', {
                        sprawling: true,
                        maxWidth: 200,
                        autoPanPaddingTopLeft: [400, 400]
                    }).addTo(map)
                });
            </script>


Thanks in advance for any help!

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question