1

I'm creating a map in the Folium library of Python. I'm also adding an additional terrain base map tile by using the following code:

import folium

m=folium.Map(location=[39.084916577250254,-94.5798510242038],
             tiles='Open Street Map',
             zoom_start=12,
             min_zoom=11)

folium.TileLayer(
          'Stamen Terrain', 
          name = 'Terrain'
          ).add_to(m)

folium.LayerControl().add_to(m)

m

The map renders without a problem, but I'm wondering if / how it's possible to rename the default base map on the dropdown control box here:

enter image description here

In this example, the 'Terrain' tile allows a name = argument to input a custom label on the map's control box, but I can't figure out how to do this for the default Open Street Map.

It bothers me that it's labelled 'openstreetmap' in all lowercase without any spaces. I'd prefer the control box to read 'Open Street Map' or something a bit nicer there. You would think I could input an argument in the initial folium.map() function, but I don't see such an argument.

Meta: let me know if this post is more appropriate for SO. I never know when it comes to questions like these.

1 Answer 1

2

You can add custom way after disabling the default option.

m = Map(tiles=None)

folium.raster_layers.TileLayer(tiles='openstreetmap', name='my name').add_to(m)

Source: https://github.com/python-visualization/folium/issues/1316

1
  • 1
    Ruddy brilliant! Thanks, this is perfect. Will accept this as the correct answer
    – Will
    Apr 29, 2022 at 15:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.