如何在Django模板中显示geemap.Map()的实例 [英] How to display an instance of geemap.Map() in Django Template
本文介绍了如何在Django模板中显示geemap.Map()的实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用Django和geemap模块,在其中我试图制作一个可以在地图上显示卫星数据的应用程序,并且地图也应该是交互式的,因为应该有从前端(Django模板)到后端(Python脚本)的双向数据流。
到目前为止,我只知道如何在Jupyter Notebook cell或Colab上显示geemap.Map()的实例(我们只需要为它编写变量的名称)。但是,我不知道如何在Django模板中显示geemap.Map()的实例。
当我使用以下方法时,它只是将实例对象打印为字典,而不是将其解释为映射并显示相同的映射。
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 })
模板代码(params.html)
<!DOCTYPE html>
{% load static %}
<html>
<head>
<meta charset="utf-8">
<title>map</title>
</head>
<body>
{{ m }}
</body>
</html>
我得到的输出如下。output
如果有人能帮我,那就太好了,谢谢。
推荐答案
您可以使用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'),
]
这篇关于如何在Django模板中显示geemap.Map()的实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文