简体   繁体   English

Flask-Admin GeoAlchemy2 示例未显示 map

[英]Flask-Admin GeoAlchemy2 example doesn't show a map

I'm trying to run this example about how to use Flask-Admin displaying maps: https://github.com/flask-admin/flask-admin/tree/master/examples/geo_alchemy .我正在尝试运行有关如何使用 Flask-Admin 显示地图的示例: https://github.com/flask-admin/flask-admin/tree/master/examples/geo_alchemy

In README.rst, there's this instruction:在 README.rst 中有这样的指令:

  1. You will notice that the maps are not rendered.你会注意到地图没有被渲染。 To see them, you will have to register for a free account at Mapbox and set the MAPBOX_MAP_ID and MAPBOX_ACCESS_TOKEN config variables accordingly.要查看它们,您必须在 Mapbox 注册一个免费帐户并相应地设置 MAPBOX_MAP_ID 和 MAPBOX_ACCESS_TOKEN 配置变量。

I already have a valid MAPBOX_ACCESS_TOKEN, and I went to MapBox to look for a MAPBOX_MAP_ID.我已经有一个有效的 MAPBOX_ACCESS_TOKEN,我去 MapBox 寻找一个 MAPBOX_MAP_ID。 There I read that MAP_ID was deprecated, and now I'll have to obtain a tileset ID, and it's described as a label composed by <my_mapbox_user_name>.the_tileset_ID itself.在那里我读到 MAP_ID 已被弃用,现在我必须获得一个图块集 ID,它被描述为由<my_mapbox_user_name>.the_tileset_ID本身组成的 label。

So I located the code as they described in the instructions (in my case, mapbox-streets-v8) and fulfilled the config.py parameters:所以我找到了他们在说明中描述的代码(在我的例子中,mapbox-streets-v8)并满足了 config.py 参数:

MAPBOX_MAP_ID = '<my_mapbox_user_name>.mapbox-streets-v8'
MAPBOX_ACCESS_TOKEN = 'pk.eyJ1...'

However, I couldn't see any map displayed or any error message.但是,我看不到任何 map 显示或任何错误消息。

How can I fix it?我该如何解决?

I think there is a small bug in file Lib\site-packages\flask_admin\static\admin\js\form.js.我认为文件 Lib\site-packages\flask_admin\static\admin\js\form.js 中有一个小错误。 The original URL generated to get a tile is:为得到一个tile而生成的原始URL是:

https://api.mapbox.com/styles/v1/mapbox/<MAPBOX_MAP_ID parameter>/tiles/12/2258/2457?access_token=<MAPBOX_ACCESS_TOKEN parameter>

However, the correct one is:但是,正确的是:

https://api.mapbox.com/styles/v1/<MAPBOX_MAP_ID parameter>/tiles/12/2258/2457?access_token=<MAPBOX_ACCESS_TOKEN parameter>

That is, I had to remove the mapbox word from the URL.也就是说,我必须从 URL 中删除mapbox词。

To do that I made some changes in form.js file:为此,我对 form.js 文件进行了一些更改:

      //var mapboxUrl = 'https://api.mapbox.com/styles/v1/mapbox/'+window.MAPBOX_MAP_ID+'/tiles/{z}/{x}/{y}?access_token='+window.MAPBOX_ACCESS_TOKEN
      var mapboxUrl = 'https://api.mapbox.com/styles/v1/'+window.MAPBOX_MAP_ID+'/tiles/{z}/{x}/{y}?access_token='+window.MAPBOX_ACCESS_TOKEN

Then, it's working now:然后,它现在正在工作:

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM