MCPcopy Create free account
hub / github.com/python-visualization/folium / Geocoder

Class Geocoder

folium/plugins/geocoder.py:10–93  ·  view source on GitHub ↗

A simple geocoder for Leaflet that by default uses OSM/Nominatim. Please respect the Nominatim usage policy: https://operations.osmfoundation.org/policies/nominatim/ Parameters ---------- collapsed: bool, default False If True, collapses the search box unless hovered/cl

Source from the content-addressed store, hash-verified

8
9
10class Geocoder(JSCSSMixin, MacroElement):
11 """A simple geocoder for Leaflet that by default uses OSM/Nominatim.
12
13 Please respect the Nominatim usage policy:
14 https://operations.osmfoundation.org/policies/nominatim/
15
16 Parameters
17 ----------
18 collapsed: bool, default False
19 If True, collapses the search box unless hovered/clicked.
20 position: str, default 'topright'
21 Choose from 'topleft', 'topright', 'bottomleft' or 'bottomright'.
22 add_marker: bool, default True
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.
30
31 For all options see https://github.com/perliedman/leaflet-control-geocoder
32
33 """
34
35 _template = Template(
36 """
37 {% macro script(this, kwargs) %}
38
39 var geocoderOpts_{{ this.get_name() }} = {{ this.options|tojavascript }};
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() }} ](
45 geocoderOpts_{{ this.get_name() }}['providerOptions']
46 );
47 geocoderOpts_{{ this.get_name() }}["geocoder"] = customGeocoder_{{ this.get_name() }};
48
49 L.Control.geocoder(
50 geocoderOpts_{{ this.get_name() }}
51 ).on('markgeocode', function(e) {
52 var zoom = geocoderOpts_{{ this.get_name() }}['zoom'] || {{ this._parent.get_name() }}.getZoom();
53 {{ this._parent.get_name() }}.setView(e.geocode.center, zoom);
54 }).addTo({{ this._parent.get_name() }});
55
56 {% endmacro %}
57 """
58 )
59
60 default_js = [
61 (
62 "Control.Geocoder.js",
63 "https://unpkg.com/leaflet-control-geocoder/dist/Control.Geocoder.js",
64 )
65 ]
66 default_css = [
67 (

Callers

nothing calls this directly

Calls 1

TemplateClass · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…