python-visualization / python-visualization/folium

Request Adding Leaflet.TileLayer.MBTiles Plugin Support

Đang mở
#1,318 4 bình luận 3 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

  • #1341 của @and-viceversa — đã đóng, không merge
enhancement plugin
Ngôn ngữ chính
Python
Star
7.4k
Fork
2.3k
Merge trung bình
17 giờ 22 phút
Pull request đã merge (30 ngày)
11

Mô tả

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

  1. Make Leaflet.TileLayer.MBTiles it's own Folium plugin.
  2. 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='&copy; <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:

  1. Is this idea acceptable and feasible?
  2. A general best practices and implementation list.

Thanks.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu bằng cách xem lại cấu trúc plugin hiện có của Folium và phần ghi đè TileLayer._template được trình bày trong issue, sau đó so sánh với pull request đã đóng 1341. Công việc hoàn tất khi Leaflet.TileLayer.MBTiles có thể được sử dụng như một plugin Folium mà không cần ghi đè thủ công TileLayer._template, và mã phía client của nó có sẵn thông qua một liên kết CDN hoạt động.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
javascript, python
Lĩnh vực
data-visualization, frontend
Loại issue
Tính năng
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
25/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.