Path: blob/main/tests/plugins/test_marker_cluster.py
1601 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(26"""27var {{this.get_name()}} = L.markerClusterGroup(28{{ this.options|tojavascript }}29);30{%- if this.icon_create_function is not none %}31{{ this.get_name() }}.options.iconCreateFunction =32{{ this.icon_create_function.strip() }};33{%- endif %}3435{% for marker in this._children.values() %}36var {{marker.get_name()}} = L.marker(37{{ marker.location|tojson }}, {}38).addTo({{this.get_name()}});39{% endfor %}4041{{ this.get_name() }}.addTo({{ this._parent.get_name() }});42"""43)44expected = normalize(tmpl_for_expected.render(this=mc))4546out = normalize(m._parent.render())4748# We verify that imports49assert (50'<script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet.markercluster/1.1.0/leaflet.markercluster.js"></script>' # noqa51in out52) # noqa53assert (54'<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet.markercluster/1.1.0/MarkerCluster.css"/>' # noqa55in out56) # noqa57assert (58'<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet.markercluster/1.1.0/MarkerCluster.Default.css"/>' # noqa59in out60) # noqa6162assert expected in out6364bounds = m.get_bounds()65np.testing.assert_allclose(66bounds,67[68[35.147332572663785, -11.520684337300109],69[59.839718052359274, 29.94931046497927],70],71)727374