我正在使用Django和geemap模块,在这些模块中,我试图制作一个应用程序,它可以在地图上显示卫星数据,地图也应该是交互式的,因为应该有一个从前端(Django模板)到后端(python脚本)的双向数据流,反之亦然。
到目前为止,我只知道如何在木星笔记本或Colab上显示geemap.Map()的实例(我们只需要为它编写变量的名称)。但是,我不知道如何在Django模板中显示geemap.Map()实例。
当我使用以下方法时,它只是将实例对象打印为字典,而不是将其解释为映射并显示相同的内容。
我的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 })模板的代码(params.html)
<!DOCTYPE html>
{% load static %}
<html>
<head>
<meta charset="utf-8">
<title>map</title>
</head>
<body>
{{ m }}
</body>
</html>我得到的输出如下。输出
如果有人能帮我,那就意味着非常感谢你。
发布于 2022-02-25 00:39:55
您可以使用geemap.foliumap.Map()或folium.Map()
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'),
]https://stackoverflow.com/questions/71233305
复制相似问题