pythonqgisfolium

Trying to apply a coverage tile on a folium map


I am trying to create an html file using "folium" library in python, and then applying a coverage tile using "Mapillary" api, but it doesn't show up when applying this layer.

The weird thing is that on QGIS program I get this layer:

enter image description here

This is my code generating the html:

def create_map():
    my_map = folium.Map(location=[50, 0], zoom_start=8)

    vector_tile_url = "https://tiles.mapillary.com/maps/vtp/mly1_public/{z}/{x}/{y}?access_token=" + os.getenv(
        "MAPILLARY_API_KEY")

    attribution = "Map data &copy; <a href='https://mapillary.com'>Mapillary</a> contributors"

    folium.TileLayer(vector_tile_url, name="mapillary", attr=attribution, overlay=True).add_to(my_map)

    folium.LayerControl().add_to(my_map)

    my_map.save("map_with_vector_tiles.html")

    print("Map with vector tiles saved as map_with_vector_tiles.html")

Solution

  • Seems like mapillary uses protocol buffers. So, maybe you need a VectorGridProtobuf ?

    import os
    import folium
    
    m = folium.Map(location=[0, 0], zoom_start=2, width="80%", height="70%")
    
    url = (
        "https://tiles.mapillary.com/maps/vtp/"
        "mly1_public/2/{z}/{x}/{y}?access_token={token}"
    )
    
    options = {
        "token": os.getenv("MAPILLARY_API_KEY"),
        "vectorTileLayerStyles": {
            "overview": {
                "fill": True,
                "radius": 5,
                "color": "#e87147",
                "opacity": 0.6,
            },
        },
    }
    
    pbf = folium.plugins.VectorGridProtobuf(url, "mapillary", options)
    pbf.__dict__["overlay"] = True # otherwise, TypeError
    pbf.add_to(m)
    
    folium.LayerControl().add_to(m)
    
    # m.save("map.html") # uncomment to make an html
    

    NB: Feel free to add the styles for the two other layers of coverage tiles: sequence & image.

    Output (m, in Jupyter) :

    enter image description here

    Another view (centered at 50/0, showing the sequences/lines):

    enter image description here