我正在使用Django和geemap模块,在这些模块中,我试图制作一个可以在地图上显示卫星数据的应用程序,地图也应该是交互式的,因为应该有从前端(Django模板(到后端(python脚本(的双向数据流,反之亦然。
到目前为止,我只知道如何显示geemap的实例。Jupyter Notebook单元格或Colab上的Map(((我们只需要为它写下变量的名称。(。但是,我不知道如何显示geemap的实例。Django模板中的Map((。
当我使用以下方法时,它只是将实例对象打印为字典,而不是将其解释为映射并显示。
我的视图.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 })
模板(params.html(的代码
<!DOCTYPE html>
{% load static %}
<html>
<head>
<meta charset="utf-8">
<title>map</title>
</head>
<body>
{{ m }}
</body>
</html>
我得到的输出如下。输出
如果有人能帮我,那将意义重大。谢谢。
您可以使用geemap.folimap.Map((或folium。映射((
html模板代码
<!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>
后端(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}
urls.py 的代码
urlpatterns = [
path('', views.map.as_view(), name = 'map'),
]