Folium: Is there a way to add colormap to LayerControl?

Created on 15 Jun 2016  路  7Comments  路  Source: python-visualization/folium

First of all incredible progress from the last time I have checked folium, my respect to the team!

I am trying to use some examples from Colormaps.ipynb and it seems like the colormap is not recognised by the LayerControl as one of the layers. My question have two parts:

  • Is there a way to make LayerControl aware of the colormap?
  • Most importantly is there a way to combine the layer created, say, with GeoJson and colormap, so they are switched on and off together in the LayerControl.

At the end I would like to have 2 layers on one map, but they should have different colormaps.

feature request

Most helpful comment

Thanks to your link @koldunovn , I finally found a way of doing it. See here.

But I don't know where it should be put:

  • As a method in branca.colormap.Colormap
  • As a method in folium.map.Layer
  • As a third object as shown in the example notebook
  • As a child of one of the two objects

Well this is open to discussion (and to volunteers for a PR :wink: )

All 7 comments

In fact a Colormap is not a Layer in Leaflet's sense. So it's not trivial to add it to a LayerControl.
But it may be possible to do that in using LayersControlEvent and writing explicit code that hides/show the colormap.

@BibMartin Thanks for the reply! I certainly will not be able to implement it, since my Java Script knowledge is zero. I just found similar question here http://gis.stackexchange.com/questions/68941/how-to-add-remove-legend-with-leaflet-layers-control with an answer [EDIT, Oh I see it's basically what you have suggested]. Maybe it will help.

Anyway I think this issue now can be turned to feature quest I guess :)

Anyway I think this issue now can be turned to feature quest I guess :)

True. And that would be a useful feature btw.

Thanks for the idea and for the link :wink:

First of all incredible progress from the last time I have checked folium, my respect to the team!

Just to be fair team == @BibMartin lately :wink:

Thanks to your link @koldunovn , I finally found a way of doing it. See here.

But I don't know where it should be put:

  • As a method in branca.colormap.Colormap
  • As a method in folium.map.Layer
  • As a third object as shown in the example notebook
  • As a child of one of the two objects

Well this is open to discussion (and to volunteers for a PR :wink: )

@BibMartin This is just amasing! Exactly what I need!
From the user perspective I think it is logical to create two separate objects and then bind them together (similar to FeatureGroup, I guess)?

@BibMartin thank you for your answer that was also helpful for me.
I wanted to ask if we can adjust the background of the colormap to white or any other color so we can avoid some visibility problems caused by the colors of the map itself.
Thank you.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

reaganch picture reaganch  路  13Comments

FlorianHoevelmann picture FlorianHoevelmann  路  14Comments

achourasia picture achourasia  路  15Comments

agravier picture agravier  路  26Comments

nathan3leaf picture nathan3leaf  路  32Comments