python-visualization / python-visualization/folium
Request Adding Leaflet.TileLayer.MBTiles Plugin Support
还没有人认领这个 Issue。
- #1341 来自 @and-viceversa —— 已关闭,未合并
- 主要语言
- Python
- 星标
- 7.4k
- 派生
- 2.3k
- 平均合并
- 17 小时 22 分钟
- 30 天内合并 PR
- 11
描述
Is your feature request related to a problem? Please describe.
No. This feature request adds support for displaying raster tile base maps in .mbtiles format.
Describe the solution you'd like
- Make Leaflet.TileLayer.MBTiles it's own Folium plugin.
- Put the above plugin on a CDN so users aren't forced to store it locally. The original author's CDN link is broken I think.
Currently, you can use Folium and Leaflet.TileLayer.MBTiles to display .mbtiles format, but it's a bit hacky.
I used roughly the following snippet to override TileLayer._template
# override defaults to use the plugin
folium.raster_layers.TileLayer._template = Template(u"""
{% macro script(this, kwargs) %}
var {{ this.get_name() }} = L.tileLayer.mbTiles( <--------
{{ this.tiles|tojson }},
{{ this.options|tojson }}
).addTo({{ this._parent.get_name() }});
{% endmacro %}
""")
# make a Map with .mbtile basemap
m = folium.Map(
location=[35.650787, -117.661728],
tiles='my_tiles.mbtiles',
attr=attr
)
# add open street map
layer = folium.TileLayer(
tiles='https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
name='OpenStreetMap Online',
attr='© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> '
'contributors',
overlay=True,
control=True,
show=False
).add_to(m)
# function to return _template back to default after the fact.
set_tile_layer_default(layer)
Even then, you have to override TileLayer._template back to it's default before m.save('index.html') for each additional (non-mbtiles) basemap you add.
It would be really nice to:
from folium.plugins import MBTiles
m = MBTiles.Map(
location = [14.0, 15.0],
tiles = 'your_tiles_url.mbtiles',
attr = 'attr text'
)
Describe alternatives you've considered
The only alternative I can see is something like the above snippet. There was some discussion in #351.
Additional context
For those unfamiliar, one open source way to make your own tiles is by using TileMill. TileMill exports the usual {z}{x}{y} directory structure, as well as the Mapbox raster .mbtiles format. Mbtiles are preferable in some cases, because you only have to manage 1 file instead of (no joke) millions of .png files.
Also, it's great when one open source project ties cleanly into another.
Implementation
folium is maintained by volunteers. Can you help make a PR if we want to implement this feature?
I would be happy to write this PR. I have working code which accomplishes the task, just not sure how to best turn it into a plugin.
If somebody could please comment:
- Is this idea acceptable and feasible?
- A general best practices and implementation list.
Thanks.
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先检查 Folium 现有的插件结构以及 issue 中展示的 TileLayer._template 覆盖方式,然后对比已关闭的 pull request 1341。当 Leaflet.TileLayer.MBTiles 无需手动覆盖 TileLayer._template 即可作为 Folium 插件使用,并且其客户端代码可通过正常工作的 CDN 链接获取时,工作即告完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- javascript, python
- 领域
- data-visualization, frontend
- Issue 类型
- 功能
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 25/100