Flask中的Python ArcGIS

2024-05-13 18:34:12 发布

您现在位置:Python中文网/ 问答频道 /正文

有没有办法在Flask应用程序中使用ArcGIS Python API,检索一个WebMap并将其传递到模板HTML中显示?我可以在Jupyter笔记本中看到这一点,但不确定如何为Flask创建一个解决方案

这是一个代码片段,我正试图将其合并成一些有效的东西。 Python部分:

from flask import Flask
from flask import render_template
from flask_cors import CORS
from arcgis.gis import GIS
from arcgis.mapping import WebMap
from arcgis.widgets import MapView

app = Flask(__name__)
CORS(app)


def get_map():
    gis = GIS("https://pythonapi.playground.esri.com/portal", "arcgis_python", "amazing_arcgis_123")
    search_result = gis.content.search("title:Natural Disasters (FC only) Collection", item_type="Web Map")
    wm_item = search_result[0]
    web_map = WebMap(wm_item)
    map_view = MapView(gis, web_map, mode='2D')
    return map_view


@app.route('/')
def index():
    """Return the main page."""
    gis_map = get_map()
    return render_template('index.html', **locals())
...

和HTML格式:

<body>
  <div id="map">{{ gis_map }}</div>

 </body>
</html>

Tags: fromimportappflaskmapsearchhtmltemplate