In case the default tile is chosen (OpenStreetMap) during the creation of the map (or other built-in tiles, the ones present in the template/tiles folder), no attribution is showing up on the bottom left of maps.
import folium
m = folium.Map(location=[45.5236, -122.6750])
Looking into the code, it seems that the file attr.txt for each built-in tile is well read, but nothing is done with it, the template does't refer to attr and the options is not updated:
Here is the template:
_template = Template(u"""
{% macro script(this, kwargs) %}
var {{ this.get_name() }} = L.tileLayer(
{{ this.tiles|tojson }},
{{ this.options|tojson }}
).addTo({{ this._parent.get_name() }});
{% endmacro %}
""")
and an extract of the code (raster_layers.py) that is supposed to set the self.attr attribute:
python
attr_template = 'tiles/' + tiles_flat + '/attr.txt'
if tile_template in templates and attr_template in templates:
self.tiles = self._env.get_template(tile_template).render(API_key=API_key) # noqa
self.attr = self._env.get_template(attr_template).render()
else:
self.tiles = tiles
if not attr:
raise ValueError('Custom tiles must have an attribution.')
self.attr = attr
Am I missing something ?
You're right! Attribution is broken, that's embarrassing :p
It should be a field in self.options with key attribution. We don't need self.attr. See https://leafletjs.com/reference-1.4.0.html#tilelayer-attribution
Do you want to make a PR for this?
Ok @Conengmo, I plan to work on the PR today.
Most helpful comment
Ok @Conengmo, I plan to work on the PR today.