You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
When folium.plugins.Search is attached to a layer with show=False (such as a folium.GeoJson layer), the show parameter is ignored and the layer is displayed when the map initially loads. To Reproduce
To reproduce this bug, it can be with any input layer, but I just chose ttc shapefiles as it is lightweight.
import folium
import folium.plugins
import geopandas as gp
gdf = gp.read_file("TTC_SUBWAY_LINES_WGS84.shp")
m = folium.Map(tiles = None, location=[43.646313, -79.384736], zoom_start=13)
tiles = folium.TileLayer(tiles="https://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer/tile/{z}/{y}/{x}/",
attr="Tiles by Esri",
name="Esri World Street Map").add_to(m)
layer = folium.GeoJson(gdf,
style_function=lambda f: {'color': 'red'},
name="Subway Lines",
show=False).add_to(m)
folium.plugins.Search(layer=layer,
geom_type="LineString",
placeholder="Search for a subway line",
search_label="ROUTE_NAME").add_to(m)
folium.LayerControl(collapsed=False).add_to(m)
m.save("out.html")
print('Map saved to out.html')
Expected behavior
I expected the data layer to be hidden on the initial map load.
Environment (please complete the following information):
Edge and Firefox
html files
Python version: 3.11.9
folium version: 1.0.0
branca version 0.8.2
Possible solutions
My personal workaround for this was to remove the layer when the map was initially loaded using a MacroElement. The solution could potentially be something as simple as:
{% if not this.show %}
{{this.map}}.removeLayer({{this.layername}});
{% endif %}
Activity
[-]folium.plugins.search.py bug[/-][+]Search Class Ignores "show" Argument.[/+]