From f34946462b4b32f82704ea8895fd4f638f57af06 Mon Sep 17 00:00:00 2001 From: Volodymyr Borysenko Date: Fri, 27 Nov 2026 00:11:34 -0800 Subject: [PATCH] Respect show in TimestampedWmsTileLayers --- folium/plugins/timestamped_wmstilelayer.py | 5 ++- .../plugins/test_timestamped_wmstilelayer.py | 39 +++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 tests/plugins/test_timestamped_wmstilelayer.py diff --git a/folium/plugins/timestamped_wmstilelayer.py b/folium/plugins/timestamped_wmstilelayer.py index 27ecd8dad1..23ab779505 100644 --- a/folium/plugins/timestamped_wmstilelayer.py +++ b/folium/plugins/timestamped_wmstilelayer.py @@ -82,7 +82,10 @@ class TimestampedWmsTileLayers(JSCSSMixin, MacroElement): updateTimeDimension: false, wmsVersion: {{ layer.options['version']|tojson }}, } - ).addTo({{ this._parent.get_name() }}); + ); + {%- if layer.show %} + {{ layer.get_name() }}.addTo({{ this._parent.get_name() }}); + {%- endif %} {% endfor %} {% endmacro %} """) diff --git a/tests/plugins/test_timestamped_wmstilelayer.py b/tests/plugins/test_timestamped_wmstilelayer.py new file mode 100644 index 0000000000..279e918307 --- /dev/null +++ b/tests/plugins/test_timestamped_wmstilelayer.py @@ -0,0 +1,39 @@ +""" +Test TimestampedWmsTileLayers +----------------------------- + +""" + +import folium +from folium import plugins +from folium.utilities import normalize + + +def test_timestamped_wms_tile_layers_respects_show(): + m = folium.Map() + hidden = folium.WmsTileLayer( + url="https://example.com/wms", + layers="hidden", + name="Hidden", + overlay=True, + show=False, + ).add_to(m) + shown = folium.WmsTileLayer( + url="https://example.com/wms", + layers="shown", + name="Shown", + overlay=True, + ).add_to(m) + plugins.TimestampedWmsTileLayers([hidden, shown]).add_to(m) + folium.LayerControl().add_to(m) + + out = normalize(m._parent.render()) + + def wrapped(layer): + start = out.index(f"var {layer.get_name()} = L.timeDimension.layer.wms(") + end = out.find("var ", start + 1) + return out[start:end] + + assert ".addTo(" not in wrapped(hidden) + assert f"{shown.get_name()}.addTo({m.get_name()});" in wrapped(shown) + assert f'"Hidden" : {hidden.get_name()},' in out