Skip to content

Commit ca5983b

Browse files
committed
FeatureGroupSubGroup plugin: Add test
Signed-off-by: Olivier Mehani <[email protected]>
1 parent 48c8b5f commit ca5983b

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# -*- coding: utf-8 -*-
2+
3+
"""
4+
Test MarkerCluster
5+
------------------
6+
"""
7+
8+
from __future__ import (absolute_import, division, print_function)
9+
10+
import folium
11+
12+
from folium import plugins
13+
14+
from jinja2 import Template
15+
16+
import numpy as np
17+
18+
19+
def test_feature_group_sub_group():
20+
m = folium.Map([0., 0.], zoom_start=6)
21+
fg = folium.FeatureGroup()
22+
m.add_child(fg)
23+
g1 = folium.plugins.FeatureGroupSubGroup(fg, 'g1')
24+
m.add_child(g1)
25+
folium.Marker([1,1]).add_to(g1)
26+
folium.Marker([-1,-1]).add_to(g1)
27+
g2 = folium.plugins.FeatureGroupSubGroup(fg, 'g2')
28+
folium.Marker([-1,1]).add_to(g2)
29+
folium.Marker([1,-1]).add_to(g2)
30+
m.add_child(g2)
31+
l = folium.LayerControl().add_to(m)
32+
m._repr_html_()
33+
34+
out = m._parent.render()
35+
36+
# We verify that imports
37+
assert '<script src="https://unpkg.com/[email protected]/dist/leaflet.featuregroup.subgroup.js"></script>' in out # noqa
38+
39+
# Verify the script part is okay.
40+
tmpl = Template("""
41+
var {{this.get_name()}} = L.featureGroup.subGroup({{this._group.get_name()}});
42+
{{this.get_name()}}.addTo({{this._parent.get_name()}});
43+
44+
{% for marker in this._children.values() %}
45+
var {{marker.get_name()}} = L.marker(
46+
[{{marker.location[0]}},{{marker.location[1]}}],
47+
{
48+
icon: new L.Icon.Default()
49+
}
50+
)
51+
.addTo({{this.get_name()}});
52+
{% endfor %}
53+
""")
54+
assert ''.join(tmpl.render(this=g1).split()) in ''.join(out.split())
55+
assert ''.join(tmpl.render(this=g2).split()) in ''.join(out.split())

0 commit comments

Comments
 (0)