()
| 12 | |
| 13 | |
| 14 | def test_marker_cluster(): |
| 15 | N = 100 |
| 16 | np.random.seed(seed=26082009) |
| 17 | data = np.array( |
| 18 | [ |
| 19 | np.random.uniform(low=35, high=60, size=N), # Random latitudes. |
| 20 | np.random.uniform(low=-12, high=30, size=N), # Random longitudes. |
| 21 | ] |
| 22 | ).T |
| 23 | m = folium.Map([45.0, 3.0], zoom_start=4) |
| 24 | mc = plugins.MarkerCluster(data).add_to(m) |
| 25 | |
| 26 | tmpl_for_expected = Template( |
| 27 | """ |
| 28 | var {{this.get_name()}} = L.markerClusterGroup( |
| 29 | {{ this.options|tojavascript }} |
| 30 | ); |
| 31 | {%- if this.icon_create_function is not none %} |
| 32 | {{ this.get_name() }}.options.iconCreateFunction = |
| 33 | {{ this.icon_create_function.strip() }}; |
| 34 | {%- endif %} |
| 35 | |
| 36 | {% for marker in this._children.values() %} |
| 37 | var {{marker.get_name()}} = L.marker( |
| 38 | {{ marker.location|tojson }}, {} |
| 39 | ).addTo({{this.get_name()}}); |
| 40 | {% endfor %} |
| 41 | |
| 42 | {{ this.get_name() }}.addTo({{ this._parent.get_name() }}); |
| 43 | """ |
| 44 | ) |
| 45 | expected = normalize(tmpl_for_expected.render(this=mc)) |
| 46 | |
| 47 | out = normalize(m._parent.render()) |
| 48 | |
| 49 | # We verify that imports |
| 50 | assert ( |
| 51 | '<script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet.markercluster/1.1.0/leaflet.markercluster.js"></script>' # noqa |
| 52 | in out |
| 53 | ) # noqa |
| 54 | assert ( |
| 55 | '<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet.markercluster/1.1.0/MarkerCluster.css"/>' # noqa |
| 56 | in out |
| 57 | ) # noqa |
| 58 | assert ( |
| 59 | '<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet.markercluster/1.1.0/MarkerCluster.Default.css"/>' # noqa |
| 60 | in out |
| 61 | ) # noqa |
| 62 | |
| 63 | assert expected in out |
| 64 | |
| 65 | bounds = m.get_bounds() |
| 66 | np.testing.assert_allclose( |
| 67 | bounds, |
| 68 | [ |
| 69 | [35.147332572663785, -11.520684337300109], |
| 70 | [59.839718052359274, 29.94931046497927], |
| 71 | ], |
nothing calls this directly
no test coverage detected