@@ -13,10 +13,19 @@ class Search(MacroElement):
13
13
14
14
Parameters
15
15
----------
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
+
20
29
See https://github.com/stefanocudini/leaflet-search for more information.
21
30
22
31
"""
@@ -35,26 +44,23 @@ def __init__(self, data, search_zoom=12, search_label='name', geom_type='Point',
35
44
36
45
{{this._parent.get_name()}}.addLayer({{this.get_name()}});
37
46
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 %}
56
63
});
57
-
58
64
searchControl.on('search:locationfound', function(e) {
59
65
60
66
e.layer.setStyle({fillColor: '#3f0', color: '#0f0'});
@@ -67,9 +73,6 @@ def __init__(self, data, search_zoom=12, search_label='name', geom_type='Point',
67
73
{{this.get_name()}}.resetStyle(layer);
68
74
});
69
75
});
70
- }
71
-
72
-
73
76
{{this._parent.get_name()}}.addControl( searchControl );
74
77
75
78
{% endmacro %}
0 commit comments