Skip to content

Search Class Ignores "show" Argument. #2377

Open

Description

@lemoaxre

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')

Link to example data that was used.

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

  1. changed the title [-]folium.plugins.search.py bug[/-] [+]Search Class Ignores "show" Argument.[/+] on Nov 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions