Skip to content

Commit

Permalink
Added geocode_zoom option for setting zoom level used to display the …
Browse files Browse the repository at this point in the history
…geocode result
  • Loading branch information
prusswan committed Jan 6, 2024
1 parent f716052 commit 5c7d7a0
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion folium/plugins/geocoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ class Geocoder(JSCSSMixin, MacroElement):
Choose from 'topleft', 'topright', 'bottomleft' or 'bottomright'.
add_marker: bool, default True
If True, adds a marker on the found location.
geocode_zoom: int, default 11
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.
geocode_provider: str, default 'nominatim'
Defaults to "nominatim", see https://github.com/perliedman/leaflet-control-geocoder/tree/2.4.0/src/geocoders for other built-in providers.
geocode_provider_options: dict, default {}
Expand All @@ -45,7 +47,8 @@ class Geocoder(JSCSSMixin, MacroElement):
L.Control.geocoder(
geocoderOpts_{{ this.get_name() }}
).on('markgeocode', function(e) {
{{ this._parent.get_name() }}.setView(e.geocode.center, 11);
var zoom = geocoderOpts_{{ this.get_name() }}['geocodeZoom'] || {{ this._parent.get_name() }}.getZoom();
{{ this._parent.get_name() }}.setView(e.geocode.center, zoom);
}).addTo({{ this._parent.get_name() }});
{% endmacro %}
Expand All @@ -70,6 +73,7 @@ def __init__(
collapsed: bool = False,
position: str = "topright",
add_marker: bool = True,
geocode_zoom: int | None = 11,
geocode_provider: str = "nominatim",
geocode_provider_options: dict = {},
**kwargs
Expand All @@ -80,6 +84,7 @@ def __init__(
collapsed=collapsed,
position=position,
default_mark_geocode=add_marker,
geocode_zoom=geocode_zoom,
geocode_provider=geocode_provider,
geocode_provider_options=geocode_provider_options,
**kwargs
Expand Down

0 comments on commit 5c7d7a0

Please sign in to comment.