ipyleaflet icon indicating copy to clipboard operation
ipyleaflet copied to clipboard

ColorFilter options for maptiles

Open tberends opened this issue 1 year ago • 1 comments

I would like to give maptiles a grayscale. Is the colorfilter availabe for tiled maplayers in ipyleaflet, like the following plugin in leaflet? And if yes, is there an example code snippet how to use it?

https://github.com/Leaflet/Leaflet/blob/93f681c488ec07690cd4a393056078cf88f3bcff/docs/_plugins/tile-image-display/leaflet-tilelayer-colorfilter.md?plain=1#L4

Thanks in advance!

tberends avatar Aug 07 '24 17:08 tberends

I found a 'hacky' work around so the grayscale can be displayed in the widget in Python. Unfortunately it isn't working for a map saved to html.

from ipyleaflet import Map, basemaps, TileLayer,
from branca.colormap import linear
from IPython.display import display, HTML

# Set basemap of the map
m = Map( zoom=10, basemap=basemaps.Esri.WorldImagery, scroll_wheel_zoom=True)

# Add a grayscale filter using custom CSS
display(HTML("""
<style>
    .leaflet-tile {
        filter: grayscale(100%);
    }
</style>
"""))

# Set size of the map
m.layout.height = '800px'
m.layout.width = '1000px'

# Save the map as html file
m.save('map.html')
m

tberends avatar Aug 07 '24 19:08 tberends