Skip to content

Commit 72fd048

Browse files
committed
docs and refactor jinja
1 parent aabad99 commit 72fd048

File tree

1 file changed

+29
-26
lines changed

1 file changed

+29
-26
lines changed

folium/plugins/search.py

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,19 @@ class Search(MacroElement):
1313
1414
Parameters
1515
----------
16-
position : str
17-
change the position of the search bar, can be:
18-
'topleft', 'topright', 'bottomright' or 'bottomleft'
19-
default: 'topleft'
16+
data: str/JSON
17+
GeoJSON strings
18+
search_zoom: int
19+
zoom level when searching features, default 12
20+
search_label: str
21+
label to index the search, default 'name'
22+
geom_type: str
23+
geometry type, default 'Point'
24+
position: str
25+
Change the position of the search bar, can be:
26+
'topleft', 'topright', 'bottomright' or 'bottomleft',
27+
default 'topleft'
28+
2029
See https://github.com/stefanocudini/leaflet-search for more information.
2130
2231
"""
@@ -35,26 +44,23 @@ def __init__(self, data, search_zoom=12, search_label='name', geom_type='Point',
3544
3645
{{this._parent.get_name()}}.addLayer({{this.get_name()}});
3746
38-
if ('{{this.geom_type}}' == 'Point'){
39-
var searchControl = new L.Control.Search({
40-
layer: {{this.get_name()}},
41-
propertyName: '{{this.search_label}}',
42-
initial: false,
43-
zoom: {{this.search_zoom}},
44-
position:'{{this.position}}',
45-
hideMarkerOnCollapse: true
46-
});
47-
} else if ('{{this.geom_type}}' == 'Polygon') {
48-
var searchControl = new L.Control.Search({
49-
layer: {{this.get_name()}},
50-
propertyName: '{{this.search_label}}',
51-
marker: false,
52-
moveToLocation: function(latlng, title, map) {
53-
var zoom = {{this._parent.get_name()}}.getBoundsZoom(latlng.layer.getBounds());
54-
{{this._parent.get_name()}}.setView(latlng, zoom); // access the zoom
55-
}
47+
var searchControl = new L.Control.Search({
48+
layer: {{this.get_name()}},
49+
propertyName: '{{this.search_label}}',
50+
{% if this.geom_type == 'Point' %}
51+
initial: false,
52+
zoom: {{this.search_zoom}},
53+
position:'{{this.position}}',
54+
hideMarkerOnCollapse: true
55+
{% endif %}
56+
{% if this.geom_type == 'Polygon' %}
57+
marker: false,
58+
moveToLocation: function(latlng, title, map) {
59+
var zoom = {{this._parent.get_name()}}.getBoundsZoom(latlng.layer.getBounds());
60+
{{this._parent.get_name()}}.setView(latlng, zoom); // access the zoom
61+
}
62+
{% endif %}
5663
});
57-
5864
searchControl.on('search:locationfound', function(e) {
5965
6066
e.layer.setStyle({fillColor: '#3f0', color: '#0f0'});
@@ -67,9 +73,6 @@ def __init__(self, data, search_zoom=12, search_label='name', geom_type='Point',
6773
{{this.get_name()}}.resetStyle(layer);
6874
});
6975
});
70-
}
71-
72-
7376
{{this._parent.get_name()}}.addControl( searchControl );
7477
7578
{% endmacro %}

0 commit comments

Comments
 (0)