0

I am working with Django and geemap modules, in which I am trying to make an app that can display satellite data on the map and the map should also be interactive as in there should be a bidirectional flow of data from the front-end(Django template) to back-end(python script) and vice-versa.

As of now I only know how to display the instance of geemap.Map() on Jupyter Notebook cell or on Colab(we just need to write the name of the variable for it.). But, I have no idea about how can i display the instance of geemap.Map() in Django Template.

When I use the following method it just prints the instance object as a dictionary instead of interpreting it as a map and displaying the same.

The code for my views.py

from django.http import HttpResponse
from django.shortcuts import render
import geemap as gm
#import pandas as pd

def params(request):
   g_map = gm.Map()
   return render(request, "PlotMap/params.html", { "m" : g_map })

The code for the template(params.html)

<!DOCTYPE html>
{% load static %}
<html>
    <head>
        <meta charset="utf-8">
        <title>map</title>
        
    </head>
    <body>
       {{ m }}
    </body>
</html>

The output that I get is as follows. output

If someone can help me out, It would mean a lot Thank you.

DK77
  • 1
  • 3

1 Answers1

0

You can use geemap.foliumap.Map() or folium.Map()

Code for html template

<!DOCTYPE html>
{% load static %}
<html>
    <head>
        <meta charset="utf-8">
        <title>map</title>
        {{ map.header.render|safe }}

    </head>
    <body>
       <div class="map">
         {{ map.html.render|safe }}
       </div>
    </body>
    <script> {{ map.script.render | safe }}</script>
</html>

Code for backend (views.py)

import folium

import geemap.foliumap as geemap

class map(TemplateView): 
    template_name = 'map.html'

    def get_context_data(request):

        figure = folium.Figure()

        Map = geemap.Map(plugin_Draw = True, 
                         Draw_export = True)

        Map.add_to(figure)

        figure.render()

        return {"map": figure}

Code for urls.py

urlpatterns = [
    path('', views.map.as_view(), name = 'map'),
]
Kevs
  • 1
  • Thank You for the help, I am actually working on another task for now, but as soon as I finish it. I will be trying to out your code. If it works, it would mean a lot, Thank you. Also is there any resource from where I can gain the knowledge of plotting geemaps as you showed above and manipulating it. As i was not able to find anything like this in the official documentation for geemap. – DK77 Feb 25 '22 at 12:16