Path: blob/main/tests/plugins/test_marker_cluster.py
2542 views
"""1Test MarkerCluster2------------------3"""45import numpy as np67import folium8from folium import plugins9from folium.template import Template10from folium.utilities import normalize111213def test_marker_cluster():14N = 10015np.random.seed(seed=26082009)16data = np.array(17[18np.random.uniform(low=35, high=60, size=N), # Random latitudes.19np.random.uniform(low=-12, high=30, size=N), # Random longitudes.20]21).T22m = folium.Map([45.0, 3.0], zoom_start=4)23mc = plugins.MarkerCluster(data).add_to(m)2425tmpl_for_expected = Template("""26var {{this.get_name()}} = L.markerClusterGroup(27{{ this.options|tojavascript }}28);29{%- if this.icon_create_function is not none %}30{{ this.get_name() }}.options.iconCreateFunction =31{{ this.icon_create_function.strip() }};32{%- endif %}3334{% for marker in this._children.values() %}35var {{marker.get_name()}} = L.marker(36{{ marker.location|tojson }}, {}37).addTo({{this.get_name()}});38{% endfor %}3940{{ this.get_name() }}.addTo({{ this._parent.get_name() }});41""")42expected = normalize(tmpl_for_expected.render(this=mc))4344out = normalize(m._parent.render())4546# We verify that imports47assert (48'<script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet.markercluster/1.1.0/leaflet.markercluster.js"></script>' # noqa49in out50) # noqa51assert (52'<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet.markercluster/1.1.0/MarkerCluster.css"/>' # noqa53in out54) # noqa55assert (56'<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet.markercluster/1.1.0/MarkerCluster.Default.css"/>' # noqa57in out58) # noqa5960assert expected in out6162bounds = m.get_bounds()63np.testing.assert_allclose(64bounds,65[66[35.147332572663785, -11.520684337300109],67[59.839718052359274, 29.94931046497927],68],69)707172