Skip to content

Commit 5c7d7a0

Browse files
committed
Added geocode_zoom option for setting zoom level used to display the geocode result
1 parent f716052 commit 5c7d7a0

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

folium/plugins/geocoder.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ class Geocoder(JSCSSMixin, MacroElement):
1919
Choose from 'topleft', 'topright', 'bottomleft' or 'bottomright'.
2020
add_marker: bool, default True
2121
If True, adds a marker on the found location.
22+
geocode_zoom: int, default 11
23+
Set zoom level used for displaying the geocode result, note that this only has an effect when add_marker is set to False. Set this to None to preserve the current map zoom level.
2224
geocode_provider: str, default 'nominatim'
2325
Defaults to "nominatim", see https://github.com/perliedman/leaflet-control-geocoder/tree/2.4.0/src/geocoders for other built-in providers.
2426
geocode_provider_options: dict, default {}
@@ -45,7 +47,8 @@ class Geocoder(JSCSSMixin, MacroElement):
4547
L.Control.geocoder(
4648
geocoderOpts_{{ this.get_name() }}
4749
).on('markgeocode', function(e) {
48-
{{ this._parent.get_name() }}.setView(e.geocode.center, 11);
50+
var zoom = geocoderOpts_{{ this.get_name() }}['geocodeZoom'] || {{ this._parent.get_name() }}.getZoom();
51+
{{ this._parent.get_name() }}.setView(e.geocode.center, zoom);
4952
}).addTo({{ this._parent.get_name() }});
5053
5154
{% endmacro %}
@@ -70,6 +73,7 @@ def __init__(
7073
collapsed: bool = False,
7174
position: str = "topright",
7275
add_marker: bool = True,
76+
geocode_zoom: int | None = 11,
7377
geocode_provider: str = "nominatim",
7478
geocode_provider_options: dict = {},
7579
**kwargs
@@ -80,6 +84,7 @@ def __init__(
8084
collapsed=collapsed,
8185
position=position,
8286
default_mark_geocode=add_marker,
87+
geocode_zoom=geocode_zoom,
8388
geocode_provider=geocode_provider,
8489
geocode_provider_options=geocode_provider_options,
8590
**kwargs

0 commit comments

Comments
 (0)