Folium: Custom name for base map on layer control

Created on 27 Jul 2019  路  4Comments  路  Source: python-visualization/folium

This is more a question then an issue. How can I give to the main map layer a name to appear on layer control?

Because when we create the main layer using folium.Map() what appears on the layer control is the tiles name. Can it be change?
Thanks!

question

Most helpful comment

Yes, you can use a custom name. You will have to use foliums TileLayer class directly. The Map class normally creates a TileLayer object with some default settings. You can disable that by setting tiles=None.

m = folium.Map((0, 0), tiles=None)
folium.TileLayer('cartodbpositron', name='my tilelayer').add_to(m)

All 4 comments

Yes, you can use a custom name. You will have to use foliums TileLayer class directly. The Map class normally creates a TileLayer object with some default settings. You can disable that by setting tiles=None.

m = folium.Map((0, 0), tiles=None)
folium.TileLayer('cartodbpositron', name='my tilelayer').add_to(m)

@Conengmo , thanks for explaining. Only to be more convenient I made this #1191 PR so we can pass the name more straightforward. What do you think?

I'd rather not overload the Map parameters even more. It's already quite crowded. We recently even removed some of the parameters, check out https://github.com/python-visualization/folium/pull/1127.

The current idea is that Map creates a TileLayer with some very common defaults and that for anything more complicated you have to call TileLayer yourself. Such as when you want to set a custom name.

Okay, I'm seeing it. I wasn't aware about all that map api pruning.
I thought that giving to the main map layer a name isn't something so complicated that should be necessary two lines of code to do it. However I'm okay with closing the PR. Thanks for your explanation :+1:

Was this page helpful?
0 / 5 - 0 ratings

Related issues

spanishinquistion picture spanishinquistion  路  16Comments

xhx509 picture xhx509  路  15Comments

themiurgo picture themiurgo  路  19Comments

reaganch picture reaganch  路  13Comments

agravier picture agravier  路  26Comments