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
Geocoder plugin: support other built-in providers (#1852)
* expanding Geocoder plugin to support other built-in providers supported by leaflet-control-geocoder
* Added geocode_zoom option for setting zoom level used to display the geocode result
* fixed docstring and type notation for geocode_zoom
* dropped geocode_ prefix in arguments
* fixed import block (ruff --fix)
Copy file name to clipboardExpand all lines: folium/plugins/geocoder.py
+36-4Lines changed: 36 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -1,3 +1,5 @@
1
+
fromtypingimportOptional
2
+
1
3
frombranca.elementimportMacroElement
2
4
fromjinja2importTemplate
3
5
@@ -19,6 +21,12 @@ class Geocoder(JSCSSMixin, MacroElement):
19
21
Choose from 'topleft', 'topright', 'bottomleft' or 'bottomright'.
20
22
add_marker: bool, default True
21
23
If True, adds a marker on the found location.
24
+
zoom: int, default 11, optional
25
+
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.
26
+
provider: str, default 'nominatim'
27
+
Defaults to "nominatim", see https://github.com/perliedman/leaflet-control-geocoder/tree/2.4.0/src/geocoders for other built-in providers.
28
+
provider_options: dict, default {}
29
+
For use with specific providers that may require api keys or other parameters.
22
30
23
31
For all options see https://github.com/perliedman/leaflet-control-geocoder
24
32
@@ -27,10 +35,22 @@ class Geocoder(JSCSSMixin, MacroElement):
27
35
_template=Template(
28
36
"""
29
37
{% macro script(this, kwargs) %}
38
+
39
+
var geocoderOpts_{{ this.get_name() }} = {{ this.options|tojson }};
40
+
41
+
// note: geocoder name should start with lowercase
42
+
var geocoderName_{{ this.get_name() }} = geocoderOpts_{{ this.get_name() }}["provider"];
43
+
44
+
var customGeocoder_{{ this.get_name() }} = L.Control.Geocoder[ geocoderName_{{ this.get_name() }} ](
0 commit comments